diff options
author | 2015-09-17 09:56:48 +0200 | |
---|---|---|
committer | 2015-09-17 09:56:48 +0200 | |
commit | b48cd70f5c2c115e1ed401492eaa62aa610ceaeb (patch) | |
tree | 47731eb9eaca7604b654c2345ec72448dbd7eedf /moonclient | |
parent | 65f87a52c2eb5583dd9277235fa196cf7354f9ed (diff) |
Add a select command to IntraExtension.
Change-Id: Ia78a10b51a17e9376e125130973f3813cc423f94
Diffstat (limited to 'moonclient')
-rw-r--r-- | moonclient/moonclient/intraextension.py | 80 | ||||
-rw-r--r-- | moonclient/moonclient/shell.py | 26 | ||||
-rw-r--r-- | moonclient/setup.py | 2 |
3 files changed, 49 insertions, 59 deletions
diff --git a/moonclient/moonclient/intraextension.py b/moonclient/moonclient/intraextension.py index 1842baa4..6def7ece 100644 --- a/moonclient/moonclient/intraextension.py +++ b/moonclient/moonclient/intraextension.py @@ -8,6 +8,31 @@ import logging from cliff.command import Command from cliff.lister import Lister from cliff.show import ShowOne +import os + + +class IntraExtensionSelect(Command): + """Select a Intra_Extension to work with.""" + + log = logging.getLogger(__name__) + + def get_parser(self, prog_name): + parser = super(IntraExtensionSelect, self).get_parser(prog_name) + parser.add_argument( + 'id', + metavar='<intraextension-id>', + help='IntraExtension UUID to select', + ) + return parser + + def take_action(self, parsed_args): + ie = self.app.get_url("/v3/OS-MOON/intra_extensions", authtoken=True) + if parsed_args.id in ie.keys(): + self.app.intraextension = parsed_args.id + self.log.info("Select {} IntraExtension.".format(self.app.intraextension)) + else: + self.log.error("IntraExtension {} unknown.".format(parsed_args.id)) + return class IntraExtensionCreate(Command): @@ -98,59 +123,36 @@ class IntraExtensionShow(ShowOne): parser.add_argument( 'uuid', metavar='<intraextension-uuid>', - help='IntraExtension UUID', + help='IntraExtension UUID (put "selected" if you want to show the selected IntraExtension)', + default="selected" ) return parser def take_action(self, parsed_args): - ie = self.app.get_url("/v3/OS-MOON/intra_extensions/{}".format(parsed_args.uuid), authtoken=True) - if "intra_extensions" not in ie: - raise Exception("Error in command {}".format(ie)) + intra_extension_id = parsed_args.uuid + if parsed_args.uuid == "selected": + intra_extension_id = self.app.intraextension + self.log.debug("self.app.intraextension={}".format(intra_extension_id)) + ie = self.app.get_url("/v3/OS-MOON/intra_extensions/{}".format(intra_extension_id), authtoken=True) + self.log.debug("ie={}".format(ie)) + if "id" not in ie: + self.log.error("Unknown intraextension {}".format(intra_extension_id)) + raise Exception() try: columns = ( "id", "name", "description", - "tenant", - "enabled", "model", "genre" ) data = ( - ie["intra_extensions"]["id"], - ie["intra_extensions"]["name"], - ie["intra_extensions"]["description"], - ie["intra_extensions"]["tenant"], - ie["intra_extensions"]["enabled"], - ie["intra_extensions"]["model"], - ie["intra_extensions"]["genre"] + ie["id"], + ie["name"], + ie["description"], + ie["model"], + ie["genre"] ) return columns, data except Exception as e: self.app.stdout.write(str(e)) - - -class TenantSet(Command): - """Set the tenant for a intra_extension.""" - - log = logging.getLogger(__name__) - - def get_parser(self, prog_name): - parser = super(TenantSet, self).get_parser(prog_name) - parser.add_argument( - 'intraextension_uuid', - metavar='<intraextension-uuid>', - help='IntraExtension UUID', - ) - parser.add_argument( - 'tenant_name', - metavar='<tenant-name>', - help='Tenant Name', - ) - return parser - - def take_action(self, parsed_args): - self.app.get_url("/v3/OS-MOON/intra_extensions/{}/tenant".format(parsed_args.intraextension_uuid), - post_data={"tenant_id": parsed_args.tenant_name}, - authtoken=True) - diff --git a/moonclient/moonclient/shell.py b/moonclient/moonclient/shell.py index 60e8e416..5efef032 100644 --- a/moonclient/moonclient/shell.py +++ b/moonclient/moonclient/shell.py @@ -37,6 +37,7 @@ class MoonClient(App): _intraextension = None _tenant_id = None _tenant_name = None + user_saving_file = ".moonclient" post = { "auth": { "identity": { @@ -91,25 +92,12 @@ class MoonClient(App): @property def intraextension(self): - if not self._intraextension: - self.log.debug("Setting intraextension") - project_id = self.get_url("/v3/projects?name={}".format(self._tenant_name), - authtoken=True)["projects"][0]["id"] - self.log.debug("project_id={}".format(project_id)) - tenants = self.get_url("/v3/OS-MOON/tenants", authtoken=True) - self.log.debug("tenants={}".format(tenants)) - if project_id not in tenants: - self.log.info("Tenant [{}] was not added in Moon".format(project_id)) - return - self._tenant_id = project_id - if tenants[project_id]['intra_authz_extension_id']: - self._intraextension = tenants[project_id]['intra_authz_extension_id'] - elif tenants[project_id]['intra_admin_extension_id']: - self._intraextension = tenants[project_id]['intra_admin_extension_id'] - else: - self._intraextension = None - self.log.info("No intra_extension found for tenant [{}].".format(project_id)) - return self._intraextension + return open(os.path.join(os.getenv('HOME'), self.user_saving_file)).read().strip() + + @intraextension.setter + def intraextension(self, value): + self._intraextension = value + open(os.path.join(os.getenv('HOME'), self.user_saving_file), "w").write(value) def get_tenant_uuid(self, tenant_name): return self.get_url("/v3/projects?name={}".format(tenant_name), authtoken=True)["projects"][0]["id"] diff --git a/moonclient/setup.py b/moonclient/setup.py index 39afdf8d..24aea055 100644 --- a/moonclient/setup.py +++ b/moonclient/setup.py @@ -68,7 +68,7 @@ setup( 'tenant_show = moonclient.tenants:TenantShow', 'tenant_delete = moonclient.tenants:TenantDelete', - 'intraextension_tenant_set = moonclient.intraextension:TenantSet', + 'intraextension_select = moonclient.intraextension:IntraExtensionSelect', 'intraextension_create = moonclient.intraextension:IntraExtensionCreate', 'intraextension_list = moonclient.intraextension:IntraExtensionList', 'intraextension_delete = moonclient.intraextension:IntraExtensionDelete', |