diff --git a/api-ref/source/os-interface.inc b/api-ref/source/os-interface.inc index 62151cbc3eb..10f3a450e87 100644 --- a/api-ref/source/os-interface.inc +++ b/api-ref/source/os-interface.inc @@ -41,12 +41,18 @@ Response - mac_addr: mac_addr - net_id: net_id_resp - port_id: port_id_resp + - tag: device_tag_nic_attachment_resp **Example List Port Interfaces: JSON response** .. literalinclude:: ../../doc/api_samples/os-attach-interfaces/attach-interfaces-list-resp.json :language: javascript +**Example List Tagged Port Interfaces (v2.70): JSON response** + +.. literalinclude:: ../../doc/api_samples/os-attach-interfaces/v2.70/attach-interfaces-list-resp.json + :language: javascript + Create Interface ================ @@ -103,12 +109,18 @@ Response - net_id: net_id_resp - port_id: port_id_resp - port_state: port_state + - tag: device_tag_nic_attachment_resp **Example Create Interface: JSON response** .. literalinclude:: ../../doc/api_samples/os-attach-interfaces/attach-interfaces-create-resp.json :language: javascript +**Example Create Tagged Interface (v2.70): JSON response** + +.. literalinclude:: ../../doc/api_samples/os-attach-interfaces/v2.70/attach-interfaces-create-resp.json + :language: javascript + Show Port Interface Details =========================== @@ -142,12 +154,18 @@ Response - mac_addr: mac_addr - net_id: net_id_resp - port_id: port_id_resp + - tag: device_tag_nic_attachment_resp **Example Show Port Interface Details: JSON response** .. literalinclude:: ../../doc/api_samples/os-attach-interfaces/attach-interfaces-show-resp.json :language: javascript +**Example Show Tagged Port Interface Details (v2.70): JSON response** + +.. literalinclude:: ../../doc/api_samples/os-attach-interfaces/v2.70/attach-interfaces-show-resp.json + :language: javascript + Detach Interface ================ diff --git a/api-ref/source/os-volume-attachments.inc b/api-ref/source/os-volume-attachments.inc index 7cc8fa69187..8146faf922f 100644 --- a/api-ref/source/os-volume-attachments.inc +++ b/api-ref/source/os-volume-attachments.inc @@ -38,12 +38,18 @@ Response - id: attachment_id_required - serverId: server_id - volumeId: volumeId_resp + - tag: device_tag_bdm_attachment_resp **Example List volume attachments for an instance: JSON response** .. literalinclude:: ../../doc/api_samples/os-volumes/list-volume-attachments-resp.json :language: javascript +**Example List tagged volume attachments for an instance (v2.70): JSON response** + +.. literalinclude:: ../../doc/api_samples/os-volumes/v2.70/list-volume-attachments-resp.json + :language: javascript + Attach a volume to an instance ============================== @@ -94,12 +100,18 @@ Response - id: attachment_id_required - serverId: server_id - volumeId: volumeId_resp + - tag: device_tag_bdm_attachment_resp **Example Attach a volume to an instance: JSON response** .. literalinclude:: ../../doc/api_samples/os-volumes/attach-volume-to-server-resp.json :language: javascript +**Example Attach a tagged volume to an instance (v2.70): JSON response** + +.. literalinclude:: ../../doc/api_samples/os-volumes/v2.70/attach-volume-to-server-resp.json + :language: javascript + Show a detail of a volume attachment ==================================== @@ -129,12 +141,18 @@ Response - id: attachment_id_required - serverId: server_id - volumeId: volumeId_resp + - tag: device_tag_bdm_attachment_resp **Example Show a detail of a volume attachment: JSON response** .. literalinclude:: ../../doc/api_samples/os-volumes/volume-attachment-detail-resp.json :language: javascript +**Example Show a detail of a tagged volume attachment (v2.70): JSON response** + +.. literalinclude:: ../../doc/api_samples/os-volumes/v2.70/volume-attachment-detail-resp.json + :language: javascript + Update a volume attachment ========================== diff --git a/api-ref/source/parameters.yaml b/api-ref/source/parameters.yaml index 0656228dc28..5b9957de3b4 100644 --- a/api-ref/source/parameters.yaml +++ b/api-ref/source/parameters.yaml @@ -2281,6 +2281,13 @@ device_tag_bdm_attachment: required: false type: string min_version: 2.49 +device_tag_bdm_attachment_resp: + description: | + The device tag applied to the volume block device or ``null``. + in: body + required: true + type: string + min_version: 2.70 device_tag_nic: description: | A device role tag that can be applied to a network interface. The guest OS @@ -2305,6 +2312,13 @@ device_tag_nic_attachment: required: false type: string min_version: 2.49 +device_tag_nic_attachment_resp: + description: | + The device tag applied to the virtual network interface or ``null``. + in: body + required: true + type: string + min_version: 2.70 device_type: description: | The device type. For example, ``disk``, ``cdrom``. diff --git a/doc/api_samples/os-attach-interfaces/v2.70/attach-interfaces-create-net_id-req.json b/doc/api_samples/os-attach-interfaces/v2.70/attach-interfaces-create-net_id-req.json new file mode 100644 index 00000000000..d64d7fbc3e0 --- /dev/null +++ b/doc/api_samples/os-attach-interfaces/v2.70/attach-interfaces-create-net_id-req.json @@ -0,0 +1,11 @@ +{ + "interfaceAttachment": { + "fixed_ips": [ + { + "ip_address": "192.168.1.3" + } + ], + "net_id": "3cb9bc59-5699-4588-a4b1-b87f96708bc6", + "tag": "public" + } +} \ No newline at end of file diff --git a/doc/api_samples/os-attach-interfaces/v2.70/attach-interfaces-create-req.json b/doc/api_samples/os-attach-interfaces/v2.70/attach-interfaces-create-req.json new file mode 100644 index 00000000000..4e7285d0e98 --- /dev/null +++ b/doc/api_samples/os-attach-interfaces/v2.70/attach-interfaces-create-req.json @@ -0,0 +1,6 @@ +{ + "interfaceAttachment": { + "port_id": "ce531f90-199f-48c0-816c-13e38010b442", + "tag": "public" + } +} \ No newline at end of file diff --git a/doc/api_samples/os-attach-interfaces/v2.70/attach-interfaces-create-resp.json b/doc/api_samples/os-attach-interfaces/v2.70/attach-interfaces-create-resp.json new file mode 100644 index 00000000000..0b0cf34a912 --- /dev/null +++ b/doc/api_samples/os-attach-interfaces/v2.70/attach-interfaces-create-resp.json @@ -0,0 +1,15 @@ +{ + "interfaceAttachment": { + "fixed_ips": [ + { + "ip_address": "192.168.1.3", + "subnet_id": "f8a6e8f8-c2ec-497c-9f23-da9616de54ef" + } + ], + "mac_addr": "fa:16:3e:4c:2c:30", + "net_id": "3cb9bc59-5699-4588-a4b1-b87f96708bc6", + "port_id": "ce531f90-199f-48c0-816c-13e38010b442", + "port_state": "ACTIVE", + "tag": "public" + } +} \ No newline at end of file diff --git a/doc/api_samples/os-attach-interfaces/v2.70/attach-interfaces-list-resp.json b/doc/api_samples/os-attach-interfaces/v2.70/attach-interfaces-list-resp.json new file mode 100644 index 00000000000..61de503fb4c --- /dev/null +++ b/doc/api_samples/os-attach-interfaces/v2.70/attach-interfaces-list-resp.json @@ -0,0 +1,17 @@ +{ + "interfaceAttachments": [ + { + "fixed_ips": [ + { + "ip_address": "192.168.1.3", + "subnet_id": "f8a6e8f8-c2ec-497c-9f23-da9616de54ef" + } + ], + "mac_addr": "fa:16:3e:4c:2c:30", + "net_id": "3cb9bc59-5699-4588-a4b1-b87f96708bc6", + "port_id": "ce531f90-199f-48c0-816c-13e38010b442", + "port_state": "ACTIVE", + "tag": "public" + } + ] +} \ No newline at end of file diff --git a/doc/api_samples/os-attach-interfaces/v2.70/attach-interfaces-show-resp.json b/doc/api_samples/os-attach-interfaces/v2.70/attach-interfaces-show-resp.json new file mode 100644 index 00000000000..0b0cf34a912 --- /dev/null +++ b/doc/api_samples/os-attach-interfaces/v2.70/attach-interfaces-show-resp.json @@ -0,0 +1,15 @@ +{ + "interfaceAttachment": { + "fixed_ips": [ + { + "ip_address": "192.168.1.3", + "subnet_id": "f8a6e8f8-c2ec-497c-9f23-da9616de54ef" + } + ], + "mac_addr": "fa:16:3e:4c:2c:30", + "net_id": "3cb9bc59-5699-4588-a4b1-b87f96708bc6", + "port_id": "ce531f90-199f-48c0-816c-13e38010b442", + "port_state": "ACTIVE", + "tag": "public" + } +} \ No newline at end of file diff --git a/doc/api_samples/os-volumes/v2.70/attach-volume-to-server-req.json b/doc/api_samples/os-volumes/v2.70/attach-volume-to-server-req.json new file mode 100644 index 00000000000..b754722297d --- /dev/null +++ b/doc/api_samples/os-volumes/v2.70/attach-volume-to-server-req.json @@ -0,0 +1,6 @@ +{ + "volumeAttachment": { + "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f803", + "tag": "foo" + } +} \ No newline at end of file diff --git a/doc/api_samples/os-volumes/v2.70/attach-volume-to-server-resp.json b/doc/api_samples/os-volumes/v2.70/attach-volume-to-server-resp.json new file mode 100644 index 00000000000..9b968680a49 --- /dev/null +++ b/doc/api_samples/os-volumes/v2.70/attach-volume-to-server-resp.json @@ -0,0 +1,9 @@ +{ + "volumeAttachment": { + "device": "/dev/vdd", + "id": "a26887c6-c47b-4654-abb5-dfadf7d3f803", + "serverId": "521b9e49-4855-4a9a-8474-759a86c1b12d", + "tag": "foo", + "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f803" + } +} \ No newline at end of file diff --git a/doc/api_samples/os-volumes/v2.70/list-volume-attachments-resp.json b/doc/api_samples/os-volumes/v2.70/list-volume-attachments-resp.json new file mode 100644 index 00000000000..b1a481dbe0f --- /dev/null +++ b/doc/api_samples/os-volumes/v2.70/list-volume-attachments-resp.json @@ -0,0 +1,18 @@ +{ + "volumeAttachments": [ + { + "device": "/dev/sdd", + "id": "a26887c6-c47b-4654-abb5-dfadf7d3f803", + "serverId": "fb6077e6-c10d-4e81-87fa-cb0f8c103051", + "tag": "foo", + "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f803" + }, + { + "device": "/dev/sdc", + "id": "a26887c6-c47b-4654-abb5-dfadf7d3f804", + "serverId": "fb6077e6-c10d-4e81-87fa-cb0f8c103051", + "tag": null, + "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f804" + } + ] +} \ No newline at end of file diff --git a/doc/api_samples/os-volumes/v2.70/update-volume-req.json b/doc/api_samples/os-volumes/v2.70/update-volume-req.json new file mode 100644 index 00000000000..bba735eec83 --- /dev/null +++ b/doc/api_samples/os-volumes/v2.70/update-volume-req.json @@ -0,0 +1,5 @@ +{ + "volumeAttachment": { + "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f805" + } +} \ No newline at end of file diff --git a/doc/api_samples/os-volumes/v2.70/volume-attachment-detail-resp.json b/doc/api_samples/os-volumes/v2.70/volume-attachment-detail-resp.json new file mode 100644 index 00000000000..a857b82d4d1 --- /dev/null +++ b/doc/api_samples/os-volumes/v2.70/volume-attachment-detail-resp.json @@ -0,0 +1,9 @@ +{ + "volumeAttachment": { + "device": "/dev/sdd", + "id": "a26887c6-c47b-4654-abb5-dfadf7d3f803", + "serverId": "a26887c6-c47b-4654-abb5-dfadf7d3f803", + "tag": "foo", + "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f803" + } +} \ No newline at end of file diff --git a/doc/api_samples/versions/v21-version-get-resp.json b/doc/api_samples/versions/v21-version-get-resp.json index e46aed8fb28..d9d08a41fc6 100644 --- a/doc/api_samples/versions/v21-version-get-resp.json +++ b/doc/api_samples/versions/v21-version-get-resp.json @@ -19,7 +19,7 @@ } ], "status": "CURRENT", - "version": "2.69", + "version": "2.70", "min_version": "2.1", "updated": "2013-07-23T11:33:21Z" } diff --git a/doc/api_samples/versions/versions-get-resp.json b/doc/api_samples/versions/versions-get-resp.json index 8468b0e3f16..1722025e969 100644 --- a/doc/api_samples/versions/versions-get-resp.json +++ b/doc/api_samples/versions/versions-get-resp.json @@ -22,7 +22,7 @@ } ], "status": "CURRENT", - "version": "2.69", + "version": "2.70", "min_version": "2.1", "updated": "2013-07-23T11:33:21Z" } diff --git a/nova/api/openstack/api_version_request.py b/nova/api/openstack/api_version_request.py index 4bbb9d213cd..12ff776bfd3 100644 --- a/nova/api/openstack/api_version_request.py +++ b/nova/api/openstack/api_version_request.py @@ -170,6 +170,8 @@ ``GET /servers/detail``, ``GET /servers/{server_id}`` and ``GET /os-services`` when there is a transient unavailability condition in the deployment like an infrastructure failure. + * 2.70 - Exposes virtual device tags in the response of the + ``os-volume_attachments`` and ``os-interface`` APIs. """ # The minimum and maximum versions of the API supported @@ -178,7 +180,7 @@ # Note(cyeoh): This only applies for the v2.1 API once microversions # support is fully merged. It does not affect the V2 API. _MIN_API_VERSION = "2.1" -_MAX_API_VERSION = "2.69" +_MAX_API_VERSION = "2.70" DEFAULT_API_VERSION = _MIN_API_VERSION # Almost all proxy APIs which are related to network, images and baremetal diff --git a/nova/api/openstack/compute/attach_interfaces.py b/nova/api/openstack/compute/attach_interfaces.py index 891747650ab..91040781e88 100644 --- a/nova/api/openstack/compute/attach_interfaces.py +++ b/nova/api/openstack/compute/attach_interfaces.py @@ -18,6 +18,7 @@ import webob from webob import exc +from nova.api.openstack import api_version_request from nova.api.openstack import common from nova.api.openstack.compute.schemas import attach_interfaces from nova.api.openstack import wsgi @@ -26,18 +27,32 @@ from nova import exception from nova.i18n import _ from nova import network +from nova import objects from nova.policies import attach_interfaces as ai_policies -def _translate_interface_attachment_view(port_info): - """Maps keys for interface attachment details view.""" - return { +def _translate_interface_attachment_view(context, port_info, show_tag=False): + """Maps keys for interface attachment details view. + + :param port_info: dict of port details from the networking service + :param show_tag: If True, includes the "tag" key in the returned dict, + else the "tag" entry is omitted (default: False) + :returns: dict of a subset of details about the port and optionally the + tag associated with the VirtualInterface record in the nova database + """ + info = { 'net_id': port_info['network_id'], 'port_id': port_info['id'], 'mac_addr': port_info['mac_address'], 'port_state': port_info['status'], 'fixed_ips': port_info.get('fixed_ips', None), } + if show_tag: + # Get the VIF for this port (if one exists - VirtualInterface records + # did not exist for neutron ports until the Newton release). + vif = objects.VirtualInterface.get_by_uuid(context, port_info['id']) + info['tag'] = vif.tag if vif else None + return info class InterfaceAttachmentController(wsgi.Controller): @@ -64,9 +79,28 @@ def index(self, req, server_id): except NotImplementedError: common.raise_feature_not_supported() + # If showing tags, get the VirtualInterfaceList for the server and + # map VIFs by port ID. Note that VirtualInterface records did not + # exist for neutron ports until the Newton release so it's OK if we + # are missing records for old servers. + show_tag = api_version_request.is_supported(req, '2.70') + tag_per_port_id = {} + if show_tag: + vifs = objects.VirtualInterfaceList.get_by_instance_uuid( + context, server_id) + tag_per_port_id = {vif.uuid: vif.tag for vif in vifs} + + results = [] ports = data.get('ports', []) - entity_maker = _translate_interface_attachment_view - results = [entity_maker(port) for port in ports] + for port in ports: + # Note that we do not pass show_tag=show_tag to + # _translate_interface_attachment_view because we are handling it + # ourselves here since we have the list of VIFs which is better + # for performance than doing a DB query per port. + info = _translate_interface_attachment_view(context, port) + if show_tag: + info['tag'] = tag_per_port_id.get(port['id']) + results.append(info) return {'interfaceAttachments': results} @@ -94,8 +128,10 @@ def show(self, req, server_id, id): "%(port)s") % {'instance': server_id, 'port': port_id} raise exc.HTTPNotFound(explanation=msg) - return {'interfaceAttachment': _translate_interface_attachment_view( - port_info['port'])} + return {'interfaceAttachment': + _translate_interface_attachment_view( + context, port_info['port'], + show_tag=api_version_request.is_supported(req, '2.70'))} @wsgi.expected_errors((400, 404, 409, 500, 501)) @validation.schema(attach_interfaces.create, '2.0', '2.48') diff --git a/nova/api/openstack/compute/rest_api_version_history.rst b/nova/api/openstack/compute/rest_api_version_history.rst index a1a331b6dfc..c47093fe823 100644 --- a/nova/api/openstack/compute/rest_api_version_history.rst +++ b/nova/api/openstack/compute/rest_api_version_history.rst @@ -879,3 +879,22 @@ minimal set of information obtained from the available information in the API database for the down cells. See `handling down cells `__ for more information. + +2.70 +---- + +Exposes virtual device tags for volume attachments and virtual interfaces +(ports). A ``tag`` parameter is added to the response body for the following +APIs: + +**Volumes** + +* GET /servers/{server_id}/os-volume_attachments (list) +* GET /servers/{server_id}/os-volume_attachments/{volume_id} (show) +* POST /servers/{server_id}/os-volume_attachments (attach) + +**Ports** + +* GET /servers/{server_id}/os-interface (list) +* GET /servers/{server_id}/os-interface/{port_id} (show) +* POST /servers/{server_id}/os-interface (attach) diff --git a/nova/api/openstack/compute/volumes.py b/nova/api/openstack/compute/volumes.py index 3947526ad70..59cf001e771 100644 --- a/nova/api/openstack/compute/volumes.py +++ b/nova/api/openstack/compute/volumes.py @@ -70,7 +70,7 @@ def _translate_volume_summary_view(context, vol): # } # } attachment = list(vol['attachments'].items())[0] - d['attachments'] = [_translate_attachment_detail_view(vol['id'], + d['attachments'] = [_translate_attachment_summary_view(vol['id'], attachment[0], attachment[1].get('mountpoint'))] else: @@ -209,14 +209,20 @@ def create(self, req, body): return wsgi.ResponseObject(result, headers=dict(location=location)) -def _translate_attachment_detail_view(volume_id, instance_uuid, mountpoint): - """Maps keys for attachment details view.""" +def _translate_attachment_detail_view(bdm, show_tag=False): + """Maps keys for attachment details view. - d = _translate_attachment_summary_view(volume_id, - instance_uuid, - mountpoint) + :param bdm: BlockDeviceMapping object for an attached volume + :param show_tag: True if the "tag" field should be in the response, False + to exclude the "tag" field from the response + """ + + d = _translate_attachment_summary_view( + bdm.volume_id, bdm.instance_uuid, bdm.device_name) + + if show_tag: + d['tag'] = bdm.tag - # No additional data / lookups at the moment return d @@ -276,11 +282,10 @@ def index(self, req, server_id): limited_list = common.limited(bdms, req) results = [] + show_tag = api_version_request.is_supported(req, '2.70') for bdm in limited_list: if bdm.volume_id: - va = _translate_attachment_summary_view(bdm.volume_id, - bdm.instance_uuid, - bdm.device_name) + va = _translate_attachment_detail_view(bdm, show_tag=show_tag) results.append(va) return {'volumeAttachments': results} @@ -303,11 +308,9 @@ def show(self, req, server_id, id): {'instance': server_id, 'volume': volume_id}) raise exc.HTTPNotFound(explanation=msg) - assigned_mountpoint = bdm.device_name + show_tag = api_version_request.is_supported(req, '2.70') return {'volumeAttachment': _translate_attachment_detail_view( - volume_id, - instance.uuid, - assigned_mountpoint)} + bdm, show_tag=show_tag)} # TODO(mriedem): This API should return a 202 instead of a 200 response. @wsgi.expected_errors((400, 403, 404, 409)) @@ -356,11 +359,17 @@ def create(self, req, server_id, body): raise exc.HTTPForbidden(explanation=e.format_message()) # The attach is async + # NOTE(mriedem): It would be nice to use + # _translate_attachment_summary_view here but that does not include + # the 'device' key if device is None or the empty string which would + # be a backward incompatible change. attachment = {} attachment['id'] = volume_id attachment['serverId'] = server_id attachment['volumeId'] = volume_id attachment['device'] = device + if api_version_request.is_supported(req, '2.70'): + attachment['tag'] = tag return {'volumeAttachment': attachment} @wsgi.response(202) diff --git a/nova/tests/functional/api_sample_tests/api_samples/os-attach-interfaces/v2.70/attach-interfaces-create-net_id-req.json.tpl b/nova/tests/functional/api_sample_tests/api_samples/os-attach-interfaces/v2.70/attach-interfaces-create-net_id-req.json.tpl new file mode 100644 index 00000000000..dcdc82e90d0 --- /dev/null +++ b/nova/tests/functional/api_sample_tests/api_samples/os-attach-interfaces/v2.70/attach-interfaces-create-net_id-req.json.tpl @@ -0,0 +1,11 @@ +{ + "interfaceAttachment": { + "fixed_ips": [ + { + "ip_address": "192.168.1.3" + } + ], + "net_id": "3cb9bc59-5699-4588-a4b1-b87f96708bc6", + "tag": "%(tag)s" + } +} diff --git a/nova/tests/functional/api_sample_tests/api_samples/os-attach-interfaces/v2.70/attach-interfaces-create-req.json.tpl b/nova/tests/functional/api_sample_tests/api_samples/os-attach-interfaces/v2.70/attach-interfaces-create-req.json.tpl new file mode 100644 index 00000000000..e120e127945 --- /dev/null +++ b/nova/tests/functional/api_sample_tests/api_samples/os-attach-interfaces/v2.70/attach-interfaces-create-req.json.tpl @@ -0,0 +1,6 @@ +{ + "interfaceAttachment": { + "port_id": "%(port_id)s", + "tag": "%(tag)s" + } +} diff --git a/nova/tests/functional/api_sample_tests/api_samples/os-attach-interfaces/v2.70/attach-interfaces-create-resp.json.tpl b/nova/tests/functional/api_sample_tests/api_samples/os-attach-interfaces/v2.70/attach-interfaces-create-resp.json.tpl new file mode 100644 index 00000000000..0f6ad7fa128 --- /dev/null +++ b/nova/tests/functional/api_sample_tests/api_samples/os-attach-interfaces/v2.70/attach-interfaces-create-resp.json.tpl @@ -0,0 +1,15 @@ +{ + "interfaceAttachment": { + "fixed_ips": [ + { + "ip_address": "%(ip_address)s", + "subnet_id": "%(subnet_id)s" + } + ], + "mac_addr": "%(mac_addr)s", + "net_id": "%(net_id)s", + "port_id": "%(port_id)s", + "port_state": "%(port_state)s", + "tag": "%(tag)s" + } +} \ No newline at end of file diff --git a/nova/tests/functional/api_sample_tests/api_samples/os-attach-interfaces/v2.70/attach-interfaces-list-resp.json.tpl b/nova/tests/functional/api_sample_tests/api_samples/os-attach-interfaces/v2.70/attach-interfaces-list-resp.json.tpl new file mode 100644 index 00000000000..456a46c3c70 --- /dev/null +++ b/nova/tests/functional/api_sample_tests/api_samples/os-attach-interfaces/v2.70/attach-interfaces-list-resp.json.tpl @@ -0,0 +1,17 @@ +{ + "interfaceAttachments": [ + { + "fixed_ips": [ + { + "ip_address": "%(ip_address)s", + "subnet_id": "%(subnet_id)s" + } + ], + "mac_addr": "%(mac_addr)s", + "net_id": "%(net_id)s", + "port_id": "%(port_id)s", + "port_state": "%(port_state)s", + "tag": "%(tag)s" + } + ] +} \ No newline at end of file diff --git a/nova/tests/functional/api_sample_tests/api_samples/os-attach-interfaces/v2.70/attach-interfaces-show-resp.json.tpl b/nova/tests/functional/api_sample_tests/api_samples/os-attach-interfaces/v2.70/attach-interfaces-show-resp.json.tpl new file mode 100644 index 00000000000..0f6ad7fa128 --- /dev/null +++ b/nova/tests/functional/api_sample_tests/api_samples/os-attach-interfaces/v2.70/attach-interfaces-show-resp.json.tpl @@ -0,0 +1,15 @@ +{ + "interfaceAttachment": { + "fixed_ips": [ + { + "ip_address": "%(ip_address)s", + "subnet_id": "%(subnet_id)s" + } + ], + "mac_addr": "%(mac_addr)s", + "net_id": "%(net_id)s", + "port_id": "%(port_id)s", + "port_state": "%(port_state)s", + "tag": "%(tag)s" + } +} \ No newline at end of file diff --git a/nova/tests/functional/api_sample_tests/api_samples/os-volumes/v2.70/attach-volume-to-server-req.json.tpl b/nova/tests/functional/api_sample_tests/api_samples/os-volumes/v2.70/attach-volume-to-server-req.json.tpl new file mode 100644 index 00000000000..770be1f4b6b --- /dev/null +++ b/nova/tests/functional/api_sample_tests/api_samples/os-volumes/v2.70/attach-volume-to-server-req.json.tpl @@ -0,0 +1,6 @@ +{ + "volumeAttachment": { + "volumeId": "%(volume_id)s", + "tag": "%(tag)s" + } +} diff --git a/nova/tests/functional/api_sample_tests/api_samples/os-volumes/v2.70/attach-volume-to-server-resp.json.tpl b/nova/tests/functional/api_sample_tests/api_samples/os-volumes/v2.70/attach-volume-to-server-resp.json.tpl new file mode 100644 index 00000000000..96f207260c4 --- /dev/null +++ b/nova/tests/functional/api_sample_tests/api_samples/os-volumes/v2.70/attach-volume-to-server-resp.json.tpl @@ -0,0 +1,9 @@ +{ + "volumeAttachment": { + "device": "%(device)s", + "id": "%(volume_id)s", + "serverId": "%(uuid)s", + "tag": "%(tag)s", + "volumeId": "%(volume_id)s" + } +} diff --git a/nova/tests/functional/api_sample_tests/api_samples/os-volumes/v2.70/list-volume-attachments-resp.json.tpl b/nova/tests/functional/api_sample_tests/api_samples/os-volumes/v2.70/list-volume-attachments-resp.json.tpl new file mode 100644 index 00000000000..88b3632d9da --- /dev/null +++ b/nova/tests/functional/api_sample_tests/api_samples/os-volumes/v2.70/list-volume-attachments-resp.json.tpl @@ -0,0 +1,18 @@ +{ + "volumeAttachments": [ + { + "device": "/dev/sdd", + "id": "a26887c6-c47b-4654-abb5-dfadf7d3f803", + "serverId": "%(uuid)s", + "tag": "%(tag)s", + "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f803" + }, + { + "device": "/dev/sdc", + "id": "a26887c6-c47b-4654-abb5-dfadf7d3f804", + "serverId": "%(uuid)s", + "tag": null, + "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f804" + } + ] +} diff --git a/nova/tests/functional/api_sample_tests/api_samples/os-volumes/v2.70/update-volume-req.json.tpl b/nova/tests/functional/api_sample_tests/api_samples/os-volumes/v2.70/update-volume-req.json.tpl new file mode 100644 index 00000000000..41411472ab0 --- /dev/null +++ b/nova/tests/functional/api_sample_tests/api_samples/os-volumes/v2.70/update-volume-req.json.tpl @@ -0,0 +1,5 @@ +{ + "volumeAttachment": { + "volumeId": "%(volume_id)s" + } +} diff --git a/nova/tests/functional/api_sample_tests/api_samples/os-volumes/v2.70/volume-attachment-detail-resp.json.tpl b/nova/tests/functional/api_sample_tests/api_samples/os-volumes/v2.70/volume-attachment-detail-resp.json.tpl new file mode 100644 index 00000000000..b8ac7e18339 --- /dev/null +++ b/nova/tests/functional/api_sample_tests/api_samples/os-volumes/v2.70/volume-attachment-detail-resp.json.tpl @@ -0,0 +1,9 @@ +{ + "volumeAttachment": { + "device": "/dev/sdd", + "id": "a26887c6-c47b-4654-abb5-dfadf7d3f803", + "serverId": "%(uuid)s", + "tag": "%(tag)s", + "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f803" + } +} diff --git a/nova/tests/functional/api_sample_tests/test_attach_interfaces.py b/nova/tests/functional/api_sample_tests/test_attach_interfaces.py index 7bdb6dc8d3f..5c445cc2115 100644 --- a/nova/tests/functional/api_sample_tests/test_attach_interfaces.py +++ b/nova/tests/functional/api_sample_tests/test_attach_interfaces.py @@ -15,6 +15,7 @@ from nova import exception from nova.network import api as network_api +from nova import objects from nova.tests.functional.api_sample_tests import test_servers from nova.tests.unit import fake_network_cache_model @@ -98,18 +99,23 @@ def generalize_subs(self, subs, vanilla_regexes): subs['ip_address'] = vanilla_regexes['ip'] return subs + def _get_subs(self): + """Allows sub-classes to override the subs dict used for verification. + """ + return { + 'ip_address': '192.168.1.3', + 'subnet_id': 'f8a6e8f8-c2ec-497c-9f23-da9616de54ef', + 'mac_addr': 'fa:16:3e:4c:2c:30', + 'net_id': '3cb9bc59-5699-4588-a4b1-b87f96708bc6', + 'port_id': 'ce531f90-199f-48c0-816c-13e38010b442', + 'port_state': 'ACTIVE' + } + def test_list_interfaces(self): instance_uuid = self._post_server() response = self._do_get('servers/%s/os-interface' % instance_uuid) - subs = { - 'ip_address': '192.168.1.3', - 'subnet_id': 'f8a6e8f8-c2ec-497c-9f23-da9616de54ef', - 'mac_addr': 'fa:16:3e:4c:2c:30', - 'net_id': '3cb9bc59-5699-4588-a4b1-b87f96708bc6', - 'port_id': 'ce531f90-199f-48c0-816c-13e38010b442', - 'port_state': 'ACTIVE' - } + subs = self._get_subs() self._verify_response('attach-interfaces-list-resp', subs, response, 200) @@ -125,28 +131,14 @@ def test_show_interfaces(self): self._stub_show_for_instance(instance_uuid, port_id) response = self._do_get('servers/%s/os-interface/%s' % (instance_uuid, port_id)) - subs = { - 'ip_address': '192.168.1.3', - 'subnet_id': 'f8a6e8f8-c2ec-497c-9f23-da9616de54ef', - 'mac_addr': 'fa:16:3e:4c:2c:30', - 'net_id': '3cb9bc59-5699-4588-a4b1-b87f96708bc6', - 'port_id': port_id, - 'port_state': 'ACTIVE' - } + subs = self._get_subs() self._verify_response('attach-interfaces-show-resp', subs, response, 200) def test_create_interfaces(self, instance_uuid=None): if instance_uuid is None: instance_uuid = self._post_server() - subs = { - 'net_id': '3cb9bc59-5699-4588-a4b1-b87f96708bc6', - 'port_id': 'ce531f90-199f-48c0-816c-13e38010b442', - 'subnet_id': 'f8a6e8f8-c2ec-497c-9f23-da9616de54ef', - 'ip_address': '192.168.1.3', - 'port_state': 'ACTIVE', - 'mac_addr': 'fa:16:3e:4c:2c:30', - } + subs = self._get_subs() self._stub_show_for_instance(instance_uuid, subs['port_id']) response = self._do_post('servers/%s/os-interface' % instance_uuid, @@ -158,14 +150,7 @@ def test_create_interfaces_with_net_id_and_fixed_ips(self, instance_uuid=None): if instance_uuid is None: instance_uuid = self._post_server() - subs = { - 'net_id': '3cb9bc59-5699-4588-a4b1-b87f96708bc6', - 'port_id': 'ce531f90-199f-48c0-816c-13e38010b442', - 'subnet_id': 'f8a6e8f8-c2ec-497c-9f23-da9616de54ef', - 'ip_address': '192.168.1.3', - 'port_state': 'ACTIVE', - 'mac_addr': 'fa:16:3e:4c:2c:30', - } + subs = self._get_subs() self._stub_show_for_instance(instance_uuid, subs['port_id']) response = self._do_post('servers/%s/os-interface' % instance_uuid, @@ -251,3 +236,35 @@ def test_create_interfaces(self, instance_uuid=None): 'attach-interfaces-create-req', subs) self._verify_response('attach-interfaces-create-resp', subs, response, 200) + + +class AttachInterfacesSampleV270JsonTest(AttachInterfacesSampleJsonTest): + """Tests for the 2.70 microversion in the os-interface API + which returns the 'tag' field in response bodies to GET and POST methods. + """ + microversion = '2.70' + scenarios = [('v2_70', {'api_major_version': 'v2.1'})] + + def setUp(self): + super(AttachInterfacesSampleV270JsonTest, self).setUp() + port_id = 'ce531f90-199f-48c0-816c-13e38010b442' + + def fake_virtual_interface_list_by_instance_uuid(*args, **kwargs): + return objects.VirtualInterfaceList(objects=[ + objects.VirtualInterface( + # All these tests care about is the uuid and tag. + uuid=port_id, tag='public')]) + + def fake_virtual_interface_get_by_uuid(*args, **kwargs): + return objects.VirtualInterface(uuid=port_id, tag='public') + + self.stub_out('nova.objects.VirtualInterface.get_by_uuid', + fake_virtual_interface_get_by_uuid) + self.stub_out('nova.objects.VirtualInterfaceList.get_by_instance_uuid', + fake_virtual_interface_list_by_instance_uuid) + + def _get_subs(self): + subs = super(AttachInterfacesSampleV270JsonTest, self)._get_subs() + # 2.70 adds the tag parameter to the request and response. + subs['tag'] = 'public' + return subs diff --git a/nova/tests/functional/api_sample_tests/test_volumes.py b/nova/tests/functional/api_sample_tests/test_volumes.py index 1d70f489976..b083689fcc8 100644 --- a/nova/tests/functional/api_sample_tests/test_volumes.py +++ b/nova/tests/functional/api_sample_tests/test_volumes.py @@ -206,6 +206,14 @@ class VolumeAttachmentsSample(test_servers.ServersSampleBase): OLD_VOLUME_ID = 'a26887c6-c47b-4654-abb5-dfadf7d3f803' NEW_VOLUME_ID = 'a26887c6-c47b-4654-abb5-dfadf7d3f805' + def _get_tags_per_volume(self): + """Allows subclasses to override which volumes have tags + + :returns: dict, keyed by volume ID, to tag value; if a volume ID is + not found in the resulting dict it is assumed to not have a tag + """ + return {} + def _stub_db_bdms_get_all_by_instance(self, server_id): def fake_bdms_get_all_by_instance(context, instance_uuid, @@ -220,6 +228,9 @@ def fake_bdms_get_all_by_instance(context, instance_uuid, 'instance_uuid': server_id, 'source_type': 'volume', 'destination_type': 'volume', 'device_name': '/dev/sdc'}) ] + tags_per_volume = self._get_tags_per_volume() + for bdm_dict in bdms: + bdm_dict['tag'] = tags_per_volume.get(bdm_dict['volume_id']) return bdms self.stub_out('nova.db.api.block_device_mapping_get_all_by_instance', @@ -227,12 +238,14 @@ def fake_bdms_get_all_by_instance(context, instance_uuid, def fake_bdm_get_by_volume_and_instance( self, ctxt, volume_id, instance_uuid, expected_attrs=None): + tag = self._get_tags_per_volume().get(self.OLD_VOLUME_ID) return objects.BlockDeviceMapping._from_db_object( ctxt, objects.BlockDeviceMapping(), fake_block_device.FakeDbBlockDeviceDict( {'id': 1, 'volume_id': self.OLD_VOLUME_ID, 'instance_uuid': instance_uuid, 'source_type': 'volume', - 'destination_type': 'volume', 'device_name': '/dev/sdd'}) + 'destination_type': 'volume', 'device_name': '/dev/sdd', + 'tag': tag}) ) def _stub_compute_api_get(self): @@ -319,7 +332,8 @@ def test_list_volume_attachments(self): response = self._do_get('servers/%s/os-volume_attachments' % server_id) - self._verify_response('list-volume-attachments-resp', {}, + subs = self._get_vol_attachment_subs({}) + self._verify_response('list-volume-attachments-resp', subs, response, 200) def test_volume_attachment_detail(self): @@ -330,7 +344,8 @@ def test_volume_attachment_detail(self): self._stub_compute_api_get() response = self._do_get('servers/%s/os-volume_attachments/%s' % (server_id, self.OLD_VOLUME_ID)) - self._verify_response('volume-attachment-detail-resp', {}, + subs = self._get_vol_attachment_subs({}) + self._verify_response('volume-attachment-detail-resp', subs, response, 200) def test_volume_attachment_delete(self): @@ -379,3 +394,15 @@ def setUp(self): def _get_vol_attachment_subs(self, subs): return dict(subs, tag='foo') + + +class VolumeAttachmentsSampleV270(VolumeAttachmentsSampleV249): + """2.70 adds the "tag" parameter to the response body""" + microversion = '2.70' + scenarios = [('v2_70', {'api_major_version': 'v2.1'})] + + def _get_tags_per_volume(self): + return { + self.OLD_VOLUME_ID: 'foo', + self.NEW_VOLUME_ID: None + } diff --git a/releasenotes/notes/microversion-2.70-expose-virtual-device-tags-ca82ba6ee6cf9272.yaml b/releasenotes/notes/microversion-2.70-expose-virtual-device-tags-ca82ba6ee6cf9272.yaml new file mode 100644 index 00000000000..bd2274d742f --- /dev/null +++ b/releasenotes/notes/microversion-2.70-expose-virtual-device-tags-ca82ba6ee6cf9272.yaml @@ -0,0 +1,18 @@ +--- +features: + - | + The 2.70 compute API microversion exposes virtual device tags for volume + attachments and virtual interfaces (ports). A ``tag`` parameter is added + to the response body for the following APIs: + + **Volumes** + + * GET /servers/{server_id}/os-volume_attachments (list) + * GET /servers/{server_id}/os-volume_attachments/{volume_id} (show) + * POST /servers/{server_id}/os-volume_attachments (attach) + + **Ports** + + * GET /servers/{server_id}/os-interface (list) + * GET /servers/{server_id}/os-interface/{port_id} (show) + * POST /servers/{server_id}/os-interface (attach)