From ddd486f67b6c97f5c25bd9e3bbc5d7f5be10733f Mon Sep 17 00:00:00 2001 From: zhangdebo1987 Date: Wed, 12 Jul 2017 19:09:33 +0800 Subject: [PATCH] Support removing projects from flavor access list When we remove one or more projects from a flavor access list, it doesn't work, now I fix it. Change-Id: I92f4fd83a958ff7a7249d0848f9fd128fc73e13f Closes-bug: #1703760 --- .../dashboards/admin/flavors/workflows.py | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/openstack_dashboard/dashboards/admin/flavors/workflows.py b/openstack_dashboard/dashboards/admin/flavors/workflows.py index 1642bf9f5b..44beda4c10 100644 --- a/openstack_dashboard/dashboards/admin/flavors/workflows.py +++ b/openstack_dashboard/dashboards/admin/flavors/workflows.py @@ -313,6 +313,26 @@ class UpdateFlavor(workflows.Workflow): flavor.id, project) + def modify_access(flavor): + if flavor.is_public: + old_flavor_projects = [] + else: + old_flavor_projects = [project.tenant_id for project in + api.nova.flavor_access_list(request, + flavor.id)] + to_remove = [project for project in old_flavor_projects if project + not in flavor_projects] + to_add = [project for project in flavor_projects if project not in + old_flavor_projects] + for project in to_remove: + api.nova.remove_tenant_from_flavor(request, + flavor.id, + project) + for project in to_add: + api.nova.add_tenant_to_flavor(request, + flavor.id, + project) + # Update flavor information try: flavor_id = data['flavor_id'] @@ -321,7 +341,7 @@ class UpdateFlavor(workflows.Workflow): # Check if the flavor info is not actually changed if not is_changed(flavor): try: - setup_access() + modify_access(flavor) except Exception: exceptions.handle(request, _('Unable to modify flavor access.'))