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:
@@ -64,14 +64,6 @@
|
||||
"namespace": "http://docs.openstack.org/compute/ext/extended_status/api/v1.1",
|
||||
"updated": "2011-11-03T00:00:00+00:00"
|
||||
},
|
||||
{
|
||||
"alias": "os-extended-volumes",
|
||||
"description": "Extended Volumes support.",
|
||||
"links": [],
|
||||
"name": "ExtendedVolumes",
|
||||
"namespace": "http://docs.openstack.org/compute/ext/extended_volumes/api/v1.1",
|
||||
"updated": "2013-06-07T00:00:00+00:00"
|
||||
},
|
||||
{
|
||||
"alias": "OS-EXT-VIF-NET",
|
||||
"description": "Adds network id parameter to the virtual interface list.",
|
||||
@@ -160,6 +152,14 @@
|
||||
"namespace": "http://docs.openstack.org/compute/ext/baremetal_nodes/api/v2",
|
||||
"updated": "2013-01-04T00:00:00+00:00"
|
||||
},
|
||||
{
|
||||
"alias": "os-block-device-mapping-v2-boot",
|
||||
"description": "Allow boot with the new BDM data format.",
|
||||
"links": [],
|
||||
"name": "BlockDeviceMappingV2Boot",
|
||||
"namespace": "http://docs.openstack.org/compute/ext/block_device_mapping_v2_boot/api/v2",
|
||||
"updated": "2013-07-08T00:00:00+00:00"
|
||||
},
|
||||
{
|
||||
"alias": "os-cell-capacities",
|
||||
"description": "Adding functionality to get cell capacities.",
|
||||
@@ -280,6 +280,14 @@
|
||||
"namespace": "http://docs.openstack.org/compute/ext/extended_services/api/v2",
|
||||
"updated": "2013-05-17T00:00:00-00:00"
|
||||
},
|
||||
{
|
||||
"alias": "os-extended-volumes",
|
||||
"description": "Extended Volumes support.",
|
||||
"links": [],
|
||||
"name": "ExtendedVolumes",
|
||||
"namespace": "http://docs.openstack.org/compute/ext/extended_volumes/api/v1.1",
|
||||
"updated": "2013-06-07T00:00:00+00:00"
|
||||
},
|
||||
{
|
||||
"alias": "os-fixed-ips",
|
||||
"description": "Fixed IPs support.",
|
||||
@@ -416,6 +424,14 @@
|
||||
"namespace": "http://docs.openstack.org/compute/ext/keypairs/api/v1.1",
|
||||
"updated": "2011-08-08T00:00:00+00:00"
|
||||
},
|
||||
{
|
||||
"alias": "os-migrations",
|
||||
"description": "Provide data on migrations.",
|
||||
"links": [],
|
||||
"name": "Migrations",
|
||||
"namespace": "http://docs.openstack.org/compute/ext/migrations/api/v2.0",
|
||||
"updated": "2013-05-30T00:00:00+00:00"
|
||||
},
|
||||
{
|
||||
"alias": "os-multiple-create",
|
||||
"description": "Allow multiple create in the Create Server v1.1 API.",
|
||||
@@ -591,14 +607,6 @@
|
||||
"name": "Volumes",
|
||||
"namespace": "http://docs.openstack.org/compute/ext/volumes/api/v1.1",
|
||||
"updated": "2011-03-25T00:00:00+00:00"
|
||||
},
|
||||
{
|
||||
"alias": "os-migrations",
|
||||
"description": "Provide data on migrations.",
|
||||
"links": [],
|
||||
"name": "Migrations",
|
||||
"namespace": "http://docs.openstack.org/compute/ext/migrations/api/v2.0",
|
||||
"updated": "2013-05-30T00:00:00+00:00"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -24,9 +24,6 @@
|
||||
<extension alias="OS-EXT-STS" updated="2011-11-03T00:00:00+00:00" namespace="http://docs.openstack.org/compute/ext/extended_status/api/v1.1" name="ExtendedStatus">
|
||||
<description>Extended Status support.</description>
|
||||
</extension>
|
||||
<extension alias="os-extended-volumes" updated="2013-06-07T00:00:00+00:00" namespace="http://docs.openstack.org/compute/ext/extended_volumes/api/v1.1" name="ExtendedVolumes">
|
||||
<description>Extended Volumes support.</description>
|
||||
</extension>
|
||||
<extension alias="OS-EXT-VIF-NET" updated="2013-03-07T00:00:00+00:00" namespace="http://docs.openstack.org/compute/ext/extended-virtual-interfaces-net/api/v1.1" name="ExtendedVIFNet">
|
||||
<description>Adds network id parameter to the virtual interface list.</description>
|
||||
</extension>
|
||||
@@ -66,6 +63,9 @@
|
||||
<extension alias="os-baremetal-nodes" updated="2013-01-04T00:00:00+00:00" namespace="http://docs.openstack.org/compute/ext/baremetal_nodes/api/v2" name="BareMetalNodes">
|
||||
<description>Admin-only bare-metal node administration.</description>
|
||||
</extension>
|
||||
<extension alias="os-block-device-mapping-v2-boot" updated="2013-07-08T00:00:00+00:00" namespace="http://docs.openstack.org/compute/ext/block_device_mapping_v2_boot/api/v2" name="BlockDeviceMappingV2Boot">
|
||||
<description>Allow boot with the new BDM data format.</description>
|
||||
</extension>
|
||||
<extension alias="os-cell-capacities" updated="2013-05-27T00:00:00+00:00" namespace="http://docs.openstack.org/compute/ext/cell_capacities/api/v1.1" name="CellCapacities">
|
||||
<description>Adding functionality to get cell capacities.</description>
|
||||
</extension>
|
||||
@@ -123,6 +123,9 @@
|
||||
<extension alias="os-extended-services" updated="2013-05-17T00:00:00-00:00" namespace="http://docs.openstack.org/compute/ext/extended_services/api/v2" name="ExtendedServices">
|
||||
<description>Extended services support.</description>
|
||||
</extension>
|
||||
<extension alias="os-extended-volumes" updated="2013-06-07T00:00:00+00:00" namespace="http://docs.openstack.org/compute/ext/extended_volumes/api/v1.1" name="ExtendedVolumes">
|
||||
<description>Extended Volumes support.</description>
|
||||
</extension>
|
||||
<extension alias="os-fixed-ips" updated="2012-10-18T13:25:27-06:00" namespace="http://docs.openstack.org/compute/ext/fixed_ips/api/v2" name="FixedIPs">
|
||||
<description>Fixed IPs support.</description>
|
||||
</extension>
|
||||
@@ -176,6 +179,9 @@
|
||||
<extension alias="os-keypairs" updated="2011-08-08T00:00:00+00:00" namespace="http://docs.openstack.org/compute/ext/keypairs/api/v1.1" name="Keypairs">
|
||||
<description>Keypair Support.</description>
|
||||
</extension>
|
||||
<extension alias="os-migrations" updated="2013-05-30T00:00:00+00:00" namespace="http://docs.openstack.org/compute/ext/migrations/api/v2.0" name="Migrations">
|
||||
<description>Provide data on migrations.</description>
|
||||
</extension>
|
||||
<extension alias="os-multiple-create" updated="2012-08-07T00:00:00+00:00" namespace="http://docs.openstack.org/compute/ext/multiplecreate/api/v1.1" name="MultipleCreate">
|
||||
<description>Allow multiple create in the Create Server v1.1 API.</description>
|
||||
</extension>
|
||||
@@ -242,8 +248,4 @@
|
||||
<extension alias="os-volumes" updated="2011-03-25T00:00:00+00:00" namespace="http://docs.openstack.org/compute/ext/volumes/api/v1.1" name="Volumes">
|
||||
<description>Volumes support.</description>
|
||||
</extension>
|
||||
<extension alias="os-migrations" updated="2013-05-30T00:00:00+00:00"
|
||||
namespace="http://docs.openstack.org/compute/ext/migrations/api/v2.0" name="Migrations">
|
||||
<description>Provide data on migrations.</description>
|
||||
</extension>
|
||||
</extensions>
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"server" : {
|
||||
"name" : "new-server-test",
|
||||
"imageRef" : "http://openstack.example.com/openstack/images/70a599e0-31e7-49b7-b260-868f441e862b",
|
||||
"flavorRef" : "http://openstack.example.com/openstack/flavors/1",
|
||||
"metadata" : {
|
||||
"My Server Name" : "Apache1"
|
||||
},
|
||||
"personality" : [
|
||||
{
|
||||
"path" : "/etc/banner.txt",
|
||||
"contents" : "ICAgICAgDQoiQSBjbG91ZCBkb2VzIG5vdCBrbm93IHdoeSBpdCBtb3ZlcyBpbiBqdXN0IHN1Y2ggYSBkaXJlY3Rpb24gYW5kIGF0IHN1Y2ggYSBzcGVlZC4uLkl0IGZlZWxzIGFuIGltcHVsc2lvbi4uLnRoaXMgaXMgdGhlIHBsYWNlIHRvIGdvIG5vdy4gQnV0IHRoZSBza3kga25vd3MgdGhlIHJlYXNvbnMgYW5kIHRoZSBwYXR0ZXJucyBiZWhpbmQgYWxsIGNsb3VkcywgYW5kIHlvdSB3aWxsIGtub3csIHRvbywgd2hlbiB5b3UgbGlmdCB5b3Vyc2VsZiBoaWdoIGVub3VnaCB0byBzZWUgYmV5b25kIGhvcml6b25zLiINCg0KLVJpY2hhcmQgQmFjaA=="
|
||||
}
|
||||
],
|
||||
"block_device_mapping_v2": [
|
||||
{
|
||||
"device_name": "/dev/sdb1",
|
||||
"source_type": "blank",
|
||||
"destination_type": "local",
|
||||
"delete_on_termination": "True",
|
||||
"guest_format": "swap",
|
||||
"boot_index": "-1"
|
||||
},
|
||||
{
|
||||
"device_name": "/dev/sda1",
|
||||
"source_type": "volume",
|
||||
"destination_type": "volume",
|
||||
"uuid": "fake-volume-id-1",
|
||||
"boot_index": "0"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<server xmlns="http://docs.openstack.org/compute/api/v1.1" imageRef="http://openstack.example.com/openstack/images/70a599e0-31e7-49b7-b260-868f441e862b" flavorRef="http://openstack.example.com/openstack/flavors/1" name="new-server-test">
|
||||
<metadata>
|
||||
<meta key="My Server Name">Apache1</meta>
|
||||
</metadata>
|
||||
<personality>
|
||||
<file path="/etc/banner.txt">
|
||||
ICAgICAgDQoiQSBjbG91ZCBkb2VzIG5vdCBrbm93IHdoeSBp
|
||||
dCBtb3ZlcyBpbiBqdXN0IHN1Y2ggYSBkaXJlY3Rpb24gYW5k
|
||||
IGF0IHN1Y2ggYSBzcGVlZC4uLkl0IGZlZWxzIGFuIGltcHVs
|
||||
c2lvbi4uLnRoaXMgaXMgdGhlIHBsYWNlIHRvIGdvIG5vdy4g
|
||||
QnV0IHRoZSBza3kga25vd3MgdGhlIHJlYXNvbnMgYW5kIHRo
|
||||
ZSBwYXR0ZXJucyBiZWhpbmQgYWxsIGNsb3VkcywgYW5kIHlv
|
||||
dSB3aWxsIGtub3csIHRvbywgd2hlbiB5b3UgbGlmdCB5b3Vy
|
||||
c2VsZiBoaWdoIGVub3VnaCB0byBzZWUgYmV5b25kIGhvcml6
|
||||
b25zLiINCg0KLVJpY2hhcmQgQmFjaA==
|
||||
</file>
|
||||
</personality>
|
||||
<block_device_mapping_v2>
|
||||
<mapping device_name="/dev/sdb1" source_type="blank" destination_type="local" delete_on_termination="True" guest_format="swap" boot_index="-1"></mapping>
|
||||
<mapping device_name="/dev/sda1" source_type="volume" destination_type="volume" uuid="fake-volume-id-1" boot_index="0"></mapping>
|
||||
</block_device_mapping_v2>
|
||||
</server>
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"server": {
|
||||
"adminPass": "N4x7wFX6iN8D",
|
||||
"id": "babd1af0-4fc6-4529-b32f-aad69811ccf5",
|
||||
"links": [
|
||||
{
|
||||
"href": "http://openstack.example.com/v2/openstack/servers/babd1af0-4fc6-4529-b32f-aad69811ccf5",
|
||||
"rel": "self"
|
||||
},
|
||||
{
|
||||
"href": "http://openstack.example.com/openstack/servers/babd1af0-4fc6-4529-b32f-aad69811ccf5",
|
||||
"rel": "bookmark"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<server xmlns:atom="http://www.w3.org/2005/Atom" xmlns="http://docs.openstack.org/compute/api/v1.1" id="fdbce07b-097e-4ab1-8141-b1c847861aa1" adminPass="zA62GVkFvN74">
|
||||
<metadata/>
|
||||
<atom:link href="http://openstack.example.com/v2/openstack/servers/fdbce07b-097e-4ab1-8141-b1c847861aa1" rel="self"/>
|
||||
<atom:link href="http://openstack.example.com/openstack/servers/fdbce07b-097e-4ab1-8141-b1c847861aa1" rel="bookmark"/>
|
||||
</server>
|
||||
@@ -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 |
|
||||
|
||||
Reference in New Issue
Block a user