Browse Source

Merge "Add floating IP port forwarding related methods"

Zuul 1 week ago
parent
commit
1d410a49c8

+ 117
- 0
openstack/network/v2/_proxy.py View File

@@ -3780,3 +3780,120 @@ class Proxy(proxy.Proxy):
3780 3780
         :rtype: :class:`~openstack.network.v2.vpn_service.VPNService`
3781 3781
         """
3782 3782
         return self._update(_vpn_service.VPNService, vpn_service, **attrs)
3783
+
3784
+    def create_floating_ip_port_forwarding(self, floating_ip, **attrs):
3785
+        """Create a new floating ip port forwarding from attributes
3786
+
3787
+        :param floating_ip: The value can be either the ID of a floating ip
3788
+                or a :class:`~openstack.network.v2.floating_ip.FloatingIP`
3789
+                instance.
3790
+        :param dict attrs:Keyword arguments which will be used to create
3791
+            a:class:`~openstack.network.v2.port_forwarding.PortForwarding`,
3792
+            comprised of the properties on the PortForwarding class.
3793
+
3794
+        :returns: The results of port forwarding creation
3795
+        :rtype: :class:`~openstack.network.v2.port_forwarding.PortForwarding`
3796
+        """
3797
+        floatingip = self._get_resource(_floating_ip.FloatingIP, floating_ip)
3798
+        return self._create(_port_forwarding.PortForwarding,
3799
+                            floatingip_id=floatingip.id, **attrs)
3800
+
3801
+    def delete_floating_ip_port_forwarding(self, floating_ip, port_forwarding,
3802
+                                           ignore_missing=True):
3803
+        """Delete a floating IP port forwarding.
3804
+
3805
+        :param floating_ip: The value can be either the ID of a floating ip
3806
+                    or a :class:`~openstack.network.v2.floating_ip.FloatingIP`
3807
+                    instance.
3808
+        :param port_forwarding: The value can be either the ID of a port
3809
+                    forwarding or a :class:`~openstack.network.v2.
3810
+                    port_forwarding.PortForwarding`instance.
3811
+        :param bool ignore_missing: When set to ``False``
3812
+                    :class:`~openstack.exceptions.ResourceNotFound` will be
3813
+                    raised when the floating ip does not exist.
3814
+                    When set to ``True``, no exception will be set when
3815
+                    attempting to delete a nonexistent ip.
3816
+
3817
+        :returns: ``None``
3818
+        """
3819
+        floatingip = self._get_resource(_floating_ip.FloatingIP, floating_ip)
3820
+        self._delete(_port_forwarding.PortForwarding,
3821
+                     port_forwarding, ignore_missing=ignore_missing,
3822
+                     floatingip_id=floatingip.id)
3823
+
3824
+    def find_floating_ip_port_forwarding(self, floating_ip, port_forwarding_id,
3825
+                                         ignore_missing=True, **args):
3826
+        """Find a floating ip port forwarding
3827
+
3828
+        :param floating_ip: The value can be the ID of the Floating IP that the
3829
+                            port forwarding  belongs or a :class:`~openstack.
3830
+                            network.v2.floating_ip.FloatingIP` instance.
3831
+        :param port_forwarding_id: The ID of a port forwarding.
3832
+        :param bool ignore_missing: When set to ``False``
3833
+                    :class:`~openstack.exceptions.ResourceNotFound` will be
3834
+                    raised when the resource does not exist.
3835
+                    When set to ``True``, None will be returned when
3836
+                    attempting to find a nonexistent resource.
3837
+        :param dict args: Any additional parameters to be passed into
3838
+                    underlying methods. such as query filters.
3839
+        :returns: One :class:`~openstack.network.v2.port_forwarding.
3840
+                   PortForwarding` or None
3841
+        """
3842
+        floatingip = self._get_resource(_floating_ip.FloatingIP, floating_ip)
3843
+        return self._find(_port_forwarding.PortForwarding,
3844
+                          port_forwarding_id, ignore_missing=ignore_missing,
3845
+                          floatingip_id=floatingip.id, **args)
3846
+
3847
+    def get_floating_ip_port_forwarding(self, floating_ip, port_forwarding):
3848
+        """Get a floating ip port forwarding
3849
+
3850
+        :param floating_ip: The value can be the ID of the Floating IP that the
3851
+                            port forwarding  belongs or a :class:`~openstack.
3852
+                            network.v2.floating_ip.FloatingIP` instance.
3853
+        :param port_forwarding: The value can be the ID of a port forwarding
3854
+                           or a :class:`~openstack.network.v2.
3855
+                           port_forwarding.PortForwarding` instance.
3856
+        :returns: One :class:`~openstack.network.v2.port_forwarding.
3857
+                        PortForwarding`
3858
+        :raises: :class:`~openstack.exceptions.ResourceNotFound`
3859
+                       when no resource can be found.
3860
+        """
3861
+        floatingip = self._get_resource(_floating_ip.FloatingIP, floating_ip)
3862
+        return self._get(_port_forwarding.PortForwarding, port_forwarding,
3863
+                         floatingip_id=floatingip.id)
3864
+
3865
+    def floating_ip_port_forwardings(self, floating_ip, **query):
3866
+        """Return a generator of floating ip port forwarding
3867
+
3868
+        :param floating_ip: The value can be the ID of the Floating IP that the
3869
+                            port forwarding  belongs or a :class:`~openstack.
3870
+                            network.v2.floating_ip.FloatingIP` instance.
3871
+        :param kwargs \*\*query: Optional query parameters to be sent to limit
3872
+                                 the resources being returned.
3873
+        :returns: A generator of floating ip port forwarding objects
3874
+        :rtype: :class:`~openstack.network.v2.port_forwarding.
3875
+                        PortForwarding`
3876
+        """
3877
+        floatingip = self._get_resource(_floating_ip.FloatingIP, floating_ip)
3878
+        return self._list(_port_forwarding.PortForwarding,
3879
+                          floatingip_id=floatingip.id, **query)
3880
+
3881
+    def update_floating_ip_port_forwarding(self, floating_ip, port_forwarding,
3882
+                                           **attrs):
3883
+        """Update a floating ip port forwarding
3884
+
3885
+        :param floating_ip: The value can be the ID of the Floating IP that the
3886
+                            port forwarding  belongs or a :class:`~openstack.
3887
+                            network.v2.floating_ip.FloatingIP` instance.
3888
+        :param port_forwarding: Either the id of a floating ip port forwarding
3889
+                            or a :class:`~openstack.network.v2.
3890
+                            port_forwarding.PortForwarding`instance.
3891
+        :attrs kwargs: The attributes to update on the floating ip port
3892
+                       forwarding represented by ``value``.
3893
+
3894
+        :returns: The updated floating ip port forwarding
3895
+        :rtype: :class:`~openstack.network.v2.port_forwarding.PortForwarding`
3896
+        """
3897
+        floatingip = self._get_resource(_floating_ip.FloatingIP, floating_ip)
3898
+        return self._update(_port_forwarding.PortForwarding, port_forwarding,
3899
+                            floatingip_id=floatingip.id, **attrs)

+ 61
- 0
openstack/tests/unit/network/v2/test_proxy.py View File

@@ -36,6 +36,7 @@ from openstack.network.v2 import network_segment_range
36 36
 from openstack.network.v2 import pool
37 37
 from openstack.network.v2 import pool_member
38 38
 from openstack.network.v2 import port
39
+from openstack.network.v2 import port_forwarding
39 40
 from openstack.network.v2 import qos_bandwidth_limit_rule
40 41
 from openstack.network.v2 import qos_dscp_marking_rule
41 42
 from openstack.network.v2 import qos_minimum_bandwidth_rule
@@ -61,6 +62,7 @@ QOS_RULE_ID = 'qos-rule-id-' + uuid.uuid4().hex
61 62
 NETWORK_ID = 'network-id-' + uuid.uuid4().hex
62 63
 AGENT_ID = 'agent-id-' + uuid.uuid4().hex
63 64
 ROUTER_ID = 'router-id-' + uuid.uuid4().hex
65
+FIP_ID = 'fip-id-' + uuid.uuid4().hex
64 66
 
65 67
 
66 68
 class TestNetworkProxy(test_proxy_base.TestProxyBase):
@@ -1156,3 +1158,62 @@ class TestNetworkProxy(test_proxy_base.TestProxyBase):
1156 1158
                           self.proxy.set_tags,
1157 1159
                           no_tag_resource, ['TAG1', 'TAG2'])
1158 1160
         self.assertEqual(0, mock_set_tags.call_count)
1161
+
1162
+    def test_create_floating_ip_port_forwarding(self):
1163
+        self.verify_create(self.proxy.create_floating_ip_port_forwarding,
1164
+                           port_forwarding.PortForwarding,
1165
+                           method_kwargs={'floating_ip': FIP_ID},
1166
+                           expected_kwargs={'floatingip_id': FIP_ID})
1167
+
1168
+    def test_delete_floating_ip_port_forwarding(self):
1169
+        self.verify_delete(
1170
+            self.proxy.delete_floating_ip_port_forwarding,
1171
+            port_forwarding.PortForwarding,
1172
+            False, input_path_args=[FIP_ID, "resource_or_id"],
1173
+            expected_path_args={'floatingip_id': FIP_ID},)
1174
+
1175
+    def test_delete_floating_ip_port_forwarding_ignore(self):
1176
+        self.verify_delete(
1177
+            self.proxy.delete_floating_ip_port_forwarding,
1178
+            port_forwarding.PortForwarding,
1179
+            True, input_path_args=[FIP_ID, "resource_or_id"],
1180
+            expected_path_args={'floatingip_id': FIP_ID}, )
1181
+
1182
+    def test_find_floating_ip_port_forwarding(self):
1183
+        fip = floating_ip.FloatingIP.new(id=FIP_ID)
1184
+        self._verify2('openstack.proxy.Proxy._find',
1185
+                      self.proxy.find_floating_ip_port_forwarding,
1186
+                      method_args=[fip, 'port_forwarding_id'],
1187
+                      expected_args=[
1188
+                          port_forwarding.PortForwarding,
1189
+                          'port_forwarding_id'],
1190
+                      expected_kwargs={'ignore_missing': True,
1191
+                                       'floatingip_id': FIP_ID})
1192
+
1193
+    def test_get_floating_ip_port_forwarding(self):
1194
+        fip = floating_ip.FloatingIP.new(id=FIP_ID)
1195
+        self._verify2('openstack.proxy.Proxy._get',
1196
+                      self.proxy.get_floating_ip_port_forwarding,
1197
+                      method_args=[fip, 'port_forwarding_id'],
1198
+                      expected_args=[
1199
+                          port_forwarding.PortForwarding,
1200
+                          'port_forwarding_id'],
1201
+                      expected_kwargs={'floatingip_id': FIP_ID})
1202
+
1203
+    def test_floating_ip_port_forwardings(self):
1204
+        self.verify_list(self.proxy.floating_ip_port_forwardings,
1205
+                         port_forwarding.PortForwarding,
1206
+                         method_kwargs={'floating_ip': FIP_ID},
1207
+                         expected_kwargs={'floatingip_id': FIP_ID})
1208
+
1209
+    def test_update_floating_ip_port_forwarding(self):
1210
+        fip = floating_ip.FloatingIP.new(id=FIP_ID)
1211
+        self._verify2('openstack.proxy.Proxy._update',
1212
+                      self.proxy.update_floating_ip_port_forwarding,
1213
+                      method_args=[fip, 'port_forwarding_id'],
1214
+                      method_kwargs={'foo': 'bar'},
1215
+                      expected_args=[
1216
+                          port_forwarding.PortForwarding,
1217
+                          'port_forwarding_id'],
1218
+                      expected_kwargs={'floatingip_id': FIP_ID,
1219
+                                       'foo': 'bar'})

+ 4
- 0
releasenotes/notes/add-fip-portforwarding-methods-cffc14a6283cedfb.yaml View File

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

Loading…
Cancel
Save