summaryrefslogtreecommitdiff
path: root/quantumclient
diff options
context:
space:
mode:
authorYong Sheng Gong <gongysh@cn.ibm.com>2012-08-12 07:33:10 +0800
committerYong Sheng Gong <gongysh@cn.ibm.com>2012-08-12 22:47:05 +0800
commitfdc12bd65027ecf28a78734b3046f20e5f90893f (patch)
tree47ee1e998da48291c4c8dc30988e106b5a225858 /quantumclient
parent8f1ce248b33fdf8d693ea1cea9e00524b6c54495 (diff)
downloadpython-neutronclient-fdc12bd65027ecf28a78734b3046f20e5f90893f.tar.gz
add ext list and show commands.
Change-Id: I3bdf1a3b066ee12572468b8d7abee96eb07f9257
Diffstat (limited to 'quantumclient')
-rw-r--r--quantumclient/quantum/v2_0/extension.py95
-rw-r--r--quantumclient/shell.py4
-rw-r--r--quantumclient/v2_0/client.py12
3 files changed, 111 insertions, 0 deletions
diff --git a/quantumclient/quantum/v2_0/extension.py b/quantumclient/quantum/v2_0/extension.py
new file mode 100644
index 0000000..00fa1fb
--- /dev/null
+++ b/quantumclient/quantum/v2_0/extension.py
@@ -0,0 +1,95 @@
+# Copyright 2012 OpenStack LLC.
+# All Rights Reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+import logging
+
+from cliff import lister
+from cliff import show
+
+from quantumclient.common import utils
+from quantumclient.quantum.v2_0 import QuantumCommand
+
+
+class ListExt(QuantumCommand, lister.Lister):
+ """List all exts."""
+
+ api = 'network'
+ resource = 'extension'
+ log = logging.getLogger(__name__ + '.ListExt')
+ _formatters = None
+
+ def get_parser(self, prog_name):
+ parser = super(ListExt, self).get_parser(prog_name)
+ return parser
+
+ def get_data(self, parsed_args):
+ self.log.debug('get_data(%s)' % parsed_args)
+ quantum_client = self.get_client()
+ search_opts = {}
+ quantum_client.format = parsed_args.request_format
+ obj_lister = getattr(quantum_client,
+ "list_%ss" % self.resource)
+ data = obj_lister(**search_opts)
+ info = []
+ collection = self.resource + "s"
+ if collection in data:
+ info = data[collection]
+ _columns = len(info) > 0 and sorted(info[0].keys()) or []
+ return (_columns, (utils.get_item_properties(s, _columns)
+ for s in info))
+
+
+class ShowExt(QuantumCommand, show.ShowOne):
+ """Show information of a given resource
+
+ """
+ api = 'network'
+ resource = "extension"
+ log = logging.getLogger(__name__ + '.ShowExt')
+
+ def get_parser(self, prog_name):
+ parser = super(ShowExt, self).get_parser(prog_name)
+ parser.add_argument(
+ 'ext_alias', metavar='ext_alias',
+ help='the extension alias')
+ return parser
+
+ def get_data(self, parsed_args):
+ self.log.debug('get_data(%s)' % parsed_args)
+ quantum_client = self.get_client()
+ quantum_client.format = parsed_args.request_format
+ params = {}
+ obj_shower = getattr(quantum_client,
+ "show_%s" % self.resource)
+ data = obj_shower(parsed_args.ext_alias, **params)
+ if self.resource in data:
+ for k, v in data[self.resource].iteritems():
+ if isinstance(v, list):
+ value = ""
+ for _item in v:
+ if value:
+ value += "\n"
+ if isinstance(_item, dict):
+ value += utils.dumps(_item)
+ else:
+ value += str(_item)
+ data[self.resource][k] = value
+ elif v is None:
+ data[self.resource][k] = ''
+ return zip(*sorted(data[self.resource].iteritems()))
+ else:
+ return None
diff --git a/quantumclient/shell.py b/quantumclient/shell.py
index a807840..1790e81 100644
--- a/quantumclient/shell.py
+++ b/quantumclient/shell.py
@@ -91,6 +91,10 @@ COMMAND_V2 = {
'quantumclient.quantum.v2_0.quota.DeleteQuota'),
'quota-update': utils.import_class(
'quantumclient.quantum.v2_0.quota.UpdateQuota'),
+ 'ext-list': utils.import_class(
+ 'quantumclient.quantum.v2_0.extension.ListExt'),
+ 'ext-show': utils.import_class(
+ 'quantumclient.quantum.v2_0.extension.ShowExt'),
}
COMMANDS = {'2.0': COMMAND_V2}
diff --git a/quantumclient/v2_0/client.py b/quantumclient/v2_0/client.py
index 8cc78d2..23766da 100644
--- a/quantumclient/v2_0/client.py
+++ b/quantumclient/v2_0/client.py
@@ -156,6 +156,8 @@ class Client(object):
subnet_path = "/subnets/%s"
quotas_path = "/quotas"
quota_path = "/quotas/%s"
+ exts_path = "/extensions"
+ ext_path = "/extensions/%s"
@APIParamsCall
def get_quotas_tenant(self, **_params):
@@ -184,6 +186,16 @@ class Client(object):
return self.delete(self.quota_path % (tenant_id))
@APIParamsCall
+ def list_extensions(self, **_params):
+ """Fetch a list of all exts on server side."""
+ return self.get(self.exts_path, params=_params)
+
+ @APIParamsCall
+ def show_extension(self, ext_alias, **_params):
+ """Fetch a list of all exts on server side."""
+ return self.get(self.ext_path % ext_alias, params=_params)
+
+ @APIParamsCall
def list_ports(self, **_params):
"""
Fetches a list of all networks for a tenant