Merge server create schema for scheduler hint 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 schema part of create server for scheduler
hint extensions.

Partially implements: blueprint api-extensions-merge-rocky

Change-Id: I7d15614051d4a38b74b0fc9e5c751fdc3f64cb1c
This commit is contained in:
ghanshyam 2018-06-27 12:33:49 +03:00 committed by Ghanshyam Mann
parent 74ee397dbb
commit f4ec8116ae
4 changed files with 59 additions and 94 deletions

View File

@ -12,8 +12,6 @@
# License for the specific language governing permissions and limitations
# under the License.
from nova.api.openstack.compute.schemas import scheduler_hints as schema
# NOTE(gmann): Accepting request body in this function to fetch "scheduler
# hint". This is a workaround to allow OS_SCH-HNT at the top level
@ -27,7 +25,3 @@ def server_create(server_dict, create_kwargs, req_body):
scheduler_hints = req_body['OS-SCH-HNT:scheduler_hints']
create_kwargs['scheduler_hints'] = scheduler_hints
def get_server_create_schema(version):
return schema.server_create

View File

@ -1,78 +0,0 @@
# Copyright 2014 NEC Corporation. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from nova.api.validation import parameter_types
_hints = {
'type': 'object',
'properties': {
'group': {
'type': 'string',
'format': 'uuid'
},
'different_host': {
# NOTE: The value of 'different_host' is the set of server
# uuids where a new server is scheduled on a different host.
# A user can specify one server as string parameter and should
# specify multiple servers as array parameter instead.
'oneOf': [
{
'type': 'string',
'format': 'uuid'
},
{
'type': 'array',
'items': parameter_types.server_id
}
]
},
'same_host': {
# NOTE: The value of 'same_host' is the set of server
# uuids where a new server is scheduled on the same host.
'type': ['string', 'array'],
'items': parameter_types.server_id
},
'query': {
# NOTE: The value of 'query' is converted to dict data with
# jsonutils.loads() and used for filtering hosts.
'type': ['string', 'object'],
},
# NOTE: The value of 'target_cell' is the cell name what cell
# a new server is scheduled on.
'target_cell': parameter_types.name,
'different_cell': {
'type': ['string', 'array'],
'items': {
'type': 'string'
}
},
'build_near_host_ip': parameter_types.ip_address,
'cidr': {
'type': 'string',
'pattern': '^\/[0-9a-f.:]+$'
},
},
# NOTE: As this Mail:
# http://lists.openstack.org/pipermail/openstack-dev/2015-June/067996.html
# pointed out the limit the scheduler-hints in the API is problematic. So
# relax it.
'additionalProperties': True
}
server_create = {
'os:scheduler_hints': _hints,
'OS-SCH-HNT:scheduler_hints': _hints,
}

View File

@ -91,6 +91,62 @@ block_device_mapping_v2_new_item = {
block_device_mapping_v2 = copy.deepcopy(legacy_block_device_mapping)
block_device_mapping_v2['properties'].update(block_device_mapping_v2_new_item)
_hints = {
'type': 'object',
'properties': {
'group': {
'type': 'string',
'format': 'uuid'
},
'different_host': {
# NOTE: The value of 'different_host' is the set of server
# uuids where a new server is scheduled on a different host.
# A user can specify one server as string parameter and should
# specify multiple servers as array parameter instead.
'oneOf': [
{
'type': 'string',
'format': 'uuid'
},
{
'type': 'array',
'items': parameter_types.server_id
}
]
},
'same_host': {
# NOTE: The value of 'same_host' is the set of server
# uuids where a new server is scheduled on the same host.
'type': ['string', 'array'],
'items': parameter_types.server_id
},
'query': {
# NOTE: The value of 'query' is converted to dict data with
# jsonutils.loads() and used for filtering hosts.
'type': ['string', 'object'],
},
# NOTE: The value of 'target_cell' is the cell name what cell
# a new server is scheduled on.
'target_cell': parameter_types.name,
'different_cell': {
'type': ['string', 'array'],
'items': {
'type': 'string'
}
},
'build_near_host_ip': parameter_types.ip_address,
'cidr': {
'type': 'string',
'pattern': '^\/[0-9a-f.:]+$'
},
},
# NOTE: As this Mail:
# http://lists.openstack.org/pipermail/openstack-dev/2015-June/067996.html
# pointed out the limit the scheduler-hints in the API is problematic. So
# relax it.
'additionalProperties': True
}
base_create = {
'type': 'object',
'properties': {
@ -144,6 +200,8 @@ base_create = {
'required': ['name', 'flavorRef'],
'additionalProperties': False,
},
'os:scheduler_hints': _hints,
'OS-SCH-HNT:scheduler_hints': _hints,
},
'required': ['server'],
'additionalProperties': False,

View File

@ -93,7 +93,6 @@ class ServersController(wsgi.Controller):
# NOTE(alex_xu): Please do not add more items into this list. This list
# should be removed in the future.
schema_func_list = [
scheduler_hints.get_server_create_schema,
security_groups.get_server_create_schema,
user_data.get_server_create_schema,
]
@ -689,15 +688,7 @@ class ServersController(wsgi.Controller):
def _create_schema_by_func(self, create_schema, version, schema_func):
schema = schema_func(version)
if (schema_func.__module__ ==
'nova.api.openstack.compute.scheduler_hints'):
# NOTE(oomichi): The request parameter position of scheduler-hint
# extension is different from the other extensions, so here handles
# the difference.
create_schema['properties'].update(schema)
else:
create_schema['properties']['server']['properties'].update(schema)
create_schema['properties']['server']['properties'].update(schema)
def _delete(self, context, req, instance_uuid):
instance = self._get_server(context, req, instance_uuid)