aboutsummaryrefslogtreecommitdiffstats
path: root/python_moonclient/python_moonclient/cli/projects.py
diff options
context:
space:
mode:
Diffstat (limited to 'python_moonclient/python_moonclient/cli/projects.py')
-rw-r--r--python_moonclient/python_moonclient/cli/projects.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/python_moonclient/python_moonclient/cli/projects.py b/python_moonclient/python_moonclient/cli/projects.py
new file mode 100644
index 00000000..c4653a51
--- /dev/null
+++ b/python_moonclient/python_moonclient/cli/projects.py
@@ -0,0 +1,56 @@
+import logging
+from python_moonclient.core import models, policies, pdp
+from python_moonclient.cli.parser import Parser
+from cliff.lister import Lister
+
+logger = logging.getLogger("moonclient.cli.projects")
+
+
+class ProjectsUtils:
+ def __init__(self):
+ pass
+
+ @staticmethod
+ def get_project_id(pdp, parsed_id, parsed_name):
+ projects = pdp.get_keystone_projects()
+ for _project_value in projects['projects']:
+ if _project_value['id'] == parsed_id or _project_value['name'] == parsed_name:
+ #logger.info("Found project : [key='{}' , name='{}']".format(_project_value['id'], _project_value['name']))
+ return _project_value['id']
+ return None
+
+ @staticmethod
+ def get_project_name(pdp, parsed_id, parsed_name):
+ projects = pdp.get_keystone_projects()
+ for _project_value in projects['projects']:
+ if _project_value['id'] == parsed_id or _project_value['name'] == parsed_name:
+ #logger.info("Found project : [key='{}' , name='{}']".format(_project_value['id'], _project_value['name']))
+ return _project_value['name']
+ return None
+
+
+class Projects(Lister):
+ """show the list of projects"""
+
+ def get_parser(self, prog_name):
+ parser = super().get_parser(prog_name)
+ Parser.add_common_options(parser)
+ return parser
+
+ def take_action(self, parsed_args):
+ consul_host = parsed_args.consul_host
+ consul_port = parsed_args.consul_port
+
+ models.init(consul_host, consul_port)
+ policies.init(consul_host, consul_port)
+ pdp.init(consul_host, consul_port)
+
+ projects = pdp.get_keystone_projects()
+
+ return (('Id' , 'Name'),
+ ((_project['id'], _project['name']) for _project in projects['projects'])
+ )
+
+
+
+