summaryrefslogtreecommitdiff
path: root/openstackclient/compute
diff options
context:
space:
mode:
authorHuanxuan Ao <huanxuan.ao@easystack.cn>2016-07-07 21:27:22 +0800
committerHuanxuan Ao <huanxuan.ao@easystack.cn>2016-07-22 10:20:18 +0800
commitb0c317ebdd5e5f2626ce2fbd495149336fe5df7e (patch)
treeb9f1430430d6c0ba3bca9f023341b7f61c8f3729 /openstackclient/compute
parent55c1c575d63f4e9e6fc3f4dbb6c572e841b513d9 (diff)
downloadpython-openstackclient-b0c317ebdd5e5f2626ce2fbd495149336fe5df7e.tar.gz
Add Support for showing flavor access list
Add a attribute "access_project_id" for flavor object to display the access project id list by using "flavor show" command. Change-Id: I7f0c152b816e0ca2e32e47f9b5c1aa7663d33b6d Closes-Bug:#1575461
Diffstat (limited to 'openstackclient/compute')
-rw-r--r--openstackclient/compute/v2/flavor.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/openstackclient/compute/v2/flavor.py b/openstackclient/compute/v2/flavor.py
index 000df598..b3f09ce5 100644
--- a/openstackclient/compute/v2/flavor.py
+++ b/openstackclient/compute/v2/flavor.py
@@ -380,7 +380,27 @@ class ShowFlavor(command.ShowOne):
def take_action(self, parsed_args):
compute_client = self.app.client_manager.compute
resource_flavor = _find_flavor(compute_client, parsed_args.flavor)
+
+ access_projects = None
+ # get access projects list of this flavor
+ if not resource_flavor.is_public:
+ try:
+ flavor_access = compute_client.flavor_access.list(
+ flavor=resource_flavor.id)
+ projects = [utils.get_field(access, 'tenant_id')
+ for access in flavor_access]
+ # TODO(Huanxuan Ao): This format case can be removed after
+ # patch https://review.openstack.org/#/c/330223/ merged.
+ access_projects = utils.format_list(projects)
+ except Exception as e:
+ msg = _("Failed to get access projects list "
+ "for flavor '%(flavor)s': %(e)s")
+ LOG.error(msg % {'flavor': parsed_args.flavor, 'e': e})
+
flavor = resource_flavor._info.copy()
+ flavor.update({
+ 'access_project_ids': access_projects
+ })
flavor.pop("links", None)
flavor['properties'] = utils.format_dict(resource_flavor.get_keys())