Add floating IP port forwarding related methods

Closes-Bug: #1811352
Change-Id: Id78c91b0a66c8c04ab783fe4ba666a18844aed59
This commit is contained in:
LIU Yulong 2018-08-28 10:36:26 +08:00
parent c7e3f3e7c6
commit 8bbd44c9b5
3 changed files with 182 additions and 0 deletions

View File

@ -3780,3 +3780,120 @@ class Proxy(proxy.Proxy):
:rtype: :class:`~openstack.network.v2.vpn_service.VPNService` :rtype: :class:`~openstack.network.v2.vpn_service.VPNService`
""" """
return self._update(_vpn_service.VPNService, vpn_service, **attrs) return self._update(_vpn_service.VPNService, vpn_service, **attrs)
def create_floating_ip_port_forwarding(self, floating_ip, **attrs):
"""Create a new floating ip port forwarding from attributes
:param floating_ip: The value can be either the ID of a floating ip
or a :class:`~openstack.network.v2.floating_ip.FloatingIP`
instance.
:param dict attrs:Keyword arguments which will be used to create
a:class:`~openstack.network.v2.port_forwarding.PortForwarding`,
comprised of the properties on the PortForwarding class.
:returns: The results of port forwarding creation
:rtype: :class:`~openstack.network.v2.port_forwarding.PortForwarding`
"""
floatingip = self._get_resource(_floating_ip.FloatingIP, floating_ip)
return self._create(_port_forwarding.PortForwarding,
floatingip_id=floatingip.id, **attrs)
def delete_floating_ip_port_forwarding(self, floating_ip, port_forwarding,
ignore_missing=True):
"""Delete a floating IP port forwarding.
:param floating_ip: The value can be either the ID of a floating ip
or a :class:`~openstack.network.v2.floating_ip.FloatingIP`
instance.
:param port_forwarding: The value can be either the ID of a port
forwarding or a :class:`~openstack.network.v2.
port_forwarding.PortForwarding`instance.
:param bool ignore_missing: When set to ``False``
:class:`~openstack.exceptions.ResourceNotFound` will be
raised when the floating ip does not exist.
When set to ``True``, no exception will be set when
attempting to delete a nonexistent ip.
:returns: ``None``
"""
floatingip = self._get_resource(_floating_ip.FloatingIP, floating_ip)
self._delete(_port_forwarding.PortForwarding,
port_forwarding, ignore_missing=ignore_missing,
floatingip_id=floatingip.id)
def find_floating_ip_port_forwarding(self, floating_ip, port_forwarding_id,
ignore_missing=True, **args):
"""Find a floating ip port forwarding
:param floating_ip: The value can be the ID of the Floating IP that the
port forwarding belongs or a :class:`~openstack.
network.v2.floating_ip.FloatingIP` instance.
:param port_forwarding_id: The ID of a port forwarding.
:param bool ignore_missing: When set to ``False``
:class:`~openstack.exceptions.ResourceNotFound` will be
raised when the resource does not exist.
When set to ``True``, None will be returned when
attempting to find a nonexistent resource.
:param dict args: Any additional parameters to be passed into
underlying methods. such as query filters.
:returns: One :class:`~openstack.network.v2.port_forwarding.
PortForwarding` or None
"""
floatingip = self._get_resource(_floating_ip.FloatingIP, floating_ip)
return self._find(_port_forwarding.PortForwarding,
port_forwarding_id, ignore_missing=ignore_missing,
floatingip_id=floatingip.id, **args)
def get_floating_ip_port_forwarding(self, floating_ip, port_forwarding):
"""Get a floating ip port forwarding
:param floating_ip: The value can be the ID of the Floating IP that the
port forwarding belongs or a :class:`~openstack.
network.v2.floating_ip.FloatingIP` instance.
:param port_forwarding: The value can be the ID of a port forwarding
or a :class:`~openstack.network.v2.
port_forwarding.PortForwarding` instance.
:returns: One :class:`~openstack.network.v2.port_forwarding.
PortForwarding`
:raises: :class:`~openstack.exceptions.ResourceNotFound`
when no resource can be found.
"""
floatingip = self._get_resource(_floating_ip.FloatingIP, floating_ip)
return self._get(_port_forwarding.PortForwarding, port_forwarding,
floatingip_id=floatingip.id)
def floating_ip_port_forwardings(self, floating_ip, **query):
"""Return a generator of floating ip port forwarding
:param floating_ip: The value can be the ID of the Floating IP that the
port forwarding belongs or a :class:`~openstack.
network.v2.floating_ip.FloatingIP` instance.
:param kwargs \*\*query: Optional query parameters to be sent to limit
the resources being returned.
:returns: A generator of floating ip port forwarding objects
:rtype: :class:`~openstack.network.v2.port_forwarding.
PortForwarding`
"""
floatingip = self._get_resource(_floating_ip.FloatingIP, floating_ip)
return self._list(_port_forwarding.PortForwarding,
floatingip_id=floatingip.id, **query)
def update_floating_ip_port_forwarding(self, floating_ip, port_forwarding,
**attrs):
"""Update a floating ip port forwarding
:param floating_ip: The value can be the ID of the Floating IP that the
port forwarding belongs or a :class:`~openstack.
network.v2.floating_ip.FloatingIP` instance.
:param port_forwarding: Either the id of a floating ip port forwarding
or a :class:`~openstack.network.v2.
port_forwarding.PortForwarding`instance.
:attrs kwargs: The attributes to update on the floating ip port
forwarding represented by ``value``.
:returns: The updated floating ip port forwarding
:rtype: :class:`~openstack.network.v2.port_forwarding.PortForwarding`
"""
floatingip = self._get_resource(_floating_ip.FloatingIP, floating_ip)
return self._update(_port_forwarding.PortForwarding, port_forwarding,
floatingip_id=floatingip.id, **attrs)

View File

@ -36,6 +36,7 @@ from openstack.network.v2 import network_segment_range
from openstack.network.v2 import pool from openstack.network.v2 import pool
from openstack.network.v2 import pool_member from openstack.network.v2 import pool_member
from openstack.network.v2 import port from openstack.network.v2 import port
from openstack.network.v2 import port_forwarding
from openstack.network.v2 import qos_bandwidth_limit_rule from openstack.network.v2 import qos_bandwidth_limit_rule
from openstack.network.v2 import qos_dscp_marking_rule from openstack.network.v2 import qos_dscp_marking_rule
from openstack.network.v2 import qos_minimum_bandwidth_rule from openstack.network.v2 import qos_minimum_bandwidth_rule
@ -61,6 +62,7 @@ QOS_RULE_ID = 'qos-rule-id-' + uuid.uuid4().hex
NETWORK_ID = 'network-id-' + uuid.uuid4().hex NETWORK_ID = 'network-id-' + uuid.uuid4().hex
AGENT_ID = 'agent-id-' + uuid.uuid4().hex AGENT_ID = 'agent-id-' + uuid.uuid4().hex
ROUTER_ID = 'router-id-' + uuid.uuid4().hex ROUTER_ID = 'router-id-' + uuid.uuid4().hex
FIP_ID = 'fip-id-' + uuid.uuid4().hex
class TestNetworkProxy(test_proxy_base.TestProxyBase): class TestNetworkProxy(test_proxy_base.TestProxyBase):
@ -1156,3 +1158,62 @@ class TestNetworkProxy(test_proxy_base.TestProxyBase):
self.proxy.set_tags, self.proxy.set_tags,
no_tag_resource, ['TAG1', 'TAG2']) no_tag_resource, ['TAG1', 'TAG2'])
self.assertEqual(0, mock_set_tags.call_count) self.assertEqual(0, mock_set_tags.call_count)
def test_create_floating_ip_port_forwarding(self):
self.verify_create(self.proxy.create_floating_ip_port_forwarding,
port_forwarding.PortForwarding,
method_kwargs={'floating_ip': FIP_ID},
expected_kwargs={'floatingip_id': FIP_ID})
def test_delete_floating_ip_port_forwarding(self):
self.verify_delete(
self.proxy.delete_floating_ip_port_forwarding,
port_forwarding.PortForwarding,
False, input_path_args=[FIP_ID, "resource_or_id"],
expected_path_args={'floatingip_id': FIP_ID},)
def test_delete_floating_ip_port_forwarding_ignore(self):
self.verify_delete(
self.proxy.delete_floating_ip_port_forwarding,
port_forwarding.PortForwarding,
True, input_path_args=[FIP_ID, "resource_or_id"],
expected_path_args={'floatingip_id': FIP_ID}, )
def test_find_floating_ip_port_forwarding(self):
fip = floating_ip.FloatingIP.new(id=FIP_ID)
self._verify2('openstack.proxy.Proxy._find',
self.proxy.find_floating_ip_port_forwarding,
method_args=[fip, 'port_forwarding_id'],
expected_args=[
port_forwarding.PortForwarding,
'port_forwarding_id'],
expected_kwargs={'ignore_missing': True,
'floatingip_id': FIP_ID})
def test_get_floating_ip_port_forwarding(self):
fip = floating_ip.FloatingIP.new(id=FIP_ID)
self._verify2('openstack.proxy.Proxy._get',
self.proxy.get_floating_ip_port_forwarding,
method_args=[fip, 'port_forwarding_id'],
expected_args=[
port_forwarding.PortForwarding,
'port_forwarding_id'],
expected_kwargs={'floatingip_id': FIP_ID})
def test_floating_ip_port_forwardings(self):
self.verify_list(self.proxy.floating_ip_port_forwardings,
port_forwarding.PortForwarding,
method_kwargs={'floating_ip': FIP_ID},
expected_kwargs={'floatingip_id': FIP_ID})
def test_update_floating_ip_port_forwarding(self):
fip = floating_ip.FloatingIP.new(id=FIP_ID)
self._verify2('openstack.proxy.Proxy._update',
self.proxy.update_floating_ip_port_forwarding,
method_args=[fip, 'port_forwarding_id'],
method_kwargs={'foo': 'bar'},
expected_args=[
port_forwarding.PortForwarding,
'port_forwarding_id'],
expected_kwargs={'floatingip_id': FIP_ID,
'foo': 'bar'})

View File

@ -0,0 +1,4 @@
---
features:
- |
Add floating IP Port Forwarding related methods.