Merge server create schema for BDM v2 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 BDM v2 extensions.

Partially implements: blueprint api-extensions-merge-rocky

Change-Id: I49146f5b2e7635aa500054e9506e9bf28f6a2ce5
This commit is contained in:
ghanshyam 2018-06-21 14:30:58 +00:00 committed by Ghanshyam Mann
parent 627ff16e9d
commit 17fcbe9fde
4 changed files with 79 additions and 110 deletions

View File

@ -17,9 +17,6 @@
from webob import exc
from nova.api.openstack import api_version_request
from nova.api.openstack.compute.schemas import block_device_mapping as \
schema_block_device_mapping
from nova import block_device
from nova import exception
from nova.i18n import _
@ -56,19 +53,3 @@ def server_create(server_dict, create_kwargs, body_deprecated_param):
create_kwargs['block_device_mapping'] = block_device_mapping
# Unset the legacy_bdm flag if we got a block device mapping.
create_kwargs['legacy_bdm'] = False
def get_server_create_schema(version):
request_version = api_version_request.APIVersionRequest(version)
version_242 = api_version_request.APIVersionRequest('2.42')
# NOTE(artom) the following conditional was merged as
# "if version == '2.32'" The intent all along was to check whether
# version was greater than or equal to 2.32. In other words, we wanted
# to support tags in versions 2.32 and up, but ended up supporting them
# in version 2.32 only. Since we need a new microversion to add request
# body attributes, tags have been re-added in version 2.42.
if version == '2.32' or request_version >= version_242:
return schema_block_device_mapping.server_create_with_tags
else:
return schema_block_device_mapping.server_create

View File

@ -1,87 +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.
import copy
from nova.api.openstack.compute.schemas import servers
from nova.api.validation import parameter_types
block_device_mapping_new_item = {
# defined in nova/block_device.py:from_api()
# NOTE: Client can specify the Id with the combination of
# source_type and uuid, or a single attribute like volume_id/
# image_id/snapshot_id.
'source_type': {
'type': 'string',
'enum': ['volume', 'image', 'snapshot', 'blank'],
},
'uuid': {
'type': 'string', 'minLength': 1, 'maxLength': 255,
'pattern': '^[a-zA-Z0-9._-]*$',
},
'image_id': parameter_types.image_id,
'destination_type': {
'type': 'string',
'enum': ['local', 'volume'],
},
# Defined as varchar(255) in column "guest_format" in table
# "block_device_mapping"
'guest_format': {
'type': 'string', 'maxLength': 255,
},
# Defined as varchar(255) in column "device_type" in table
# "block_device_mapping"
'device_type': {
'type': 'string', 'maxLength': 255,
},
# Defined as varchar(255) in column "disk_bus" in table
# "block_device_mapping"
'disk_bus': {
'type': 'string', 'maxLength': 255,
},
# Defined as integer in nova/block_device.py:from_api()
# NOTE(mriedem): boot_index=None is also accepted for backward
# compatibility with the legacy v2 API.
'boot_index': {
'type': ['integer', 'string', 'null'],
'pattern': '^-?[0-9]+$',
},
}
block_device_mapping = copy.deepcopy(
servers.legacy_block_device_mapping)
block_device_mapping['properties'].update(block_device_mapping_new_item)
server_create = {
'block_device_mapping_v2': {
'type': 'array',
'items': block_device_mapping
}
}
block_device_mapping_with_tags_new_item = {
'tag': parameter_types.tag
}
block_device_mapping_with_tags = copy.deepcopy(block_device_mapping)
block_device_mapping_with_tags['properties'].update(
block_device_mapping_with_tags_new_item)
server_create_with_tags = {
'block_device_mapping_v2': {
'type': 'array',
'items': block_device_mapping_with_tags
}
}

View File

@ -46,6 +46,51 @@ legacy_block_device_mapping = {
'additionalProperties': False
}
block_device_mapping_v2_new_item = {
# defined in nova/block_device.py:from_api()
# NOTE: Client can specify the Id with the combination of
# source_type and uuid, or a single attribute like volume_id/
# image_id/snapshot_id.
'source_type': {
'type': 'string',
'enum': ['volume', 'image', 'snapshot', 'blank'],
},
'uuid': {
'type': 'string', 'minLength': 1, 'maxLength': 255,
'pattern': '^[a-zA-Z0-9._-]*$',
},
'image_id': parameter_types.image_id,
'destination_type': {
'type': 'string',
'enum': ['local', 'volume'],
},
# Defined as varchar(255) in column "guest_format" in table
# "block_device_mapping"
'guest_format': {
'type': 'string', 'maxLength': 255,
},
# Defined as varchar(255) in column "device_type" in table
# "block_device_mapping"
'device_type': {
'type': 'string', 'maxLength': 255,
},
# Defined as varchar(255) in column "disk_bus" in table
# "block_device_mapping"
'disk_bus': {
'type': 'string', 'maxLength': 255,
},
# Defined as integer in nova/block_device.py:from_api()
# NOTE(mriedem): boot_index=None is also accepted for backward
# compatibility with the legacy v2 API.
'boot_index': {
'type': ['integer', 'string', 'null'],
'pattern': '^-?[0-9]+$',
},
}
block_device_mapping_v2 = copy.deepcopy(legacy_block_device_mapping)
block_device_mapping_v2['properties'].update(block_device_mapping_v2_new_item)
base_create = {
'type': 'object',
'properties': {
@ -85,8 +130,13 @@ base_create = {
'block_device_mapping': {
'type': 'array',
'items': legacy_block_device_mapping
},
'block_device_mapping_v2': {
'type': 'array',
'items': block_device_mapping_v2
}
},
'required': ['name', 'flavorRef'],
'additionalProperties': False,
@ -108,18 +158,38 @@ base_create_v219 = copy.deepcopy(base_create)
base_create_v219['properties']['server'][
'properties']['description'] = parameter_types.description
base_create_v232 = copy.deepcopy(base_create_v219)
base_create_v232['properties']['server'][
'properties']['networks']['items'][
'properties']['tag'] = parameter_types.tag
base_create_v232['properties']['server'][
'properties']['block_device_mapping_v2']['items'][
'properties']['tag'] = parameter_types.tag
# NOTE(artom) the following conditional was merged as
# "if version == '2.32'" The intent all along was to check whether
# version was greater than or equal to 2.32. In other words, we wanted
# to support tags in versions 2.32 and up, but ended up supporting them
# in version 2.32 only. Since we need a new microversion to add request
# body attributes, tags have been re-added in version 2.42.
# NOTE(gmann) Below schema 'base_create_v233' is added (builds on 2.19 schema)
# to keep the above mentioned behavior while merging the extension schema code
# into server schema file. Below is the ref code where BDM tag was originally
# got added for 2.32 microversion *only*.
# Ref- https://github.com/openstack/nova/blob/
# 9882a60e69a5ab8da314a199a56defc05098b743/nova/api/
# openstack/compute/block_device_mapping.py#L71
base_create_v233 = copy.deepcopy(base_create_v219)
base_create_v233['properties']['server'][
'properties']['networks']['items'][
'properties']['tag'] = parameter_types.tag
# 2.37 builds on 2.32 and makes the following changes:
# 1. server.networks is required
# 2. server.networks is now either an enum or a list
# 3. server.networks.uuid is now required to be a uuid
base_create_v237 = copy.deepcopy(base_create_v232)
base_create_v237 = copy.deepcopy(base_create_v233)
base_create_v237['properties']['server']['required'].append('networks')
base_create_v237['properties']['server']['properties']['networks'] = {
'oneOf': [
@ -163,6 +233,9 @@ base_create_v242['properties']['server']['properties']['networks'] = {
},
{'type': 'string', 'enum': ['none', 'auto']},
]}
base_create_v242['properties']['server'][
'properties']['block_device_mapping_v2']['items'][
'properties']['tag'] = parameter_types.tag
# 2.52 builds on 2.42 and makes the following changes:

View File

@ -81,6 +81,7 @@ class ServersController(wsgi.Controller):
schema_server_rebuild_v257 = schema_servers.base_rebuild_v257
schema_server_create_v232 = schema_servers.base_create_v232
schema_server_create_v233 = schema_servers.base_create_v233
schema_server_create_v237 = schema_servers.base_create_v237
schema_server_create_v242 = schema_servers.base_create_v242
schema_server_create_v252 = schema_servers.base_create_v252
@ -92,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 = [
block_device_mapping.get_server_create_schema,
config_drive.get_server_create_schema,
keypairs.get_server_create_schema,
multiple_create.get_server_create_schema,
@ -139,6 +139,7 @@ class ServersController(wsgi.Controller):
self._create_schema(self.schema_server_create_v252, '2.52')
self._create_schema(self.schema_server_create_v242, '2.42')
self._create_schema(self.schema_server_create_v237, '2.37')
self._create_schema(self.schema_server_create_v233, '2.33')
self._create_schema(self.schema_server_create_v232, '2.32')
self._create_schema(self.schema_server_create_v219, '2.19')
self._create_schema(self.schema_server_create, '2.1')
@ -459,7 +460,8 @@ class ServersController(wsgi.Controller):
@validation.schema(schema_server_create_v20, '2.0', '2.0')
@validation.schema(schema_server_create, '2.1', '2.18')
@validation.schema(schema_server_create_v219, '2.19', '2.31')
@validation.schema(schema_server_create_v232, '2.32', '2.36')
@validation.schema(schema_server_create_v232, '2.32', '2.32')
@validation.schema(schema_server_create_v233, '2.33', '2.36')
@validation.schema(schema_server_create_v237, '2.37', '2.41')
@validation.schema(schema_server_create_v242, '2.42', '2.51')
@validation.schema(schema_server_create_v252, '2.52', '2.56')