From e863e8f1cd25a786fe416e94185f250eb1191d2f Mon Sep 17 00:00:00 2001 From: ZhaoBo Date: Thu, 28 Jun 2018 18:41:00 +0800 Subject: [PATCH] Extend port_forwardings field in Floatingip response This patch introduces a new API extension for exposing port_forwardings field in Floatingip response. This extension requires the router and port_forwarding service plugins. This change implements the effect of port forwarding on the existing Floatingip API, as specified in [1] [1] https://specs.openstack.org/openstack/neutron-specs/rocky/port-forwarding.html Change-Id: Ia35b57fb26a0cf277f31816e90d24f91ca1f63d1 Partial-Bug: #1491317 --- api-ref/source/v2/floatingips.inc | 11 +++++ api-ref/source/v2/parameters.yaml | 12 ++++++ .../floating-ips-list-response.json | 38 +++++++++++++++++- .../floatingip-create-response.json | 3 +- .../floatingip-disassociate-response.json | 3 +- .../floatingips/floatingip-show-response.json | 4 +- .../floatingip-update-response.json | 3 +- neutron_lib/api/definitions/__init__.py | 2 + neutron_lib/api/definitions/base.py | 1 + .../expose_port_forwarding_in_fip.py | 40 +++++++++++++++++++ .../test_expose_port_forwarding_in_fip.py | 21 ++++++++++ ...rt-forwarding-in-fip-a7880506cea0ad1d.yaml | 6 +++ 12 files changed, 138 insertions(+), 6 deletions(-) create mode 100644 neutron_lib/api/definitions/expose_port_forwarding_in_fip.py create mode 100644 neutron_lib/tests/unit/api/definitions/test_expose_port_forwarding_in_fip.py create mode 100644 releasenotes/notes/expose-port-forwarding-in-fip-a7880506cea0ad1d.yaml diff --git a/api-ref/source/v2/floatingips.inc b/api-ref/source/v2/floatingips.inc index fc9f15655..a54c750ae 100644 --- a/api-ref/source/v2/floatingips.inc +++ b/api-ref/source/v2/floatingips.inc @@ -17,6 +17,13 @@ The ``fip-port-details`` extension adds the ``port_details`` attribute to floating IPs. The value of this attribute contains information of the associated port. +Floating IP port forwardings +============================ + +The ``expose-port-forwarding-in-fip`` extension adds the ``port_forwardings`` +attribute to floating IPs. The value of this attribute contains the +information of associated port forwarding resources. + Resource timestamps =================== @@ -104,6 +111,7 @@ Response Parameters - floating_ip_address: floating_ip_address - port_id: floatingip-port_id - tags: tags + - port_forwardings: floatingip-port_forwardings Response Example ---------------- @@ -216,6 +224,7 @@ Response Parameters - port_id: floatingip-port_id - id: floatingip-id - tags: tags + - port_forwardings: floatingip-port_forwardings Response Example ---------------- @@ -281,6 +290,7 @@ Response Parameters - port_id: floatingip-port_id - id: floatingip-id - tags: tags + - port_forwardings: floatingip-port_forwardings Response Example ---------------- @@ -360,6 +370,7 @@ Response Parameters - dns_name: dns_name - port_details: floating_port_details - tags: tags + - port_forwardings: floatingip-port_forwardings Response Example ---------------- diff --git a/api-ref/source/v2/parameters.yaml b/api-ref/source/v2/parameters.yaml index a58783e62..de985e183 100644 --- a/api-ref/source/v2/parameters.yaml +++ b/api-ref/source/v2/parameters.yaml @@ -2992,6 +2992,18 @@ floatingip-id: in: body required: true type: string +floatingip-port_forwardings: + description: | + The associated port forwarding resources for the floating IP. If the + floating IP has multiple port forwarding resources, this field has + multiple entries. Each entry consists of network IP protocol + (``protocol``), the fixed IP address of internal neutron port + (``internal_ip_address``), the TCP or UDP port used by internal + neutron port (``internal_port``) and the TCP or UDP port used by + floating IP (``external_port``). + in: body + required: true + type: array floatingip-port_id: description: | The ID of a port associated with the floating IP. diff --git a/api-ref/source/v2/samples/floatingips/floating-ips-list-response.json b/api-ref/source/v2/samples/floatingips/floating-ips-list-response.json index 1d93292a1..9aed05464 100644 --- a/api-ref/source/v2/samples/floatingips/floating-ips-list-response.json +++ b/api-ref/source/v2/samples/floatingips/floating-ips-list-response.json @@ -25,7 +25,8 @@ "mac_address": "fa:16:3e:b1:3b:30", "device_id": "8e3941b4-a6e9-499f-a1ac-2a4662025cba" }, - "tags": ["tag1,tag2"] + "tags": ["tag1,tag2"], + "port_forwardings": [] }, { "router_id": null, @@ -44,7 +45,40 @@ "id": "61cea855-49cb-4846-997d-801b70c71bdd", "status": "DOWN", "port_details": null, - "tags": ["tag1,tag2"] + "tags": ["tag1,tag2"], + "port_forwardings": [] + }, + { + "router_id": "0303bf18-2c52-479c-bd68-e0ad712a1639", + "description": "for test with port forwarding", + "dns_domain": "my-domain.org.", + "dns_name": "myfip3", + "created_at": "2018-06-15T02:12:48Z", + "updated_at": "2018-06-15T02:12:57Z", + "revision_number": 1, + "project_id": "4969c491a3c74ee4af974e6d800c62de", + "tenant_id": "4969c491a3c74ee4af974e6d800c62de", + "floating_network_id": "376da547-b977-4cfe-9cba-275c80debf57", + "fixed_ip_address": null, + "floating_ip_address": "172.24.4.42", + "port_id": null, + "id": "898b198e-49f7-47d6-a7e1-53f626a548e6", + "status": "ACTIVE", + "tags": [], + "port_forwardings": [ + { + "protocol": "tcp", + "internal_ip_address": "10.0.0.19", + "internal_port": 25, + "external_port": 2225 + }, + { + "protocol": "tcp", + "internal_ip_address": "10.0.0.18", + "internal_port": 16666, + "external_port": 8786 + } + ] } ] } diff --git a/api-ref/source/v2/samples/floatingips/floatingip-create-response.json b/api-ref/source/v2/samples/floatingips/floatingip-create-response.json index b4a676800..6282b43cb 100644 --- a/api-ref/source/v2/samples/floatingips/floatingip-create-response.json +++ b/api-ref/source/v2/samples/floatingips/floatingip-create-response.json @@ -24,6 +24,7 @@ "mac_address": "fa:16:3e:b1:3b:30", "device_id": "8e3941b4-a6e9-499f-a1ac-2a4662025cba" }, - "tags": ["tag1,tag2"] + "tags": ["tag1,tag2"], + "port_forwardings": [] } } diff --git a/api-ref/source/v2/samples/floatingips/floatingip-disassociate-response.json b/api-ref/source/v2/samples/floatingips/floatingip-disassociate-response.json index bf1674f71..11a04133c 100644 --- a/api-ref/source/v2/samples/floatingips/floatingip-disassociate-response.json +++ b/api-ref/source/v2/samples/floatingips/floatingip-disassociate-response.json @@ -14,6 +14,7 @@ "updated_at": "2016-12-22T03:13:49Z", "revision_number": 3, "port_details": null, - "tags": ["tag1,tag2"] + "tags": ["tag1,tag2"], + "port_forwardings": [] } } diff --git a/api-ref/source/v2/samples/floatingips/floatingip-show-response.json b/api-ref/source/v2/samples/floatingips/floatingip-show-response.json index 68f5c087f..699fe24f9 100644 --- a/api-ref/source/v2/samples/floatingips/floatingip-show-response.json +++ b/api-ref/source/v2/samples/floatingips/floatingip-show-response.json @@ -24,6 +24,8 @@ "mac_address": "fa:16:3e:b1:3b:30", "device_id": "8e3941b4-a6e9-499f-a1ac-2a4662025cba" }, - "tags": ["tag1,tag2"] + "tags": ["tag1,tag2"], + "port_forwardings": [] + } } diff --git a/api-ref/source/v2/samples/floatingips/floatingip-update-response.json b/api-ref/source/v2/samples/floatingips/floatingip-update-response.json index eb62fbfaf..c1563229a 100644 --- a/api-ref/source/v2/samples/floatingips/floatingip-update-response.json +++ b/api-ref/source/v2/samples/floatingips/floatingip-update-response.json @@ -24,6 +24,7 @@ "device_owner": "compute:nova", "mac_address": "fa:16:3e:b1:3b:30", "device_id": "8e3941b4-a6e9-499f-a1ac-2a4662025cba" - } + }, + "port_forwardings": [] } } diff --git a/neutron_lib/api/definitions/__init__.py b/neutron_lib/api/definitions/__init__.py index 4081b04a1..3a7d6539a 100644 --- a/neutron_lib/api/definitions/__init__.py +++ b/neutron_lib/api/definitions/__init__.py @@ -30,6 +30,7 @@ from neutron_lib.api.definitions import dns from neutron_lib.api.definitions import dns_domain_ports from neutron_lib.api.definitions import dvr from neutron_lib.api.definitions import empty_string_filtering +from neutron_lib.api.definitions import expose_port_forwarding_in_fip from neutron_lib.api.definitions import external_net from neutron_lib.api.definitions import extra_dhcp_opt from neutron_lib.api.definitions import extraroute @@ -115,6 +116,7 @@ _ALL_API_DEFINITIONS = { dns_domain_ports, dvr, empty_string_filtering, + expose_port_forwarding_in_fip, external_net, extra_dhcp_opt, extraroute, diff --git a/neutron_lib/api/definitions/base.py b/neutron_lib/api/definitions/base.py index 4490425c3..52f4890b2 100644 --- a/neutron_lib/api/definitions/base.py +++ b/neutron_lib/api/definitions/base.py @@ -87,6 +87,7 @@ KNOWN_EXTENSIONS = ( 'dns-integration', 'dvr', 'empty-string-filtering', + 'expose-port-forwarding-in-fip', 'ext-gw-mode', 'external-net', 'extra_dhcp_opt', diff --git a/neutron_lib/api/definitions/expose_port_forwarding_in_fip.py b/neutron_lib/api/definitions/expose_port_forwarding_in_fip.py new file mode 100644 index 000000000..8b63f64a0 --- /dev/null +++ b/neutron_lib/api/definitions/expose_port_forwarding_in_fip.py @@ -0,0 +1,40 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from neutron_lib.api.definitions import floating_ip_port_forwarding +from neutron_lib.api.definitions import l3 + + +ALIAS = "expose-port-forwarding-in-fip" +IS_SHIM_EXTENSION = False +IS_STANDARD_ATTR_EXTENSION = False +NAME = 'Expose Floating IP port forwardings' +API_PREFIX = '' +DESCRIPTION = 'Expose port forwarding fields in floating IP response' +UPDATED_TIMESTAMP = '2018-06-28T16:00:00-00:00' +RESOURCE_NAME = l3.FLOATINGIP +COLLECTION_NAME = l3.FLOATINGIPS +RESOURCE_ATTRIBUTE_MAP = { + COLLECTION_NAME: { + floating_ip_port_forwarding.COLLECTION_NAME: { + 'allow_post': False, + 'allow_put': False, + 'is_visible': True, + 'default': None + } + } +} +SUB_RESOURCE_ATTRIBUTE_MAP = {} +ACTION_MAP = {} +REQUIRED_EXTENSIONS = [l3.ALIAS, floating_ip_port_forwarding.ALIAS] +OPTIONAL_EXTENSIONS = [] +ACTION_STATUS = {} diff --git a/neutron_lib/tests/unit/api/definitions/test_expose_port_forwarding_in_fip.py b/neutron_lib/tests/unit/api/definitions/test_expose_port_forwarding_in_fip.py new file mode 100644 index 000000000..3e1712f6d --- /dev/null +++ b/neutron_lib/tests/unit/api/definitions/test_expose_port_forwarding_in_fip.py @@ -0,0 +1,21 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from neutron_lib.api.definitions import expose_port_forwarding_in_fip +from neutron_lib.api.definitions import floating_ip_port_forwarding +from neutron_lib.tests.unit.api.definitions import base + + +class ExposePortForwardingInFip(base.DefinitionBaseTestCase): + extension_module = expose_port_forwarding_in_fip + extension_resources = (expose_port_forwarding_in_fip.COLLECTION_NAME,) + extension_attributes = (floating_ip_port_forwarding.COLLECTION_NAME,) diff --git a/releasenotes/notes/expose-port-forwarding-in-fip-a7880506cea0ad1d.yaml b/releasenotes/notes/expose-port-forwarding-in-fip-a7880506cea0ad1d.yaml new file mode 100644 index 000000000..8f876de61 --- /dev/null +++ b/releasenotes/notes/expose-port-forwarding-in-fip-a7880506cea0ad1d.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + Introduced ``expose-port-forwarding-in-fip`` API extension for exposing + ``port_forwardings`` field in ``FloatingIP`` API response. This extension + requires the ``router`` and ``port_forwarding`` service plugins.