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
This commit is contained in:
ZhaoBo 2018-06-28 18:41:00 +08:00
parent 8cbab5756c
commit e863e8f1cd
12 changed files with 138 additions and 6 deletions

View File

@ -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
----------------

View File

@ -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.

View File

@ -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
}
]
}
]
}

View File

@ -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": []
}
}

View File

@ -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": []
}
}

View File

@ -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": []
}
}

View File

@ -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": []
}
}

View File

@ -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,

View File

@ -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',

View File

@ -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 = {}

View File

@ -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,)

View File

@ -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.