Servers API for the new BDM format

This patch makes the nova API aware and able to accept the new block
device mapping format introduced in
If30afdb59d4c4268b97d3d10270df2cc729a0c4c when booting an instance.

It does so by introducing a new extension into the v2 API. There is no
v3 extension as part of this patch because volume extension is going
away in v3 and thus this functionality can be part of the core servers
extension. This will be done in a subsequent patch.

The compute API create method will still convert these back to the
legacy format for the time being until the compute API will know how to
take advantage of the new format.

As this change adds the new API extension, marking it as DocImpact so
that the changes and the API data format can be documented.

blueprint: improve-block-device-handling
Change-Id: I2c1b63e41deca26f727fb9ed912a55494db9c76c
This commit is contained in:
Nikola Dipanov
2013-07-18 16:55:52 +02:00
parent 84b730b70f
commit 8c3475706d
21 changed files with 589 additions and 57 deletions

View File

@@ -54,6 +54,17 @@ bdm_db_inherited_fields = set(['created_at', 'updated_at',
'deleted_at', 'deleted'])
bdm_new_non_api_fields = set(['volume_id', 'snapshot_id',
'image_id', 'connection_info'])
bdm_new_api_only_fields = set(['uuid'])
bdm_new_api_fields = ((bdm_new_fields - bdm_new_non_api_fields) |
bdm_new_api_only_fields)
class BlockDeviceDict(dict):
"""Represents a Block Device Mapping in Nova."""
@@ -126,6 +137,27 @@ class BlockDeviceDict(dict):
return cls(new_bdm, non_computable_fields)
@classmethod
def from_api(cls, api_dict):
"""Transform the API format of data to the internally used one.
Only validate if the source_type field makes sense.
"""
if not api_dict.get('no_device'):
source_type = api_dict.get('source_type')
device_uuid = api_dict.get('uuid')
if source_type not in ('volume', 'image', 'snapshot', 'blank'):
raise exception.InvalidBDMFormat()
elif source_type != 'blank':
if not device_uuid:
raise exception.InvalidBDMFormat()
api_dict[source_type + '_id'] = device_uuid
api_dict.pop('uuid', None)
return cls(api_dict)
def legacy(self):
copy_over_fields = bdm_legacy_fields - set(['virtual_name'])
copy_over_fields |= (bdm_db_only_fields |