From 021a2717e389a52da999b377e8398ef33a9bb077 Mon Sep 17 00:00:00 2001 From: ghanshyam Date: Thu, 28 Jun 2018 10:33:48 +0300 Subject: [PATCH] Merge server create for security group extension As nova extensions has been deprecated already and goal is to merge all scattered code into main controller side. Currently schema and request/response extended code are there among all extensions. This commit merge the server_create for security group extensions. Partially implements: blueprint api-extensions-merge-rocky Note- unit tests will be moved to test_serversV21 when we will merge the extended response for security group. Change-Id: I447947e23451d3898a5eee0e25facc3d9ae8c01e --- nova/api/openstack/compute/security_groups.py | 11 ----------- nova/api/openstack/compute/servers.py | 8 ++++++-- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/nova/api/openstack/compute/security_groups.py b/nova/api/openstack/compute/security_groups.py index 53e79dcd4b..9801f46dcd 100644 --- a/nova/api/openstack/compute/security_groups.py +++ b/nova/api/openstack/compute/security_groups.py @@ -540,14 +540,3 @@ class SecurityGroupsOutputController(wsgi.Controller): @wsgi.extends def detail(self, req, resp_obj): self._extend_servers(req, list(resp_obj.obj['servers'])) - - -# NOTE(gmann): This function is not supposed to use 'body_deprecated_param' -# parameter as this is placed to handle scheduler_hint extension for V2.1. -def server_create(server_dict, create_kwargs, body_deprecated_param): - security_groups = server_dict.get(ATTRIBUTE_NAME) - if security_groups is not None: - create_kwargs['security_groups'] = [ - sg['name'] for sg in security_groups if sg.get('name')] - create_kwargs['security_groups'] = list( - set(create_kwargs['security_groups'])) diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py index 7e4e3f8cf8..f4c1e3a896 100644 --- a/nova/api/openstack/compute/servers.py +++ b/nova/api/openstack/compute/servers.py @@ -35,7 +35,6 @@ from nova.api.openstack.compute import keypairs from nova.api.openstack.compute import multiple_create from nova.api.openstack.compute import scheduler_hints from nova.api.openstack.compute.schemas import servers as schema_servers -from nova.api.openstack.compute import security_groups from nova.api.openstack.compute.views import servers as views_servers from nova.api.openstack import wsgi from nova.api import validation @@ -74,7 +73,6 @@ class ServersController(wsgi.Controller): keypairs.server_create, multiple_create.server_create, scheduler_hints.server_create, - security_groups.server_create, ] @staticmethod @@ -435,6 +433,12 @@ class ServersController(wsgi.Controller): # all of extended code into ServersController. self._create_by_func_list(server_dict, create_kwargs, body) create_kwargs['user_data'] = server_dict.get('user_data') + security_groups = server_dict.get('security_groups') + if security_groups is not None: + create_kwargs['security_groups'] = [ + sg['name'] for sg in security_groups if sg.get('name')] + create_kwargs['security_groups'] = list( + set(create_kwargs['security_groups'])) availability_zone = server_dict.pop("availability_zone", None)