diff options
author | Thiago Paiva Brito <thiagop@lsd.ufcg.edu.br> | 2014-08-20 16:26:00 -0300 |
---|---|---|
committer | Rodrigo Duarte Sousa <rodrigods@lsd.ufcg.edu.br> | 2015-02-05 22:36:47 -0300 |
commit | 8da68e3ded4aa7208f5bc55cf4f438e4d0e910b1 (patch) | |
tree | f9cca18a304d1d8ae5109b8bbb65aaece7216ee0 /keystoneclient/v3/projects.py | |
parent | cef7775cda6d4113171ff713ee36b93731b89242 (diff) | |
download | python-keystoneclient-8da68e3ded4aa7208f5bc55cf4f438e4d0e910b1.tar.gz |
Hierarchical multitenancy basic calls
This patch addresses changes needed to manage projects through
keystoneclient API v3. The changes are:
create:
new param 'parent': set the parent project of the project being created
get:
new param 'subtree_as_list': If True, shows projects down the hierarchy
new param 'parents_as_list': If True, shows projects up the hierarchy
Co-Authored-By: Andre Aranha <afaranha@lsd.ufcg.edu.br>
Co-Authored-By: Rodrigo Duarte <rodrigods@lsd.ufcg.edu.br>
Change-Id: I0f02a66e6a29584197ed00cb32caecb50956f458
Implements: blueprint hierarchical-multitenancy
Diffstat (limited to 'keystoneclient/v3/projects.py')
-rw-r--r-- | keystoneclient/v3/projects.py | 52 |
1 files changed, 48 insertions, 4 deletions
diff --git a/keystoneclient/v3/projects.py b/keystoneclient/v3/projects.py index 2fcd249..0a98991 100644 --- a/keystoneclient/v3/projects.py +++ b/keystoneclient/v3/projects.py @@ -26,6 +26,11 @@ class Project(base.Resource): * name: project name * description: project description * enabled: boolean to indicate if project is enabled + * parent_id: a uuid representing this project's parent in hierarchy + * parents: a list or a structured dict containing the parents of this + project in the hierarchy + * subtree: a list or a structured dict containing the subtree of this + project in the hierarchy """ @utils.positional(enforcement=utils.positional.WARN) @@ -54,7 +59,26 @@ class ProjectManager(base.CrudManager): key = 'project' @utils.positional(1, enforcement=utils.positional.WARN) - def create(self, name, domain, description=None, enabled=True, **kwargs): + def create(self, name, domain, description=None, + enabled=True, parent=None, **kwargs): + """Create a project. + + :param str name: project name. + :param domain: the project domain. + :type domain: :py:class:`keystoneclient.v3.domains.Domain` or str + :param str description: the project description. (optional) + :param boolean enabled: if the project is enabled. (optional) + :param parent: the project's parent in the hierarchy. (optional) + :type parent: :py:class:`keystoneclient.v3.projects.Project` or str + """ + + # NOTE(rodrigods): the API must be backwards compatible, so if an + # application was passing a 'parent_id' before as kwargs, the call + # should not fail. If both 'parent' and 'parent_id' are provided, + # 'parent' will be preferred. + if parent: + kwargs['parent_id'] = base.getid(parent) + return super(ProjectManager, self).create( domain_id=base.getid(domain), name=name, @@ -79,9 +103,29 @@ class ProjectManager(base.CrudManager): fallback_to_auth=True, **kwargs) - def get(self, project): - return super(ProjectManager, self).get( - project_id=base.getid(project)) + @utils.positional() + def get(self, project, subtree_as_list=False, parents_as_list=False): + """Get a project. + + :param project: project to be retrieved. + :type project: :py:class:`keystoneclient.v3.projects.Project` or str + :param boolean subtree_as_list: retrieve projects below this project + in the hierarchy as a flat list. + (optional) + :param boolean parents_as_list: retrieve projects above this project + in the hierarchy as a flat list. + (optional) + """ + # According to the API spec, the query params are key only + query = '' + if subtree_as_list: + query = '?subtree_as_list' + if parents_as_list: + query = query + '&parents_as_list' if query else '?parents_as_list' + + dict_args = {'project_id': base.getid(project)} + url = self.build_url(dict_args_in_out=dict_args) + query + return self._get(url, self.key) @utils.positional(enforcement=utils.positional.WARN) def update(self, project, name=None, domain=None, description=None, |