diff options
| author | Jenkins <jenkins@review.openstack.org> | 2013-05-28 17:27:19 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-05-28 17:27:19 +0000 |
| commit | ad611b1cff8f60e1425b9319fc62bdeced12bf1a (patch) | |
| tree | 5d0372c49d54d142c8d9c5b46a2213326b057cc0 /nova/api | |
| parent | 713d612582a2c82ea1eae0d7286d2f83e95cb258 (diff) | |
| parent | 0604e77654d0c7eb5fda9600e9ca604da656d856 (diff) | |
| download | nova-ad611b1cff8f60e1425b9319fc62bdeced12bf1a.tar.gz nova-ad611b1cff8f60e1425b9319fc62bdeced12bf1a.tar.xz nova-ad611b1cff8f60e1425b9319fc62bdeced12bf1a.zip | |
Merge "Optimize SecurityGroupsOutputController by len(servers)"
Diffstat (limited to 'nova/api')
| -rw-r--r-- | nova/api/openstack/compute/contrib/security_groups.py | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/nova/api/openstack/compute/contrib/security_groups.py b/nova/api/openstack/compute/contrib/security_groups.py index de5a9bd8e..87ef6d882 100644 --- a/nova/api/openstack/compute/contrib/security_groups.py +++ b/nova/api/openstack/compute/contrib/security_groups.py @@ -466,6 +466,8 @@ class SecurityGroupsOutputController(wsgi.Controller): def _extend_servers(self, req, servers): # TODO(arosen) this function should be refactored to reduce duplicate # code and use get_instance_security_groups instead of get_db_instance. + if not len(servers): + return key = "security_groups" context = _authorize_context(req) if not openstack_driver.is_quantum_security_groups(): @@ -480,13 +482,20 @@ class SecurityGroupsOutputController(wsgi.Controller): # quantum security groups the requested security groups for the # instance are not in the db and have not been sent to quantum yet. if req.method != 'POST': - sg_instance_bindings = ( - self.security_group_api - .get_instances_security_groups_bindings(context)) - for server in servers: - groups = sg_instance_bindings.get(server['id']) - if groups: - server[key] = groups + if len(servers) == 1: + group = (self.security_group_api + .get_instance_security_groups(context, + servers[0]['id'])) + if group: + servers[0][key] = group + else: + sg_instance_bindings = ( + self.security_group_api + .get_instances_security_groups_bindings(context)) + for server in servers: + groups = sg_instance_bindings.get(server['id']) + if groups: + server[key] = groups # In this section of code len(servers) == 1 as you can only POST # one server in an API request. else: |
