Add microversion to expose virtual device tags
This change adds a new microversion to expose virtual device tags for volumes and ports attached to a server. Implements blueprint expose-virtual-device-tags-in-rest-api Change-Id: I09420ff7134874dfe4dc399931c7740e81ecc2d0
This commit is contained in:
parent
a37a035c9d
commit
1c6fdc9aec
@ -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
|
||||
================
|
||||
|
||||
|
@ -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
|
||||
==========================
|
||||
|
||||
|
@ -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``.
|
||||
|
@ -0,0 +1,11 @@
|
||||
{
|
||||
"interfaceAttachment": {
|
||||
"fixed_ips": [
|
||||
{
|
||||
"ip_address": "192.168.1.3"
|
||||
}
|
||||
],
|
||||
"net_id": "3cb9bc59-5699-4588-a4b1-b87f96708bc6",
|
||||
"tag": "public"
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
{
|
||||
"interfaceAttachment": {
|
||||
"port_id": "ce531f90-199f-48c0-816c-13e38010b442",
|
||||
"tag": "public"
|
||||
}
|
||||
}
|
@ -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"
|
||||
}
|
||||
}
|
@ -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"
|
||||
}
|
||||
]
|
||||
}
|
@ -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"
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
{
|
||||
"volumeAttachment": {
|
||||
"volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f803",
|
||||
"tag": "foo"
|
||||
}
|
||||
}
|
@ -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"
|
||||
}
|
||||
}
|
@ -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"
|
||||
}
|
||||
]
|
||||
}
|
5
doc/api_samples/os-volumes/v2.70/update-volume-req.json
Normal file
5
doc/api_samples/os-volumes/v2.70/update-volume-req.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"volumeAttachment": {
|
||||
"volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f805"
|
||||
}
|
||||
}
|
@ -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"
|
||||
}
|
||||
}
|
@ -19,7 +19,7 @@
|
||||
}
|
||||
],
|
||||
"status": "CURRENT",
|
||||
"version": "2.69",
|
||||
"version": "2.70",
|
||||
"min_version": "2.1",
|
||||
"updated": "2013-07-23T11:33:21Z"
|
||||
}
|
||||
|
@ -22,7 +22,7 @@
|
||||
}
|
||||
],
|
||||
"status": "CURRENT",
|
||||
"version": "2.69",
|
||||
"version": "2.70",
|
||||
"min_version": "2.1",
|
||||
"updated": "2013-07-23T11:33:21Z"
|
||||
}
|
||||
|
@ -170,6 +170,8 @@ REST_API_VERSION_HISTORY = """REST API Version History:
|
||||
``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 @@ REST_API_VERSION_HISTORY = """REST API Version History:
|
||||
# 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
|
||||
|
@ -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 compute
|
||||
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 @@ class InterfaceAttachmentController(wsgi.Controller):
|
||||
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 @@ class InterfaceAttachmentController(wsgi.Controller):
|
||||
"%(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')
|
||||
|
@ -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
|
||||
<https://developer.openstack.org/api-guide/compute/down_cells.html>`__ 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)
|
||||
|
@ -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 @@ class VolumeController(wsgi.Controller):
|
||||
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 @@ class VolumeAttachmentController(wsgi.Controller):
|
||||
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 @@ class VolumeAttachmentController(wsgi.Controller):
|
||||
{'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 @@ class VolumeAttachmentController(wsgi.Controller):
|
||||
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)
|
||||
|
@ -0,0 +1,11 @@
|
||||
{
|
||||
"interfaceAttachment": {
|
||||
"fixed_ips": [
|
||||
{
|
||||
"ip_address": "192.168.1.3"
|
||||
}
|
||||
],
|
||||
"net_id": "3cb9bc59-5699-4588-a4b1-b87f96708bc6",
|
||||
"tag": "%(tag)s"
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
{
|
||||
"interfaceAttachment": {
|
||||
"port_id": "%(port_id)s",
|
||||
"tag": "%(tag)s"
|
||||
}
|
||||
}
|
@ -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"
|
||||
}
|
||||
}
|
@ -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"
|
||||
}
|
||||
]
|
||||
}
|
@ -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"
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
{
|
||||
"volumeAttachment": {
|
||||
"volumeId": "%(volume_id)s",
|
||||
"tag": "%(tag)s"
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
{
|
||||
"volumeAttachment": {
|
||||
"device": "%(device)s",
|
||||
"id": "%(volume_id)s",
|
||||
"serverId": "%(uuid)s",
|
||||
"tag": "%(tag)s",
|
||||
"volumeId": "%(volume_id)s"
|
||||
}
|
||||
}
|
@ -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"
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
{
|
||||
"volumeAttachment": {
|
||||
"volumeId": "%(volume_id)s"
|
||||
}
|
||||
}
|
@ -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"
|
||||
}
|
||||
}
|
@ -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 @@ class AttachInterfacesSampleJsonTest(test_servers.ServersSampleBase):
|
||||
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 @@ class AttachInterfacesSampleJsonTest(test_servers.ServersSampleBase):
|
||||
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 @@ class AttachInterfacesSampleJsonTest(test_servers.ServersSampleBase):
|
||||
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 @@ class AttachInterfacesSampleV249JsonTest(test_servers.ServersSampleBase):
|
||||
'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
|
||||
|
@ -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 @@ class VolumeAttachmentsSample(test_servers.ServersSampleBase):
|
||||
'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 @@ class VolumeAttachmentsSample(test_servers.ServersSampleBase):
|
||||
|
||||
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 @@ class VolumeAttachmentsSample(test_servers.ServersSampleBase):
|
||||
|
||||
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 @@ class VolumeAttachmentsSample(test_servers.ServersSampleBase):
|
||||
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 @@ class VolumeAttachmentsSampleV249(VolumeAttachmentsSample):
|
||||
|
||||
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
|
||||
}
|
||||
|
@ -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)
|
Loading…
Reference in New Issue
Block a user