From efb2b0949a64cec12ecc2987d26b1871e179d9c0 Mon Sep 17 00:00:00 2001 From: Maxime Cottret Date: Tue, 13 Dec 2016 15:24:38 +0100 Subject: [PATCH] Improve User experience This patch adds access to new REST API for config and service metadata retrieval. The following work has been done: * Create new manager for config retrieval * Create new Resource and CRUD manager for service info retrieval * Add managers to client * Add new CLI command and openstack client entries Change-Id: I43f572202b1cd3832a820f46f7c7b44a0d998406 Depends-on: https://review.openstack.org/#/c/406180/ --- cloudkittyclient/v1/client.py | 2 ++ cloudkittyclient/v1/core.py | 23 +++++++++++++++++++++++ cloudkittyclient/v1/shell.py | 26 ++++++++++++++++++++++++++ cloudkittyclient/v1/shell_cli.py | 23 +++++++++++++++++++++++ setup.cfg | 3 +++ 5 files changed, 77 insertions(+) diff --git a/cloudkittyclient/v1/client.py b/cloudkittyclient/v1/client.py index 2126e29..886338d 100644 --- a/cloudkittyclient/v1/client.py +++ b/cloudkittyclient/v1/client.py @@ -60,6 +60,8 @@ class Client(object): self.reportsummary = report.ReportSummaryManager(self.http_client) self.quotations = core.QuotationManager(self.http_client) self.storage = storage.StorageManager(self.http_client) + self.config = core.ConfigInfoManager(self.http_client) + self.service_info = core.ServiceInfoManager(self.http_client) self._expose_submodules() def _expose_submodules(self): diff --git a/cloudkittyclient/v1/core.py b/cloudkittyclient/v1/core.py index 2744649..d3b3cc6 100644 --- a/cloudkittyclient/v1/core.py +++ b/cloudkittyclient/v1/core.py @@ -64,3 +64,26 @@ class QuotationManager(base.Manager): out = self.api.post(self.base_url, json={'resources': resources}).json() return out + + +class ServiceInfo(base.Resource): + + key = "service" + + def __repr__(self): + return "" % self._info + + +class ServiceInfoManager(base.CrudManager): + resource_class = ServiceInfo + base_url = "/v1/info" + key = "service" + collection_key = "services" + + +class ConfigInfoManager(base.Manager): + base_url = "/v1/info/config" + + def get_config(self): + out = self.api.get(self.base_url).json() + return out diff --git a/cloudkittyclient/v1/shell.py b/cloudkittyclient/v1/shell.py index 26b58df..4bd2edc 100644 --- a/cloudkittyclient/v1/shell.py +++ b/cloudkittyclient/v1/shell.py @@ -86,3 +86,29 @@ def do_module_set_priority(cc, args): modules = [cc.modules.get(module_id=args.name)] utils.print_list(modules, fields, field_labels, sortby=0) + + +def do_info_config_get(cc, args): + '''Get cloudkitty configuration.''' + utils.print_dict(cc.config.get_config(), dict_property="Section") + + +@utils.arg('-n', '--name', + help='Service name', + required=False) +def do_info_service_get(cc, args): + '''Get service info.''' + if args.name: + try: + services_info = [cc.service_info.get(service_id=args.name)] + except exceptions.NotFound: + raise exc.CommandError('Service not found: %s' % args.name) + else: + try: + services_info = cc.service_info.list() + except exceptions.NotFound: + raise exc.CommandError('ServiceInfo not found') + + field_labels = ['Service', 'Metadata', 'Unit'] + fields = ['service_id', 'metadata', 'unit'] + utils.print_list(services_info, fields, field_labels, sortby=0) diff --git a/cloudkittyclient/v1/shell_cli.py b/cloudkittyclient/v1/shell_cli.py index c4a51a0..e97d1a5 100644 --- a/cloudkittyclient/v1/shell_cli.py +++ b/cloudkittyclient/v1/shell_cli.py @@ -66,3 +66,26 @@ class CliModuleSetPriority(command.Command): def take_action(self, parsed_args): ckclient = self.app.client_manager.rating shell.do_module_set_priority(ckclient, parsed_args) + + +class CliInfoGetConfig(command.Command): + def get_parser(self, prog_name): + parser = super(CliInfoGetConfig, self).get_parser(prog_name) + return parser + + def take_action(self, parsed_args): + ckclient = self.app.client_manager.rating + shell.do_info_config_get(ckclient, parsed_args) + + +class CliInfoGetService(command.Command): + def get_parser(self, prog_name): + parser = super(CliInfoGetService, self).get_parser(prog_name) + parser.add_argument('-n', '--name', + help='Service name', + required=False) + return parser + + def take_action(self, parsed_args): + ckclient = self.app.client_manager.rating + shell.do_info_service_get(ckclient, parsed_args) diff --git a/setup.cfg b/setup.cfg index 7bca081..88cc9bb 100644 --- a/setup.cfg +++ b/setup.cfg @@ -39,6 +39,9 @@ openstack.rating.v1 = rating_module-disable = cloudkittyclient.v1.shell_cli:CliModuleDisable rating_module-set-priority = cloudkittyclient.v1.shell_cli:CliModuleSetPriority + rating_info-config-get = cloudkittyclient.v1.shell_cli:CliInfoGetConfig + rating_info-service-get = cloudkittyclient.v1.shell_cli:CliInfoGetService + rating_total-get = cloudkittyclient.v1.report.shell_cli:CliTotalGet rating_summary-get = cloudkittyclient.v1.report.shell_cli:CliSummaryGet rating_report-tenant-list = cloudkittyclient.v1.report.shell_cli:CliReportTenantList