Skip to content

Commit

Permalink
Add microversion to expose virtual device tags
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mriedem committed Feb 21, 2019
1 parent a37a035 commit 1c6fdc9
Show file tree
Hide file tree
Showing 32 changed files with 459 additions and 59 deletions.
18 changes: 18 additions & 0 deletions api-ref/source/os-interface.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
================

Expand Down Expand Up @@ -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
===========================

Expand Down Expand Up @@ -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
================

Expand Down
18 changes: 18 additions & 0 deletions api-ref/source/os-volume-attachments.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
==============================

Expand Down Expand Up @@ -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
====================================

Expand Down Expand Up @@ -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
==========================

Expand Down
14 changes: 14 additions & 0 deletions api-ref/source/parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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``.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"interfaceAttachment": {
"fixed_ips": [
{
"ip_address": "192.168.1.3"
}
],
"net_id": "3cb9bc59-5699-4588-a4b1-b87f96708bc6",
"tag": "public"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"interfaceAttachment": {
"port_id": "ce531f90-199f-48c0-816c-13e38010b442",
"tag": "public"
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"volumeAttachment": {
"volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f803",
"tag": "foo"
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
18 changes: 18 additions & 0 deletions doc/api_samples/os-volumes/v2.70/list-volume-attachments-resp.json
Original file line number Diff line number Diff line change
@@ -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 changes: 5 additions & 0 deletions doc/api_samples/os-volumes/v2.70/update-volume-req.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"volumeAttachment": {
"volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f805"
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
2 changes: 1 addition & 1 deletion doc/api_samples/versions/v21-version-get-resp.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
}
],
"status": "CURRENT",
"version": "2.69",
"version": "2.70",
"min_version": "2.1",
"updated": "2013-07-23T11:33:21Z"
}
Expand Down
2 changes: 1 addition & 1 deletion doc/api_samples/versions/versions-get-resp.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
}
],
"status": "CURRENT",
"version": "2.69",
"version": "2.70",
"min_version": "2.1",
"updated": "2013-07-23T11:33:21Z"
}
Expand Down
4 changes: 3 additions & 1 deletion nova/api/openstack/api_version_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
50 changes: 43 additions & 7 deletions nova/api/openstack/compute/attach_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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}

Expand Down Expand Up @@ -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')
Expand Down
Loading

0 comments on commit 1c6fdc9

Please sign in to comment.