Le Tian Ren 5e1c266859 Initial code base commit.
Change-Id: Id1e336028fa662ddee865841ac7b6c31a316f854
Closes-Bug: #1317383
2014-05-08 22:00:29 +08:00

118 lines
3.9 KiB
Python

COPYRIGHT = """
*************************************************************
Licensed Materials - Property of IBM
OCO Source Materials
(C) Copyright IBM Corp. 2013 All Rights Reserved
*************************************************************
"""
from oslo.config import cfg
from prettytable import PrettyTable
from neutron.openstack.common.rpc import proxy
from neutron.openstack.common import log as logging
from powervc.common.gettextutils import _
LOG = logging.getLogger(__name__)
LIST_COLUMNS = ['status', 'local_id', 'pvc_id', 'sync_key']
#==============================================================================
# RPC client
#==============================================================================
class RpcClient(proxy.RpcProxy):
BASE_RPC_API_VERSION = '1.0'
def __init__(self, context):
LOG.debug(_('__init__'))
self.topic = 'powervcrpc'
self.context = context
self.host = cfg.CONF.host
super(RpcClient, self).__init__(
topic=self.topic, default_version=self.BASE_RPC_API_VERSION)
def _print_table(self, result):
if result and len(result) > 0:
pt = PrettyTable(LIST_COLUMNS)
for obj in result:
row = []
for col in LIST_COLUMNS:
row.append(obj.get(col))
pt.add_row(row)
print pt
def _print_object(self, result):
if result:
pt = PrettyTable(['Field', 'Value'])
pt.align['Field'] = 'l'
pt.align['Value'] = 'l'
for field in result.keys():
row = [field, result.get(field)]
pt.add_row(row)
print pt
else:
print 'Result from RPC call: ', result
def get_local_network_uuid(self, network_id):
LOG.debug(_('get_local_network_uuid'))
result = self.call(self.context,
self.make_msg('get_local_network_uuid',
network_id=network_id),
topic=self.topic)
print 'Result from RPC call:', result
def get_pvc_network_uuid(self, network_id):
LOG.debug(_('get_pvc_network_uuid'))
result = self.call(self.context,
self.make_msg('get_pvc_network_uuid',
network_id=network_id),
topic=self.topic)
print 'Result from RPC call:', result
def get_network(self, opt):
LOG.debug(_('get_network: %s'), opt)
result = self.call(self.context,
self.make_msg('get_network', sync_key=opt),
topic=self.topic)
self._print_object(result)
def get_networks(self):
LOG.debug(_('get_networks'))
result = self.call(self.context,
self.make_msg('get_networks'),
topic=self.topic)
self._print_table(result)
def get_subnet(self, opt):
LOG.debug(_('get_subnet: %s'), opt)
result = self.call(self.context,
self.make_msg('get_subnet', sync_key=opt),
topic=self.topic)
self._print_object(result)
def get_subnets(self):
LOG.debug(_('get_subnets'))
result = self.call(self.context,
self.make_msg('get_subnets'),
topic=self.topic)
self._print_table(result)
def get_port(self, opt):
LOG.debug(_('get_port: %s'), opt)
result = self.call(self.context,
self.make_msg('get_port', sync_key=opt),
topic=self.topic)
self._print_object(result)
def get_ports(self):
LOG.debug(_('get_ports'))
result = self.call(self.context,
self.make_msg('get_ports'),
topic=self.topic)
self._print_table(result)