aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--moonclient/moonclient/intraextension.py80
-rw-r--r--moonclient/moonclient/shell.py26
-rw-r--r--moonclient/setup.py2
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',