From 539bae9d3ea5f7a6fb56bc80572f9efd47ed787d Mon Sep 17 00:00:00 2001 From: "T. Schreiber" Date: Tue, 12 Nov 2019 10:05:37 +0000 Subject: [PATCH 01/12] initial nat gateway branche --- otcextensions/sdk/__init__.py | 4 ++ otcextensions/sdk/nat/__init__.py | 0 otcextensions/sdk/nat/nat_service.py | 22 ++++++++++ otcextensions/sdk/nat/v2/__init__.py | 0 otcextensions/sdk/nat/v2/_proxy.py | 36 +++++++++++++++++ otcextensions/sdk/nat/v2/nat_gateway.py | 54 +++++++++++++++++++++++++ 6 files changed, 116 insertions(+) create mode 100644 otcextensions/sdk/nat/__init__.py create mode 100644 otcextensions/sdk/nat/nat_service.py create mode 100644 otcextensions/sdk/nat/v2/__init__.py create mode 100644 otcextensions/sdk/nat/v2/_proxy.py create mode 100644 otcextensions/sdk/nat/v2/nat_gateway.py diff --git a/otcextensions/sdk/__init__.py b/otcextensions/sdk/__init__.py index f9c76b8e2..c153dac6c 100644 --- a/otcextensions/sdk/__init__.py +++ b/otcextensions/sdk/__init__.py @@ -82,6 +82,10 @@ 'service_type': 'kms', 'append_project_id': True, }, + 'nat': { + 'service_type': 'nat', + 'append_project_id': True, + }, 'obs': { 'service_type': 'obs', 'require_ak': True, diff --git a/otcextensions/sdk/nat/__init__.py b/otcextensions/sdk/nat/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/otcextensions/sdk/nat/nat_service.py b/otcextensions/sdk/nat/nat_service.py new file mode 100644 index 000000000..d5fbc32f1 --- /dev/null +++ b/otcextensions/sdk/nat/nat_service.py @@ -0,0 +1,22 @@ +# 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 openstack import service_description + +from otcextensions.sdk.nat.v2 import _proxy + + +class NatService(service_description.ServiceDescription): + """The NAT service.""" + + supported_versions = { + '2': _proxy.Proxy + } diff --git a/otcextensions/sdk/nat/v2/__init__.py b/otcextensions/sdk/nat/v2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/otcextensions/sdk/nat/v2/_proxy.py b/otcextensions/sdk/nat/v2/_proxy.py new file mode 100644 index 000000000..f7ace7ca1 --- /dev/null +++ b/otcextensions/sdk/nat/v2/_proxy.py @@ -0,0 +1,36 @@ +# 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 otcextensions.sdk.nat.v2 import nat_gateway as _nat_gateway + +from openstack import proxy + + +class Proxy(proxy.Proxy): + + def gateways(self, **attrs): + return self._list(_nat_gateway.NatGateway, **attrs) + + def create_gateway(self, **attrs): + """Create a new gateway from attributes + + :param dict attrs: Keyword arguments which will be used to create + a :class:`~otcextensions.sdk.nat.v2.nat_gateway.NatGateway + """ + return self._create(_nat_gateway.NatGateway, **attrs) + + def delete_gateway(self, id): + """Create a new gateway from attributes + + :param dict attrs: Keyword arguments which will be used to create + a :class:`~otcextensions.sdk.nat.v2.nat_gateway.NatGateway + """ + return self._delete(_nat_gateway.NatGateway, id=id) diff --git a/otcextensions/sdk/nat/v2/nat_gateway.py b/otcextensions/sdk/nat/v2/nat_gateway.py new file mode 100644 index 000000000..d87da1924 --- /dev/null +++ b/otcextensions/sdk/nat/v2/nat_gateway.py @@ -0,0 +1,54 @@ +# 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 openstack import resource + +class NatGateway(resource.Resource): + resources_key = 'nat_gateways' + base_path = '/nat_gateways' + + # capabilities + allow_create = True + allow_delete = True + allow_list = True + #allow_get = True + + # Properties + #: Specifies the ID of the NAT gateway. + id = resource.Body('id') + #: Specifies the project ID + tenant_id = resource.Body('tenant_id') + #: Specifies the name of the NAT gateway. + #: Contains only digits, letters, underscores and hyphens + name = resource.Body('name') + #: Provides description of NAT Gateway + description = resource.Body('description') + #: Specifies the type of the NAT gateway. + #: *1:* small type, supports up to 10,000 SNAT connections + #: *2:* medium type, supports up to 50,000 SNAT connections + #: *3:* large type, supports up to 200,000 SNAT connections + #: *4:* extra-large type, supports up to 1,000,000 SNAT connections + spec = resource.Body('spec', type=int) + #: Specifies the router ID + router_id = resource.Body('router_id') + #: Specifies the network ID of the downstream interface + internal_network_id = resource.Body('internal_network_id') + #: Specifies the status + status = resource.Body('status') + #: Specifies whether GW is up or down + #: *true:* Gw is up + #: *false:* GW is down + admin_state_up = resource.Body('admin_state_up', type=bool) + #: Specifies when GW was is created + #: format is *yyyy-mm-dd hh:mm:ss* + created_at = resource.Body('created_at') + + From adf6243b4fdb264af5f6782c3f53d420f3d5f22c Mon Sep 17 00:00:00 2001 From: "T. Schreiber" Date: Tue, 12 Nov 2019 14:03:38 +0000 Subject: [PATCH 02/12] added snat and dnat resource --- otcextensions/sdk/nat/v2/_proxy.py | 44 ++++++++++++++++--- otcextensions/sdk/nat/v2/dnat.py | 57 +++++++++++++++++++++++++ otcextensions/sdk/nat/v2/nat_gateway.py | 5 ++- otcextensions/sdk/nat/v2/snat.py | 54 +++++++++++++++++++++++ 4 files changed, 153 insertions(+), 7 deletions(-) create mode 100644 otcextensions/sdk/nat/v2/dnat.py create mode 100644 otcextensions/sdk/nat/v2/snat.py diff --git a/otcextensions/sdk/nat/v2/_proxy.py b/otcextensions/sdk/nat/v2/_proxy.py index f7ace7ca1..36cd1f64e 100644 --- a/otcextensions/sdk/nat/v2/_proxy.py +++ b/otcextensions/sdk/nat/v2/_proxy.py @@ -13,17 +13,15 @@ from openstack import proxy - class Proxy(proxy.Proxy): - def gateways(self, **attrs): - return self._list(_nat_gateway.NatGateway, **attrs) +# NAT Gateway def create_gateway(self, **attrs): """Create a new gateway from attributes :param dict attrs: Keyword arguments which will be used to create - a :class:`~otcextensions.sdk.nat.v2.nat_gateway.NatGateway + a :class:`~otcextensions.sdk.nat.v2.nat_gateway.NatGateway` """ return self._create(_nat_gateway.NatGateway, **attrs) @@ -31,6 +29,42 @@ def delete_gateway(self, id): """Create a new gateway from attributes :param dict attrs: Keyword arguments which will be used to create - a :class:`~otcextensions.sdk.nat.v2.nat_gateway.NatGateway + a :class:`~otcextensions.sdk.nat.v2.nat_gateway.NatGateway` """ return self._delete(_nat_gateway.NatGateway, id=id) + + def gateways(self, **attrs): + """Return a generator of NAT Gateways + + :param kwargs query: Optional query parameters to be sent to limit + the resources being returned. + :returns: A generator of NAT Gateway objects + :rtype: :class:`~otcextensions.sdk.nat.v2.nat_gateway.NatGateway` + """ + return self._list(_nat_gateway.NatGateway, **attrs) + + def get_nat_gateway(self, nat_gateway): + """Get a single Nat Gateway + + :param nat_gateway: The value can be the ID of a NAT Gatway or a + :class:`~otcextensions.sdk.nat.v2.nat_gateway.NatGateway` + instance. + + :returns: One :class:`~otcextensions.sdk.nat.v2.nat_gateway.NatGateway` + :raises: :class:`~openstack.exceptions.ResourceNotFound` + when no resource can be found. + """ + return self._get(_nat_gateway.NatGateway, nat_gateway) + + def update_nat_gateway(self, nat_gateway, **attrs): + """Update a NAT Gateway + + :param nat_gateway: Either the ID of a NAT Gateway or a + :class:`~otcextensions.sdk.nat.v2.nat_gateway.NatGateway` instance. + :attrs kwargs: The attributes to update on the server represented + by ``server``. + + :returns: The updated NAT Gateway + :rtype: :class:`~otcextensions.sdk.nat.v2.nat_gateway.NatGateway` + """ + return self._update(_server.Server, server, **attrs) diff --git a/otcextensions/sdk/nat/v2/dnat.py b/otcextensions/sdk/nat/v2/dnat.py new file mode 100644 index 000000000..35a46c40b --- /dev/null +++ b/otcextensions/sdk/nat/v2/dnat.py @@ -0,0 +1,57 @@ +# 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 openstack import resource + +class Dnat(resource.Resource): + resources_key = 'dnat_rules' + base_path = '/dnat_rules' + + # capabilities + allow_create = True + allow_fetch = True + allow_delete = True + allow_list = True + + # Properties + id = resource.Body('id') + #: Specifies the ID of the DNAT rule. + tenant_id = resource.Body('tenant_id') + #: Specifies the project ID. + nat_gateway_id = resource.Body('nat_gateway_id') + #: Specifies the NAT Gateway ID. + port_id = resource.Body('port_id') + #: Specifies the port ID of an ECS or BMS + #: Parameter is used in the VPC scenario. + #: This parameter is an alternative to private_ip + private_ip = resource.Body('private_ip') + #: Specifies the IP address of a Direct Connect connection. + #: Parameter is used in the Direct Connect scenario. + #: This parameter is an alternative to port_id. + internal_service_port = resource.Body('internal_service_port', type=int) + #: Specifies port used by ECS/BMS to provide services for external systems + floating_ip_id = resource.Body('floating_ip_id') + #: Specifies the EIP ID + floating_ip_address = resource.Body('floating_ip_address') + #: Specifies the EIP + external_service_port = resource.Body('external_service_port') + #: Specifies the port for providing external services. + protocol = resource.Body('protocol') + #: Specifies the protocol type. Currently TCP(6), UDP(17) and ANY(0) + status = resource.Body('status') + #: Specifies the status of the DNAT rule + admin_state_up = resource.Body('admin_state_up', type=bool) + #: Specifies whether DNAT rule is enabled / disabled + #: *true:* DNAT rule is enabled + #: *false:* DNAT rule is disabled + created_at = resource.Body('created_at') + #: Specifies when the rule is created. + #: The format is yyyy-mm-dd hh:mm:ss. diff --git a/otcextensions/sdk/nat/v2/nat_gateway.py b/otcextensions/sdk/nat/v2/nat_gateway.py index d87da1924..b33776bf7 100644 --- a/otcextensions/sdk/nat/v2/nat_gateway.py +++ b/otcextensions/sdk/nat/v2/nat_gateway.py @@ -17,10 +17,11 @@ class NatGateway(resource.Resource): # capabilities allow_create = True + allow_fetch = True + allow_commit = True allow_delete = True allow_list = True - #allow_get = True - + # Properties #: Specifies the ID of the NAT gateway. id = resource.Body('id') diff --git a/otcextensions/sdk/nat/v2/snat.py b/otcextensions/sdk/nat/v2/snat.py new file mode 100644 index 000000000..b9f49619e --- /dev/null +++ b/otcextensions/sdk/nat/v2/snat.py @@ -0,0 +1,54 @@ +# 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 openstack import resource + +class Snat(resource.Resource): + resources_key = 'snat_rules' + base_path = '/snat_rules' + + # capabilities + allow_create = True + allow_fetch = True + allow_delete = True + allow_list = True + + # Properties + id = resource.Body('id') + #: Specifies the ID of the SNAT rule. + tenant_id = resource.Body('tenant_id') + #: Specifies the project ID. + nat_gateway_id = resource.Body('nat_gateway_id') + #: Specifies the NAT Gateway ID. + network_id = resource.Body('network_id') + #: Specifies the network ID + cidr = resource.Body('cidr') + #: Specifies a subset of the VPC subnet CIDR block or a + #: CIDR block of Direct Connect connection. + source_type = resource.Body('source_type', type=int) + #: *0:* Either network_id or cidr can be specified in VPC + #: *1:* only cidr can be specified over a Direct Connect connection + #: Default: 0 + floating_ip_id = resource.Body('floating_ip_id') + #: Specifies the EIP ID + #: Multiple EIPs are separated using commas + floating_ip_address = resource.Body('floating_ip_address') + #: Specifies the EIP + #: Multiple EIPs are separated using commas + status = resource.Body('status') + #: Specifies the status of the SNAT rule + admin_state_up = resource.Body('admin_state_up', type=bool) + #: Specifies whether SNAT rule is enabled / disabled + #: *true:* SNAT rule is enabled + #: *false:* SNAT rule is disabled + created_at = resource.Body('created_at') + #: Specifies when the rule is created. + #: The format is yyyy-mm-dd hh:mm:ss. \ No newline at end of file From 4ad264490c0bebd54355085021c1ac6701591057 Mon Sep 17 00:00:00 2001 From: "T. Schreiber" Date: Tue, 12 Nov 2019 14:51:25 +0000 Subject: [PATCH 03/12] dnat and snat proxy functions added --- otcextensions/sdk/nat/v2/_proxy.py | 90 +++++++++++++++++++++++++++++- 1 file changed, 87 insertions(+), 3 deletions(-) diff --git a/otcextensions/sdk/nat/v2/_proxy.py b/otcextensions/sdk/nat/v2/_proxy.py index 36cd1f64e..3a21b133a 100644 --- a/otcextensions/sdk/nat/v2/_proxy.py +++ b/otcextensions/sdk/nat/v2/_proxy.py @@ -10,6 +10,8 @@ # License for the specific language governing permissions and limitations # under the License. from otcextensions.sdk.nat.v2 import nat_gateway as _nat_gateway +from otcextensions.sdk.nat.v2 import snat as _snat +from otcextensions.sdk.nat.v2 import dnat as _dnat from openstack import proxy @@ -26,7 +28,7 @@ def create_gateway(self, **attrs): return self._create(_nat_gateway.NatGateway, **attrs) def delete_gateway(self, id): - """Create a new gateway from attributes + """Delete a NAT gateway :param dict attrs: Keyword arguments which will be used to create a :class:`~otcextensions.sdk.nat.v2.nat_gateway.NatGateway` @@ -61,10 +63,92 @@ def update_nat_gateway(self, nat_gateway, **attrs): :param nat_gateway: Either the ID of a NAT Gateway or a :class:`~otcextensions.sdk.nat.v2.nat_gateway.NatGateway` instance. - :attrs kwargs: The attributes to update on the server represented + :attrs attrs: The attributes to update on the server represented by ``server``. :returns: The updated NAT Gateway :rtype: :class:`~otcextensions.sdk.nat.v2.nat_gateway.NatGateway` """ - return self._update(_server.Server, server, **attrs) + return self._update(_nat_gateway, nat_gateway, **attrs) + +# SNAT rules + + def create_snat_rule(self, **attrs): + """Create a new SNAT rule from attributes + + :param dict attrs: Keyword arguments which will be used to create + a :class:`~otcextensions.sdk.nat.v2.snat.Snat` + """ + return self._create(_snat.Snat, **attrs) + + def delete_snat_rule(self, id): + """Delete a SNAT rule + + :param dict attrs: Keyword arguments which will be used to create + a :class:`~otcextensions.sdk.nat.v2.snat.Snat` + """ + return self._delete(_snat.Snat, id=id) + + def get_snat_rule(self, snat_rule): + """Get a single SNAT rule + + :param snat_rule: The value can be the ID of a SNAT rule or a + :class:`~otcextensions.sdk.nat.v2.snat.Snat` + instance. + + :returns: One :class:`~otcextensions.sdk.nat.v2.snat.Snat` + :raises: :class:`~openstack.exceptions.ResourceNotFound` + when no resource can be found. + """ + return self._get(_snat.Snat, snat_rule) + + def snat_rules(self, **attrs): + """Return a generator of SNAT rules + + :param attrs query: Optional query parameters to be sent to limit + the resources being returned. + :returns: A generator of NAT Gateway objects + :rtype: :class:`~otcextensions.sdk.nat.v2.snat.SNAT` + """ + return self._list(_snat.Snat, **attrs) + +# DNAT rules + + def create_dnat_rule(self, **attrs): + """Create a new DNAT rule from attributes + + :param dict attrs: Keyword arguments which will be used to create + a :class:`~otcextensions.sdk.nat.v2.dnat.Dnat` + """ + return self._create(_dnat.Dnat, **attrs) + + def delete_dnat_rule(self, id): + """Delete a DNAT rule + + :param dict attrs: Keyword arguments which will be used to create + a :class:`~otcextensions.sdk.nat.v2.dnat.Dnat` + """ + return self._delete(_dnat.Dnat, id=id) + + def get_dnat_rule(self, dnat_rule): + """Get a single DNAT rule + + :param dnat_rule: The value can be the ID of a DNAT rule or a + :class:`~otcextensions.sdk.nat.v2.dnat.Dnat` + instance. + + :returns: One :class:`~otcextensions.sdk.nat.v2.dnat.Dnat` + :raises: :class:`~openstack.exceptions.ResourceNotFound` + when no resource can be found. + """ + return self._get(_dnat.Dnat, dnat_rule) + + def dnat_rules(self, **attrs): + """Return a generator of DNAT rules + + :param attrs query: Optional query parameters to be sent to limit + the resources being returned. + :returns: A generator of DNAT rules objects + :rtype: :class:`~otcextensions.sdk.nat.v2.dnat.Dnat` + """ + return self._list(_dnat.Dnat, **attrs) \ No newline at end of file From dcf62914fcc7243ea604a7ca6ab3e514155a8021 Mon Sep 17 00:00:00 2001 From: "T. Schreiber" Date: Fri, 15 Nov 2019 13:36:12 +0000 Subject: [PATCH 04/12] first running state --- otcextensions/sdk/__init__.py | 3 +-- otcextensions/sdk/nat/v2/_proxy.py | 2 ++ otcextensions/sdk/nat/v2/nat_gateway.py | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/otcextensions/sdk/__init__.py b/otcextensions/sdk/__init__.py index c153dac6c..bcf865dec 100644 --- a/otcextensions/sdk/__init__.py +++ b/otcextensions/sdk/__init__.py @@ -83,8 +83,7 @@ 'append_project_id': True, }, 'nat': { - 'service_type': 'nat', - 'append_project_id': True, + 'service_type': 'nat' }, 'obs': { 'service_type': 'obs', diff --git a/otcextensions/sdk/nat/v2/_proxy.py b/otcextensions/sdk/nat/v2/_proxy.py index 3a21b133a..080ffe71e 100644 --- a/otcextensions/sdk/nat/v2/_proxy.py +++ b/otcextensions/sdk/nat/v2/_proxy.py @@ -17,6 +17,8 @@ class Proxy(proxy.Proxy): + skip_discovery = True + # NAT Gateway def create_gateway(self, **attrs): diff --git a/otcextensions/sdk/nat/v2/nat_gateway.py b/otcextensions/sdk/nat/v2/nat_gateway.py index b33776bf7..a7951d81c 100644 --- a/otcextensions/sdk/nat/v2/nat_gateway.py +++ b/otcextensions/sdk/nat/v2/nat_gateway.py @@ -13,6 +13,7 @@ class NatGateway(resource.Resource): resources_key = 'nat_gateways' + resource_key = 'nat_gateway' base_path = '/nat_gateways' # capabilities @@ -37,7 +38,7 @@ class NatGateway(resource.Resource): #: *2:* medium type, supports up to 50,000 SNAT connections #: *3:* large type, supports up to 200,000 SNAT connections #: *4:* extra-large type, supports up to 1,000,000 SNAT connections - spec = resource.Body('spec', type=int) + spec = resource.Body('spec') #: Specifies the router ID router_id = resource.Body('router_id') #: Specifies the network ID of the downstream interface From ecb94c8a418c88f8c03ee3f2e40ff268df18929d Mon Sep 17 00:00:00 2001 From: "T. Schreiber" Date: Fri, 15 Nov 2019 15:07:14 +0000 Subject: [PATCH 05/12] gateway fixed --- otcextensions/sdk/nat/v2/_proxy.py | 50 +++++++++---------- otcextensions/sdk/nat/v2/dnat.py | 48 +++++++++--------- .../sdk/nat/v2/{nat_gateway.py => gateway.py} | 40 +++++++-------- otcextensions/sdk/nat/v2/snat.py | 44 ++++++++-------- 4 files changed, 90 insertions(+), 92 deletions(-) rename otcextensions/sdk/nat/v2/{nat_gateway.py => gateway.py} (87%) diff --git a/otcextensions/sdk/nat/v2/_proxy.py b/otcextensions/sdk/nat/v2/_proxy.py index 080ffe71e..8c19bc932 100644 --- a/otcextensions/sdk/nat/v2/_proxy.py +++ b/otcextensions/sdk/nat/v2/_proxy.py @@ -9,7 +9,7 @@ # 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 otcextensions.sdk.nat.v2 import nat_gateway as _nat_gateway +from otcextensions.sdk.nat.v2 import gateway as _gateway from otcextensions.sdk.nat.v2 import snat as _snat from otcextensions.sdk.nat.v2 import dnat as _dnat @@ -19,59 +19,59 @@ class Proxy(proxy.Proxy): skip_discovery = True -# NAT Gateway +# Gateway def create_gateway(self, **attrs): """Create a new gateway from attributes :param dict attrs: Keyword arguments which will be used to create - a :class:`~otcextensions.sdk.nat.v2.nat_gateway.NatGateway` + a :class:`~otcextensions.sdk.nat.v2.gateway.Gateway` """ - return self._create(_nat_gateway.NatGateway, **attrs) + return self._create(_gateway.Gateway, **attrs) def delete_gateway(self, id): - """Delete a NAT gateway + """Delete a gateway :param dict attrs: Keyword arguments which will be used to create - a :class:`~otcextensions.sdk.nat.v2.nat_gateway.NatGateway` + a :class:`~otcextensions.sdk.nat.v2.gateway.Gateway` """ - return self._delete(_nat_gateway.NatGateway, id=id) + return self._delete(_gateway.Gateway, id=id) def gateways(self, **attrs): - """Return a generator of NAT Gateways + """Return a generator of gateways :param kwargs query: Optional query parameters to be sent to limit the resources being returned. - :returns: A generator of NAT Gateway objects - :rtype: :class:`~otcextensions.sdk.nat.v2.nat_gateway.NatGateway` + :returns: A generator of gateway objects + :rtype: :class:`~otcextensions.sdk.nat.v2.gateway.Gateway` """ - return self._list(_nat_gateway.NatGateway, **attrs) + return self._list(_gateway.Gateway, **attrs) - def get_nat_gateway(self, nat_gateway): - """Get a single Nat Gateway + def get_gateway(self, gateway): + """Get a single gateway - :param nat_gateway: The value can be the ID of a NAT Gatway or a - :class:`~otcextensions.sdk.nat.v2.nat_gateway.NatGateway` + :param gateway: The value can be the ID of a NAT Gatway or a + :class:`~otcextensions.sdk.nat.v2.gateway.Gateway` instance. - :returns: One :class:`~otcextensions.sdk.nat.v2.nat_gateway.NatGateway` + :returns: One :class:`~otcextensions.sdk.nat.v2.gateway.Gateway` :raises: :class:`~openstack.exceptions.ResourceNotFound` when no resource can be found. """ - return self._get(_nat_gateway.NatGateway, nat_gateway) + return self._get(_gateway.Gateway, gateway) - def update_nat_gateway(self, nat_gateway, **attrs): - """Update a NAT Gateway + def update_gateway(self, gateway, **attrs): + """Update a gateway - :param nat_gateway: Either the ID of a NAT Gateway or a - :class:`~otcextensions.sdk.nat.v2.nat_gateway.NatGateway` instance. + :param gateway: Either the ID of a gateway or a + :class:`~otcextensions.sdk.nat.v2.gateway.Gateway` instance. :attrs attrs: The attributes to update on the server represented by ``server``. - :returns: The updated NAT Gateway - :rtype: :class:`~otcextensions.sdk.nat.v2.nat_gateway.NatGateway` + :returns: The updated gateway + :rtype: :class:`~otcextensions.sdk.nat.v2.gateway.Gateway` """ - return self._update(_nat_gateway, nat_gateway, **attrs) + return self._update(_gateway.Gateway, gateway, **attrs) # SNAT rules @@ -109,7 +109,7 @@ def snat_rules(self, **attrs): :param attrs query: Optional query parameters to be sent to limit the resources being returned. - :returns: A generator of NAT Gateway objects + :returns: A generator of gateway objects :rtype: :class:`~otcextensions.sdk.nat.v2.snat.SNAT` """ return self._list(_snat.Snat, **attrs) diff --git a/otcextensions/sdk/nat/v2/dnat.py b/otcextensions/sdk/nat/v2/dnat.py index 35a46c40b..4cada2e6f 100644 --- a/otcextensions/sdk/nat/v2/dnat.py +++ b/otcextensions/sdk/nat/v2/dnat.py @@ -22,36 +22,36 @@ class Dnat(resource.Resource): allow_list = True # Properties - id = resource.Body('id') + #: Specifies whether DNAT rule is enabled / disabled + #: *true:* DNAT rule is enabled + #: *false:* DNAT rule is disabled + admin_state_up = resource.Body('admin_state_up', type=bool) + #: Specifies when the rule is created. + #: The format is yyyy-mm-dd hh:mm:ss. + created_at = resource.Body('created_at') + #: Specifies the port for providing external services. + external_service_port = resource.Body('external_service_port') + #: Specifies the EIP + floating_ip_address = resource.Body('floating_ip_address') + #: Specifies the EIP ID + floating_ip_id = resource.Body('floating_ip_id') + #: Specifies the gateway ID. + gateway_id = resource.Body('gateway_id') #: Specifies the ID of the DNAT rule. - tenant_id = resource.Body('tenant_id') - #: Specifies the project ID. - nat_gateway_id = resource.Body('nat_gateway_id') - #: Specifies the NAT Gateway ID. - port_id = resource.Body('port_id') + id = resource.Body('id') + #: Specifies port used by ECS/BMS to provide services for external systems + internal_service_port = resource.Body('internal_service_port', type=int) #: Specifies the port ID of an ECS or BMS #: Parameter is used in the VPC scenario. #: This parameter is an alternative to private_ip - private_ip = resource.Body('private_ip') + port_id = resource.Body('port_id') #: Specifies the IP address of a Direct Connect connection. #: Parameter is used in the Direct Connect scenario. #: This parameter is an alternative to port_id. - internal_service_port = resource.Body('internal_service_port', type=int) - #: Specifies port used by ECS/BMS to provide services for external systems - floating_ip_id = resource.Body('floating_ip_id') - #: Specifies the EIP ID - floating_ip_address = resource.Body('floating_ip_address') - #: Specifies the EIP - external_service_port = resource.Body('external_service_port') - #: Specifies the port for providing external services. - protocol = resource.Body('protocol') + private_ip = resource.Body('private_ip') #: Specifies the protocol type. Currently TCP(6), UDP(17) and ANY(0) - status = resource.Body('status') + protocol = resource.Body('protocol') #: Specifies the status of the DNAT rule - admin_state_up = resource.Body('admin_state_up', type=bool) - #: Specifies whether DNAT rule is enabled / disabled - #: *true:* DNAT rule is enabled - #: *false:* DNAT rule is disabled - created_at = resource.Body('created_at') - #: Specifies when the rule is created. - #: The format is yyyy-mm-dd hh:mm:ss. + status = resource.Body('status') + #: Specifies the project ID. + tenant_id = resource.Body('tenant_id') \ No newline at end of file diff --git a/otcextensions/sdk/nat/v2/nat_gateway.py b/otcextensions/sdk/nat/v2/gateway.py similarity index 87% rename from otcextensions/sdk/nat/v2/nat_gateway.py rename to otcextensions/sdk/nat/v2/gateway.py index a7951d81c..cf5dc99f4 100644 --- a/otcextensions/sdk/nat/v2/nat_gateway.py +++ b/otcextensions/sdk/nat/v2/gateway.py @@ -11,7 +11,7 @@ # under the License. from openstack import resource -class NatGateway(resource.Resource): +class Gateway(resource.Resource): resources_key = 'nat_gateways' resource_key = 'nat_gateway' base_path = '/nat_gateways' @@ -24,33 +24,31 @@ class NatGateway(resource.Resource): allow_list = True # Properties - #: Specifies the ID of the NAT gateway. + #: Specifies whether GW is up or down + #: *true:* Gw is up + #: *false:* GW is down + admin_state_up = resource.Body('admin_state_up', type=bool) + #: Specifies when GW was is created + #: format is *yyyy-mm-dd hh:mm:ss* + created_at = resource.Body('created_at') + #: Provides description of gateway + description = resource.Body('description') + #: Specifies the ID of the gateway. id = resource.Body('id') - #: Specifies the project ID - tenant_id = resource.Body('tenant_id') - #: Specifies the name of the NAT gateway. + #: Specifies the network ID of the downstream interface + internal_network_id = resource.Body('internal_network_id') + #: Specifies the name of the gateway. #: Contains only digits, letters, underscores and hyphens name = resource.Body('name') - #: Provides description of NAT Gateway - description = resource.Body('description') - #: Specifies the type of the NAT gateway. + #: Specifies the router ID + router_id = resource.Body('router_id') + #: Specifies the type of the gateway. #: *1:* small type, supports up to 10,000 SNAT connections #: *2:* medium type, supports up to 50,000 SNAT connections #: *3:* large type, supports up to 200,000 SNAT connections #: *4:* extra-large type, supports up to 1,000,000 SNAT connections spec = resource.Body('spec') - #: Specifies the router ID - router_id = resource.Body('router_id') - #: Specifies the network ID of the downstream interface - internal_network_id = resource.Body('internal_network_id') #: Specifies the status status = resource.Body('status') - #: Specifies whether GW is up or down - #: *true:* Gw is up - #: *false:* GW is down - admin_state_up = resource.Body('admin_state_up', type=bool) - #: Specifies when GW was is created - #: format is *yyyy-mm-dd hh:mm:ss* - created_at = resource.Body('created_at') - - + #: Specifies the project ID + tenant_id = resource.Body('tenant_id') \ No newline at end of file diff --git a/otcextensions/sdk/nat/v2/snat.py b/otcextensions/sdk/nat/v2/snat.py index b9f49619e..53467da1b 100644 --- a/otcextensions/sdk/nat/v2/snat.py +++ b/otcextensions/sdk/nat/v2/snat.py @@ -22,33 +22,33 @@ class Snat(resource.Resource): allow_list = True # Properties - id = resource.Body('id') - #: Specifies the ID of the SNAT rule. - tenant_id = resource.Body('tenant_id') - #: Specifies the project ID. - nat_gateway_id = resource.Body('nat_gateway_id') - #: Specifies the NAT Gateway ID. - network_id = resource.Body('network_id') - #: Specifies the network ID - cidr = resource.Body('cidr') + #: Specifies the status of the SNAT rule + admin_state_up = resource.Body('admin_state_up', type=bool) #: Specifies a subset of the VPC subnet CIDR block or a #: CIDR block of Direct Connect connection. - source_type = resource.Body('source_type', type=int) - #: *0:* Either network_id or cidr can be specified in VPC - #: *1:* only cidr can be specified over a Direct Connect connection - #: Default: 0 - floating_ip_id = resource.Body('floating_ip_id') - #: Specifies the EIP ID + cidr = resource.Body('cidr') + #: Specifies when the rule is created. + #: The format is yyyy-mm-dd hh:mm:ss. + created_at = resource.Body('created_at') + #: Specifies the EIP #: Multiple EIPs are separated using commas floating_ip_address = resource.Body('floating_ip_address') - #: Specifies the EIP + #: Specifies the EIP ID #: Multiple EIPs are separated using commas - status = resource.Body('status') - #: Specifies the status of the SNAT rule - admin_state_up = resource.Body('admin_state_up', type=bool) + floating_ip_id = resource.Body('floating_ip_id') + #: Specifies the gateway ID. + gateway_id = resource.Body('gateway_id') + #: Specifies the ID of the SNAT rule. + id = resource.Body('id') + #: Specifies the network ID + network_id = resource.Body('network_id') + #: *0:* Either network_id or cidr can be specified in VPC + #: *1:* only cidr can be specified over a Direct Connect connection + #: Default: 0 + source_type = resource.Body('source_type', type=int) #: Specifies whether SNAT rule is enabled / disabled #: *true:* SNAT rule is enabled #: *false:* SNAT rule is disabled - created_at = resource.Body('created_at') - #: Specifies when the rule is created. - #: The format is yyyy-mm-dd hh:mm:ss. \ No newline at end of file + status = resource.Body('status') + #: Specifies the project ID. + tenant_id = resource.Body('tenant_id') \ No newline at end of file From de41e076ab88a04474ff8e2a9aa477cf9c813772 Mon Sep 17 00:00:00 2001 From: "T. Schreiber" Date: Fri, 15 Nov 2019 15:22:44 +0000 Subject: [PATCH 06/12] linting corrections --- otcextensions/sdk/__init__.py | 2 +- otcextensions/sdk/nat/v2/_proxy.py | 6 ++++-- otcextensions/sdk/nat/v2/dnat.py | 5 +++-- otcextensions/sdk/nat/v2/gateway.py | 5 +++-- otcextensions/sdk/nat/v2/snat.py | 9 +++++---- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/otcextensions/sdk/__init__.py b/otcextensions/sdk/__init__.py index bcf865dec..a02385686 100644 --- a/otcextensions/sdk/__init__.py +++ b/otcextensions/sdk/__init__.py @@ -84,7 +84,7 @@ }, 'nat': { 'service_type': 'nat' - }, + }, 'obs': { 'service_type': 'obs', 'require_ak': True, diff --git a/otcextensions/sdk/nat/v2/_proxy.py b/otcextensions/sdk/nat/v2/_proxy.py index 8c19bc932..cca88af90 100644 --- a/otcextensions/sdk/nat/v2/_proxy.py +++ b/otcextensions/sdk/nat/v2/_proxy.py @@ -15,6 +15,7 @@ from openstack import proxy + class Proxy(proxy.Proxy): skip_discovery = True @@ -64,7 +65,8 @@ def update_gateway(self, gateway, **attrs): """Update a gateway :param gateway: Either the ID of a gateway or a - :class:`~otcextensions.sdk.nat.v2.gateway.Gateway` instance. + :class:`~otcextensions.sdk.nat.v2.gateway.Gateway` + instance. :attrs attrs: The attributes to update on the server represented by ``server``. @@ -153,4 +155,4 @@ def dnat_rules(self, **attrs): :returns: A generator of DNAT rules objects :rtype: :class:`~otcextensions.sdk.nat.v2.dnat.Dnat` """ - return self._list(_dnat.Dnat, **attrs) \ No newline at end of file + return self._list(_dnat.Dnat, **attrs) diff --git a/otcextensions/sdk/nat/v2/dnat.py b/otcextensions/sdk/nat/v2/dnat.py index 4cada2e6f..c26f928ac 100644 --- a/otcextensions/sdk/nat/v2/dnat.py +++ b/otcextensions/sdk/nat/v2/dnat.py @@ -11,6 +11,7 @@ # under the License. from openstack import resource + class Dnat(resource.Resource): resources_key = 'dnat_rules' base_path = '/dnat_rules' @@ -20,7 +21,7 @@ class Dnat(resource.Resource): allow_fetch = True allow_delete = True allow_list = True - + # Properties #: Specifies whether DNAT rule is enabled / disabled #: *true:* DNAT rule is enabled @@ -54,4 +55,4 @@ class Dnat(resource.Resource): #: Specifies the status of the DNAT rule status = resource.Body('status') #: Specifies the project ID. - tenant_id = resource.Body('tenant_id') \ No newline at end of file + tenant_id = resource.Body('tenant_id') diff --git a/otcextensions/sdk/nat/v2/gateway.py b/otcextensions/sdk/nat/v2/gateway.py index cf5dc99f4..8080521f9 100644 --- a/otcextensions/sdk/nat/v2/gateway.py +++ b/otcextensions/sdk/nat/v2/gateway.py @@ -11,6 +11,7 @@ # under the License. from openstack import resource + class Gateway(resource.Resource): resources_key = 'nat_gateways' resource_key = 'nat_gateway' @@ -22,7 +23,7 @@ class Gateway(resource.Resource): allow_commit = True allow_delete = True allow_list = True - + # Properties #: Specifies whether GW is up or down #: *true:* Gw is up @@ -51,4 +52,4 @@ class Gateway(resource.Resource): #: Specifies the status status = resource.Body('status') #: Specifies the project ID - tenant_id = resource.Body('tenant_id') \ No newline at end of file + tenant_id = resource.Body('tenant_id') diff --git a/otcextensions/sdk/nat/v2/snat.py b/otcextensions/sdk/nat/v2/snat.py index 53467da1b..a2e556de3 100644 --- a/otcextensions/sdk/nat/v2/snat.py +++ b/otcextensions/sdk/nat/v2/snat.py @@ -11,6 +11,7 @@ # under the License. from openstack import resource + class Snat(resource.Resource): resources_key = 'snat_rules' base_path = '/snat_rules' @@ -20,16 +21,16 @@ class Snat(resource.Resource): allow_fetch = True allow_delete = True allow_list = True - + # Properties #: Specifies the status of the SNAT rule admin_state_up = resource.Body('admin_state_up', type=bool) - #: Specifies a subset of the VPC subnet CIDR block or a + #: Specifies a subset of the VPC subnet CIDR block or a #: CIDR block of Direct Connect connection. cidr = resource.Body('cidr') #: Specifies when the rule is created. #: The format is yyyy-mm-dd hh:mm:ss. - created_at = resource.Body('created_at') + created_at = resource.Body('created_at') #: Specifies the EIP #: Multiple EIPs are separated using commas floating_ip_address = resource.Body('floating_ip_address') @@ -51,4 +52,4 @@ class Snat(resource.Resource): #: *false:* SNAT rule is disabled status = resource.Body('status') #: Specifies the project ID. - tenant_id = resource.Body('tenant_id') \ No newline at end of file + tenant_id = resource.Body('tenant_id') From 2d10ad3c6c381db3035ad9f34e63b75f541defb4 Mon Sep 17 00:00:00 2001 From: "T. Schreiber" Date: Mon, 18 Nov 2019 15:46:18 +0000 Subject: [PATCH 07/12] Minor changes, tested successfully --- otcextensions/sdk/nat/v2/dnat.py | 13 ++++++++++++- otcextensions/sdk/nat/v2/gateway.py | 6 ++++++ otcextensions/sdk/nat/v2/snat.py | 15 +++++++++++---- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/otcextensions/sdk/nat/v2/dnat.py b/otcextensions/sdk/nat/v2/dnat.py index c26f928ac..fc7f842dd 100644 --- a/otcextensions/sdk/nat/v2/dnat.py +++ b/otcextensions/sdk/nat/v2/dnat.py @@ -14,6 +14,7 @@ class Dnat(resource.Resource): resources_key = 'dnat_rules' + resource_key = 'dnat_rule' base_path = '/dnat_rules' # capabilities @@ -22,6 +23,14 @@ class Dnat(resource.Resource): allow_delete = True allow_list = True + _query_mapping = resource.QueryParameters( + 'admin_state_up', 'cidr', 'created_at', 'external_service_port', + 'floating_ip_address', 'floating_ip_id', 'id', + 'internal_service_port', 'limit', 'nat_gateway_id', 'network_id', + 'port_id', 'private_id', 'protocol', 'source_type', 'status', + 'tenant_id' + ) + # Properties #: Specifies whether DNAT rule is enabled / disabled #: *true:* DNAT rule is enabled @@ -31,7 +40,7 @@ class Dnat(resource.Resource): #: The format is yyyy-mm-dd hh:mm:ss. created_at = resource.Body('created_at') #: Specifies the port for providing external services. - external_service_port = resource.Body('external_service_port') + external_service_port = resource.Body('external_service_port', type=int) #: Specifies the EIP floating_ip_address = resource.Body('floating_ip_address') #: Specifies the EIP ID @@ -42,6 +51,8 @@ class Dnat(resource.Resource): id = resource.Body('id') #: Specifies port used by ECS/BMS to provide services for external systems internal_service_port = resource.Body('internal_service_port', type=int) + #: Specifies the ID of the NAT gateway. + nat_gateway_id = resource.Body('nat_gateway_id') #: Specifies the port ID of an ECS or BMS #: Parameter is used in the VPC scenario. #: This parameter is an alternative to private_ip diff --git a/otcextensions/sdk/nat/v2/gateway.py b/otcextensions/sdk/nat/v2/gateway.py index 8080521f9..0b42f1172 100644 --- a/otcextensions/sdk/nat/v2/gateway.py +++ b/otcextensions/sdk/nat/v2/gateway.py @@ -24,6 +24,12 @@ class Gateway(resource.Resource): allow_delete = True allow_list = True + _query_mapping = resource.QueryParameters( + 'admin_state_up', 'created_at', 'description', 'id', + 'internal_network_id', 'limit', 'name', 'router_id', + 'spec', 'status', 'tenant_id' + ) + # Properties #: Specifies whether GW is up or down #: *true:* Gw is up diff --git a/otcextensions/sdk/nat/v2/snat.py b/otcextensions/sdk/nat/v2/snat.py index a2e556de3..dc8afcc7e 100644 --- a/otcextensions/sdk/nat/v2/snat.py +++ b/otcextensions/sdk/nat/v2/snat.py @@ -14,6 +14,7 @@ class Snat(resource.Resource): resources_key = 'snat_rules' + resource_key = 'snat_rule' base_path = '/snat_rules' # capabilities @@ -22,6 +23,12 @@ class Snat(resource.Resource): allow_delete = True allow_list = True + _query_mapping = resource.QueryParameters( + 'admin_state_up', 'cidr', 'created_at', 'floating_ip_address', + 'floating_ip_id', 'id', 'limit', 'nat_gateway_id', 'network_id', + 'source_type', 'status', 'tenant_id' + ) + # Properties #: Specifies the status of the SNAT rule admin_state_up = resource.Body('admin_state_up', type=bool) @@ -37,12 +44,14 @@ class Snat(resource.Resource): #: Specifies the EIP ID #: Multiple EIPs are separated using commas floating_ip_id = resource.Body('floating_ip_id') - #: Specifies the gateway ID. - gateway_id = resource.Body('gateway_id') #: Specifies the ID of the SNAT rule. id = resource.Body('id') + #: Specifies the gateway ID. + nat_gateway_id = resource.Body('nat_gateway_id') #: Specifies the network ID network_id = resource.Body('network_id') + #: Specifies the project ID. + tenant_id = resource.Body('tenant_id') #: *0:* Either network_id or cidr can be specified in VPC #: *1:* only cidr can be specified over a Direct Connect connection #: Default: 0 @@ -51,5 +60,3 @@ class Snat(resource.Resource): #: *true:* SNAT rule is enabled #: *false:* SNAT rule is disabled status = resource.Body('status') - #: Specifies the project ID. - tenant_id = resource.Body('tenant_id') From e1b927ff96e5d0b86116ab01bcd716b875b65c3e Mon Sep 17 00:00:00 2001 From: "T. Schreiber" Date: Tue, 19 Nov 2019 15:28:52 +0000 Subject: [PATCH 08/12] unittest nat.test_snat nat.test_dnat and nat.test_gateway added --- otcextensions/tests/unit/sdk/nat/__init__.py | 0 .../tests/unit/sdk/nat/v2/test_dnat.py | 67 +++++++++++++++++++ .../tests/unit/sdk/nat/v2/test_gateway.py | 60 +++++++++++++++++ .../tests/unit/sdk/nat/v2/test_proxy.py | 0 .../tests/unit/sdk/nat/v2/test_snat.py | 61 +++++++++++++++++ 5 files changed, 188 insertions(+) create mode 100644 otcextensions/tests/unit/sdk/nat/__init__.py create mode 100644 otcextensions/tests/unit/sdk/nat/v2/test_dnat.py create mode 100644 otcextensions/tests/unit/sdk/nat/v2/test_gateway.py create mode 100644 otcextensions/tests/unit/sdk/nat/v2/test_proxy.py create mode 100644 otcextensions/tests/unit/sdk/nat/v2/test_snat.py diff --git a/otcextensions/tests/unit/sdk/nat/__init__.py b/otcextensions/tests/unit/sdk/nat/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/otcextensions/tests/unit/sdk/nat/v2/test_dnat.py b/otcextensions/tests/unit/sdk/nat/v2/test_dnat.py new file mode 100644 index 000000000..60f2c0ac2 --- /dev/null +++ b/otcextensions/tests/unit/sdk/nat/v2/test_dnat.py @@ -0,0 +1,67 @@ +# 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 openstack.tests.unit import base + +from otcextensions.sdk.nat.v2 import dnat + + +INSTANCE_ID = '5b95c675-69c2-4656-ba06-58ff72e1d338' +EXAMPLE = { + 'floating_ip_id': 'bdc10a4c-d81a-41ec-adf7-de857f7c812a', + 'status': 'ACTIVE', + 'nat_gateway_id': 'a78fb3eb-1654-4710-8742-3fc49d5f04f8', + 'admin_state_up': True, + 'port_id': '9a469561-daac-4c94-88f5-39366e5ea193', + 'internal_service_port': 993, + 'protocol': 'TCP', + 'tenant_id': '27e25061336f4af590faeabeb7fcd9a3', + 'created_at': '2017-11-18 07:54:21.665430', + 'id': INSTANCE_ID, + 'floating_ip_address': '5.21.11.226', + 'external_service_port': 242, + 'private_ip': "", +} + + +class TestDnat(base.TestCase): + + def test_basic(self): + sot = dnat.Dnat() + self.assertEqual('dnat_rule', sot.resource_key) + self.assertEqual('dnat_rules', sot.resources_key) + path = '/dnat_rules' + self.assertEqual(path, sot.base_path) + self.assertTrue(sot.allow_list) + self.assertTrue(sot.allow_create) + self.assertTrue(sot.allow_fetch) + self.assertFalse(sot.allow_commit) + self.assertTrue(sot.allow_delete) + + def test_make_it(self): + sot = dnat.Dnat(**EXAMPLE) + self.assertEqual(EXAMPLE['floating_ip_id'], sot.floating_ip_id) + self.assertEqual(EXAMPLE['status'], sot.status) + self.assertEqual(EXAMPLE['nat_gateway_id'], sot.nat_gateway_id) + self.assertEqual(EXAMPLE['admin_state_up'], sot.admin_state_up) + self.assertEqual(EXAMPLE['port_id'], sot.port_id) + self.assertEqual(EXAMPLE['internal_service_port'], + sot.internal_service_port) + self.assertEqual(EXAMPLE['protocol'], sot.protocol) + self.assertEqual(EXAMPLE['tenant_id'], sot.tenant_id) + self.assertEqual(EXAMPLE['created_at'], sot.created_at) + self.assertEqual(EXAMPLE['id'], sot.id) + self.assertEqual(EXAMPLE['floating_ip_address'], + sot.floating_ip_address) + self.assertEqual(EXAMPLE['external_service_port'], + sot.external_service_port) + self.assertEqual(EXAMPLE['private_ip'], sot.private_ip) diff --git a/otcextensions/tests/unit/sdk/nat/v2/test_gateway.py b/otcextensions/tests/unit/sdk/nat/v2/test_gateway.py new file mode 100644 index 000000000..ae462908b --- /dev/null +++ b/otcextensions/tests/unit/sdk/nat/v2/test_gateway.py @@ -0,0 +1,60 @@ +# 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 openstack.tests.unit import base + +from otcextensions.sdk.nat.v2 import gateway + + +INSTANCE_NAME = 'GATEWAYNAME' +INSTANCE_ID = 'a78fb3eb-1654-4710-8742-3fc49d5f04f8' +EXAMPLE = { + 'router_id': 'd84f345c-80a1-4fa2-a39c-d0d397c3f09a', + 'status': 'PENDING_CREATE', + 'description': 'Test Gateway Response', + 'admin_state_up': True, + 'tenant_id': '27e25061336f4af590faeabeb7fcd9a3', + 'created_at': '2017-11-18 07:34:32.203044', + 'spec': '2', + 'internal_network_id': '89d66639-aacb-4929-969d-07080b0f9fd9', + 'id': INSTANCE_ID, + 'name': INSTANCE_NAME +} + + +class TestGateway(base.TestCase): + + def test_basic(self): + sot = gateway.Gateway() + self.assertEqual('nat_gateway', sot.resource_key) + self.assertEqual('nat_gateways', sot.resources_key) + path = '/nat_gateways' + self.assertEqual(path, sot.base_path) + self.assertTrue(sot.allow_list) + self.assertTrue(sot.allow_create) + self.assertTrue(sot.allow_fetch) + self.assertTrue(sot.allow_commit) + self.assertTrue(sot.allow_delete) + + def test_make_it(self): + sot = gateway.Gateway(**EXAMPLE) + self.assertEqual(EXAMPLE['router_id'], sot.router_id) + self.assertEqual(EXAMPLE['status'], sot.status) + self.assertEqual(EXAMPLE['description'], sot.description) + self.assertEqual(EXAMPLE['admin_state_up'], sot.admin_state_up) + self.assertEqual(EXAMPLE['tenant_id'], sot.tenant_id) + self.assertEqual(EXAMPLE['created_at'], sot.created_at) + self.assertEqual(EXAMPLE['spec'], sot.spec) + self.assertEqual(EXAMPLE['internal_network_id'], + sot.internal_network_id) + self.assertEqual(EXAMPLE['id'], sot.id) + self.assertEqual(EXAMPLE['name'], sot.name) diff --git a/otcextensions/tests/unit/sdk/nat/v2/test_proxy.py b/otcextensions/tests/unit/sdk/nat/v2/test_proxy.py new file mode 100644 index 000000000..e69de29bb diff --git a/otcextensions/tests/unit/sdk/nat/v2/test_snat.py b/otcextensions/tests/unit/sdk/nat/v2/test_snat.py new file mode 100644 index 000000000..7a801a63f --- /dev/null +++ b/otcextensions/tests/unit/sdk/nat/v2/test_snat.py @@ -0,0 +1,61 @@ +# 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 openstack.tests.unit import base + +from otcextensions.sdk.nat.v2 import snat + + +INSTANCE_ID = '5b95c675-69c2-4656-ba06-58ff72e1d338' +EXAMPLE = { + 'floating_ip_id': 'bdc10a4c-d81a-41ec-adf7-de857f7c812a', + 'status': 'PENDING_CREATE', + 'nat_gateway_id': 'a78fb3eb-1654-4710-8742-3fc49d5f04f8', + 'admin_state_up': True, + 'network_id': 'eaad9cd6-2372-4be1-9535-9bd37210ae7b', + 'cidr': None, + 'source_type': 0, + 'tenant_id': '27e25061336f4af590faeabeb7fcd9a3', + 'created_at': '2017-11-18 07:54:21.665430', + 'id': INSTANCE_ID, + 'floating_ip_address': '5.21.11.226' +} + + +class TestSnat(base.TestCase): + + def test_basic(self): + sot = snat.Snat() + self.assertEqual('snat_rule', sot.resource_key) + self.assertEqual('snat_rules', sot.resources_key) + path = '/snat_rules' + self.assertEqual(path, sot.base_path) + self.assertTrue(sot.allow_list) + self.assertTrue(sot.allow_create) + self.assertTrue(sot.allow_fetch) + self.assertFalse(sot.allow_commit) + self.assertTrue(sot.allow_delete) + + def test_make_it(self): + sot = snat.Snat(**EXAMPLE) + self.assertEqual(EXAMPLE['floating_ip_id'], sot.floating_ip_id) + self.assertEqual(EXAMPLE['status'], sot.status) + self.assertEqual(EXAMPLE['nat_gateway_id'], sot.nat_gateway_id) + self.assertEqual(EXAMPLE['admin_state_up'], sot.admin_state_up) + self.assertEqual(EXAMPLE['network_id'], sot.network_id) + self.assertIsNone(sot.cidr) + self.assertEqual(EXAMPLE['source_type'], sot.source_type) + self.assertEqual(EXAMPLE['tenant_id'], sot.tenant_id) + self.assertEqual(EXAMPLE['created_at'], sot.created_at) + self.assertEqual(EXAMPLE['id'], sot.id) + self.assertEqual(EXAMPLE['floating_ip_address'], + sot.floating_ip_address) From 6b1d299540d58f66441e33fe844e1c733ec2c0d8 Mon Sep 17 00:00:00 2001 From: "T. Schreiber" Date: Fri, 6 Dec 2019 14:39:06 +0000 Subject: [PATCH 09/12] nat changes --- otcextensions/sdk/nat/v2/_proxy.py | 92 ++++++++++++++----- otcextensions/sdk/nat/v2/dnat.py | 6 +- otcextensions/sdk/nat/v2/gateway.py | 6 +- otcextensions/sdk/nat/v2/snat.py | 4 +- .../tests/unit/sdk/nat/v2/test_dnat.py | 4 +- .../tests/unit/sdk/nat/v2/test_gateway.py | 4 +- .../tests/unit/sdk/nat/v2/test_snat.py | 4 +- 7 files changed, 82 insertions(+), 38 deletions(-) diff --git a/otcextensions/sdk/nat/v2/_proxy.py b/otcextensions/sdk/nat/v2/_proxy.py index cca88af90..dbb9c7436 100644 --- a/otcextensions/sdk/nat/v2/_proxy.py +++ b/otcextensions/sdk/nat/v2/_proxy.py @@ -20,8 +20,7 @@ class Proxy(proxy.Proxy): skip_discovery = True -# Gateway - + # ======== Gateway ======== def create_gateway(self, **attrs): """Create a new gateway from attributes @@ -30,23 +29,40 @@ def create_gateway(self, **attrs): """ return self._create(_gateway.Gateway, **attrs) +<<<<<<< Updated upstream def delete_gateway(self, id): +======= + def delete_gateway(self, gateway, ignore_missing=True): +>>>>>>> Stashed changes """Delete a gateway - :param dict attrs: Keyword arguments which will be used to create - a :class:`~otcextensions.sdk.nat.v2.gateway.Gateway` + :param gateway: key id or an instance of + :class:`~otcextensions.sdk.nat.v2.gateway.Gateway` + :param bool ignore_missing: When set to ``False`` + :class:`~openstack.exceptions.ResourceNotFound` will be raised when + the gateway does not exist. + When set to ``True``, no exception will be set when attempting to + delete a nonexistent gateway. + + :returns: Gateway been deleted + :rtype: :class:`~otcextensions.sdk.nat.v2.gateway.Gateway` """ +<<<<<<< Updated upstream return self._delete(_gateway.Gateway, id=id) +======= + return self._delete(_gateway.Gateway, gateway, + ignore_missing=ignore_missing) +>>>>>>> Stashed changes - def gateways(self, **attrs): + def gateways(self, **query): """Return a generator of gateways - :param kwargs query: Optional query parameters to be sent to limit + :param dict query: Optional query parameters to be sent to limit the resources being returned. :returns: A generator of gateway objects :rtype: :class:`~otcextensions.sdk.nat.v2.gateway.Gateway` """ - return self._list(_gateway.Gateway, **attrs) + return self._list(_gateway.Gateway, **query) def get_gateway(self, gateway): """Get a single gateway @@ -67,16 +83,15 @@ def update_gateway(self, gateway, **attrs): :param gateway: Either the ID of a gateway or a :class:`~otcextensions.sdk.nat.v2.gateway.Gateway` instance. - :attrs attrs: The attributes to update on the server represented - by ``server``. + :param dict attrs: The attributes to update on the gateway represented + by ``gateway``. :returns: The updated gateway :rtype: :class:`~otcextensions.sdk.nat.v2.gateway.Gateway` """ return self._update(_gateway.Gateway, gateway, **attrs) -# SNAT rules - + # ======== SNAT rules ======== def create_snat_rule(self, **attrs): """Create a new SNAT rule from attributes @@ -85,13 +100,27 @@ def create_snat_rule(self, **attrs): """ return self._create(_snat.Snat, **attrs) +<<<<<<< Updated upstream def delete_snat_rule(self, id): +======= + def delete_snat_rule(self, snat, ignore_missing=True): +>>>>>>> Stashed changes """Delete a SNAT rule - :param dict attrs: Keyword arguments which will be used to create - a :class:`~otcextensions.sdk.nat.v2.snat.Snat` + :param bool ignore_missing: When set to ``False`` + :class:`~openstack.exceptions.ResourceNotFound` will be raised when + the SNAT rule does not exist. + When set to ``True``, no exception will be set when attempting to + delete a nonexistent SNAT rule. + + :returns: SNAT rule been deleted + :rtype: :class:`~otcextensions.sdk.nat.v2.snat.Snat` """ +<<<<<<< Updated upstream return self._delete(_snat.Snat, id=id) +======= + return self._delete(_snat.Snat, snat, ignore_missing=ignore_missing) +>>>>>>> Stashed changes def get_snat_rule(self, snat_rule): """Get a single SNAT rule @@ -106,18 +135,17 @@ def get_snat_rule(self, snat_rule): """ return self._get(_snat.Snat, snat_rule) - def snat_rules(self, **attrs): + def snat_rules(self, **query): """Return a generator of SNAT rules - :param attrs query: Optional query parameters to be sent to limit + :param dict query: Optional query parameters to be sent to limit the resources being returned. - :returns: A generator of gateway objects - :rtype: :class:`~otcextensions.sdk.nat.v2.snat.SNAT` + :returns: A generator of Snat rule objects + :rtype: :class:`~otcextensions.sdk.nat.v2.snat.Snat` """ - return self._list(_snat.Snat, **attrs) - -# DNAT rules + return self._list(_snat.Snat, **query) + # ======== DNAT rules ======== def create_dnat_rule(self, **attrs): """Create a new DNAT rule from attributes @@ -126,13 +154,29 @@ def create_dnat_rule(self, **attrs): """ return self._create(_dnat.Dnat, **attrs) +<<<<<<< Updated upstream def delete_dnat_rule(self, id): +======= + def delete_dnat_rule(self, dnat, ignore_missing=True): +>>>>>>> Stashed changes """Delete a DNAT rule - :param dict attrs: Keyword arguments which will be used to create + :param dict attrs: Keyword arguments which will be used to delete a :class:`~otcextensions.sdk.nat.v2.dnat.Dnat` + :param bool ignore_missing: When set to ``False`` + :class:`~openstack.exceptions.ResourceNotFound` will be raised when + the DNAT rule does not exist. + When set to ``True``, no exception will be set when attempting to + delete a nonexistent DNAT rule. + + :returns: DNAT rule been deleted + :rtype: :class:`~otcextensions.sdk.nat.v2.dnat.Dnat` """ +<<<<<<< Updated upstream return self._delete(_dnat.Dnat, id=id) +======= + return self._delete(_dnat.Dnat, dnat, ignore_missing=ignore_missing) +>>>>>>> Stashed changes def get_dnat_rule(self, dnat_rule): """Get a single DNAT rule @@ -147,12 +191,12 @@ def get_dnat_rule(self, dnat_rule): """ return self._get(_dnat.Dnat, dnat_rule) - def dnat_rules(self, **attrs): + def dnat_rules(self, **query): """Return a generator of DNAT rules - :param attrs query: Optional query parameters to be sent to limit + :param dict query: Optional query parameters to be sent to limit the resources being returned. :returns: A generator of DNAT rules objects :rtype: :class:`~otcextensions.sdk.nat.v2.dnat.Dnat` """ - return self._list(_dnat.Dnat, **attrs) + return self._list(_dnat.Dnat, **query) diff --git a/otcextensions/sdk/nat/v2/dnat.py b/otcextensions/sdk/nat/v2/dnat.py index fc7f842dd..5c71f7e2c 100644 --- a/otcextensions/sdk/nat/v2/dnat.py +++ b/otcextensions/sdk/nat/v2/dnat.py @@ -28,7 +28,7 @@ class Dnat(resource.Resource): 'floating_ip_address', 'floating_ip_id', 'id', 'internal_service_port', 'limit', 'nat_gateway_id', 'network_id', 'port_id', 'private_id', 'protocol', 'source_type', 'status', - 'tenant_id' + 'project_id' ) # Properties @@ -61,9 +61,9 @@ class Dnat(resource.Resource): #: Parameter is used in the Direct Connect scenario. #: This parameter is an alternative to port_id. private_ip = resource.Body('private_ip') + #: Specifies the project ID. + project_id = resource.Body('tenant_id') #: Specifies the protocol type. Currently TCP(6), UDP(17) and ANY(0) protocol = resource.Body('protocol') #: Specifies the status of the DNAT rule status = resource.Body('status') - #: Specifies the project ID. - tenant_id = resource.Body('tenant_id') diff --git a/otcextensions/sdk/nat/v2/gateway.py b/otcextensions/sdk/nat/v2/gateway.py index 0b42f1172..bcacd7f32 100644 --- a/otcextensions/sdk/nat/v2/gateway.py +++ b/otcextensions/sdk/nat/v2/gateway.py @@ -27,7 +27,7 @@ class Gateway(resource.Resource): _query_mapping = resource.QueryParameters( 'admin_state_up', 'created_at', 'description', 'id', 'internal_network_id', 'limit', 'name', 'router_id', - 'spec', 'status', 'tenant_id' + 'spec', 'status', 'project_id' ) # Properties @@ -47,6 +47,8 @@ class Gateway(resource.Resource): #: Specifies the name of the gateway. #: Contains only digits, letters, underscores and hyphens name = resource.Body('name') + #: Specifies the project ID + project_id = resource.Body('tenant_id') #: Specifies the router ID router_id = resource.Body('router_id') #: Specifies the type of the gateway. @@ -57,5 +59,3 @@ class Gateway(resource.Resource): spec = resource.Body('spec') #: Specifies the status status = resource.Body('status') - #: Specifies the project ID - tenant_id = resource.Body('tenant_id') diff --git a/otcextensions/sdk/nat/v2/snat.py b/otcextensions/sdk/nat/v2/snat.py index dc8afcc7e..57c75685f 100644 --- a/otcextensions/sdk/nat/v2/snat.py +++ b/otcextensions/sdk/nat/v2/snat.py @@ -26,7 +26,7 @@ class Snat(resource.Resource): _query_mapping = resource.QueryParameters( 'admin_state_up', 'cidr', 'created_at', 'floating_ip_address', 'floating_ip_id', 'id', 'limit', 'nat_gateway_id', 'network_id', - 'source_type', 'status', 'tenant_id' + 'source_type', 'status', 'project_id' ) # Properties @@ -51,7 +51,7 @@ class Snat(resource.Resource): #: Specifies the network ID network_id = resource.Body('network_id') #: Specifies the project ID. - tenant_id = resource.Body('tenant_id') + project_id = resource.Body('tenant_id') #: *0:* Either network_id or cidr can be specified in VPC #: *1:* only cidr can be specified over a Direct Connect connection #: Default: 0 diff --git a/otcextensions/tests/unit/sdk/nat/v2/test_dnat.py b/otcextensions/tests/unit/sdk/nat/v2/test_dnat.py index 60f2c0ac2..655773526 100644 --- a/otcextensions/tests/unit/sdk/nat/v2/test_dnat.py +++ b/otcextensions/tests/unit/sdk/nat/v2/test_dnat.py @@ -24,7 +24,7 @@ 'port_id': '9a469561-daac-4c94-88f5-39366e5ea193', 'internal_service_port': 993, 'protocol': 'TCP', - 'tenant_id': '27e25061336f4af590faeabeb7fcd9a3', + 'project_id': '27e25061336f4af590faeabeb7fcd9a3', 'created_at': '2017-11-18 07:54:21.665430', 'id': INSTANCE_ID, 'floating_ip_address': '5.21.11.226', @@ -57,7 +57,7 @@ def test_make_it(self): self.assertEqual(EXAMPLE['internal_service_port'], sot.internal_service_port) self.assertEqual(EXAMPLE['protocol'], sot.protocol) - self.assertEqual(EXAMPLE['tenant_id'], sot.tenant_id) + self.assertEqual(EXAMPLE['project_id'], sot.project_id) self.assertEqual(EXAMPLE['created_at'], sot.created_at) self.assertEqual(EXAMPLE['id'], sot.id) self.assertEqual(EXAMPLE['floating_ip_address'], diff --git a/otcextensions/tests/unit/sdk/nat/v2/test_gateway.py b/otcextensions/tests/unit/sdk/nat/v2/test_gateway.py index ae462908b..327231eae 100644 --- a/otcextensions/tests/unit/sdk/nat/v2/test_gateway.py +++ b/otcextensions/tests/unit/sdk/nat/v2/test_gateway.py @@ -22,7 +22,7 @@ 'status': 'PENDING_CREATE', 'description': 'Test Gateway Response', 'admin_state_up': True, - 'tenant_id': '27e25061336f4af590faeabeb7fcd9a3', + 'project_id': '27e25061336f4af590faeabeb7fcd9a3', 'created_at': '2017-11-18 07:34:32.203044', 'spec': '2', 'internal_network_id': '89d66639-aacb-4929-969d-07080b0f9fd9', @@ -51,7 +51,7 @@ def test_make_it(self): self.assertEqual(EXAMPLE['status'], sot.status) self.assertEqual(EXAMPLE['description'], sot.description) self.assertEqual(EXAMPLE['admin_state_up'], sot.admin_state_up) - self.assertEqual(EXAMPLE['tenant_id'], sot.tenant_id) + self.assertEqual(EXAMPLE['project_id'], sot.project_id) self.assertEqual(EXAMPLE['created_at'], sot.created_at) self.assertEqual(EXAMPLE['spec'], sot.spec) self.assertEqual(EXAMPLE['internal_network_id'], diff --git a/otcextensions/tests/unit/sdk/nat/v2/test_snat.py b/otcextensions/tests/unit/sdk/nat/v2/test_snat.py index 7a801a63f..21cf7ee60 100644 --- a/otcextensions/tests/unit/sdk/nat/v2/test_snat.py +++ b/otcextensions/tests/unit/sdk/nat/v2/test_snat.py @@ -24,7 +24,7 @@ 'network_id': 'eaad9cd6-2372-4be1-9535-9bd37210ae7b', 'cidr': None, 'source_type': 0, - 'tenant_id': '27e25061336f4af590faeabeb7fcd9a3', + 'project_id': '27e25061336f4af590faeabeb7fcd9a3', 'created_at': '2017-11-18 07:54:21.665430', 'id': INSTANCE_ID, 'floating_ip_address': '5.21.11.226' @@ -54,7 +54,7 @@ def test_make_it(self): self.assertEqual(EXAMPLE['network_id'], sot.network_id) self.assertIsNone(sot.cidr) self.assertEqual(EXAMPLE['source_type'], sot.source_type) - self.assertEqual(EXAMPLE['tenant_id'], sot.tenant_id) + self.assertEqual(EXAMPLE['project_id'], sot.project_id) self.assertEqual(EXAMPLE['created_at'], sot.created_at) self.assertEqual(EXAMPLE['id'], sot.id) self.assertEqual(EXAMPLE['floating_ip_address'], From 28bfb42f5451d6c2377a51f416c947256cc6abc0 Mon Sep 17 00:00:00 2001 From: "T. Schreiber" Date: Fri, 6 Dec 2019 15:18:04 +0000 Subject: [PATCH 10/12] pep8 issues --- otcextensions/sdk/nat/v2/_proxy.py | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/otcextensions/sdk/nat/v2/_proxy.py b/otcextensions/sdk/nat/v2/_proxy.py index dbb9c7436..4df1a1a06 100644 --- a/otcextensions/sdk/nat/v2/_proxy.py +++ b/otcextensions/sdk/nat/v2/_proxy.py @@ -29,11 +29,7 @@ def create_gateway(self, **attrs): """ return self._create(_gateway.Gateway, **attrs) -<<<<<<< Updated upstream - def delete_gateway(self, id): -======= def delete_gateway(self, gateway, ignore_missing=True): ->>>>>>> Stashed changes """Delete a gateway :param gateway: key id or an instance of @@ -47,12 +43,8 @@ def delete_gateway(self, gateway, ignore_missing=True): :returns: Gateway been deleted :rtype: :class:`~otcextensions.sdk.nat.v2.gateway.Gateway` """ -<<<<<<< Updated upstream - return self._delete(_gateway.Gateway, id=id) -======= return self._delete(_gateway.Gateway, gateway, ignore_missing=ignore_missing) ->>>>>>> Stashed changes def gateways(self, **query): """Return a generator of gateways @@ -100,11 +92,7 @@ def create_snat_rule(self, **attrs): """ return self._create(_snat.Snat, **attrs) -<<<<<<< Updated upstream - def delete_snat_rule(self, id): -======= def delete_snat_rule(self, snat, ignore_missing=True): ->>>>>>> Stashed changes """Delete a SNAT rule :param bool ignore_missing: When set to ``False`` @@ -116,11 +104,7 @@ def delete_snat_rule(self, snat, ignore_missing=True): :returns: SNAT rule been deleted :rtype: :class:`~otcextensions.sdk.nat.v2.snat.Snat` """ -<<<<<<< Updated upstream - return self._delete(_snat.Snat, id=id) -======= return self._delete(_snat.Snat, snat, ignore_missing=ignore_missing) ->>>>>>> Stashed changes def get_snat_rule(self, snat_rule): """Get a single SNAT rule @@ -154,11 +138,7 @@ def create_dnat_rule(self, **attrs): """ return self._create(_dnat.Dnat, **attrs) -<<<<<<< Updated upstream - def delete_dnat_rule(self, id): -======= def delete_dnat_rule(self, dnat, ignore_missing=True): ->>>>>>> Stashed changes """Delete a DNAT rule :param dict attrs: Keyword arguments which will be used to delete @@ -172,11 +152,7 @@ def delete_dnat_rule(self, dnat, ignore_missing=True): :returns: DNAT rule been deleted :rtype: :class:`~otcextensions.sdk.nat.v2.dnat.Dnat` """ -<<<<<<< Updated upstream - return self._delete(_dnat.Dnat, id=id) -======= return self._delete(_dnat.Dnat, dnat, ignore_missing=ignore_missing) ->>>>>>> Stashed changes def get_dnat_rule(self, dnat_rule): """Get a single DNAT rule From 9f2e1b21e9a0369f56d9bf68532f0665b5a6f457 Mon Sep 17 00:00:00 2001 From: "T. Schreiber" Date: Fri, 6 Dec 2019 15:34:18 +0000 Subject: [PATCH 11/12] test_proxy.py added for NAT --- .../tests/unit/sdk/nat/v2/test_proxy.py | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/otcextensions/tests/unit/sdk/nat/v2/test_proxy.py b/otcextensions/tests/unit/sdk/nat/v2/test_proxy.py index e69de29bb..5d5ac33f5 100644 --- a/otcextensions/tests/unit/sdk/nat/v2/test_proxy.py +++ b/otcextensions/tests/unit/sdk/nat/v2/test_proxy.py @@ -0,0 +1,93 @@ +<<<<<<< Updated upstream +======= +# 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. + +# 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 otcextensions.sdk.nat.v2 import _proxy +from otcextensions.sdk.nat.v2 import snat +from otcextensions.sdk.nat.v2 import dnat +from otcextensions.sdk.nat.v2 import gateway + +from openstack.tests.unit import test_proxy_base + + +class TestNatProxy(test_proxy_base.TestProxyBase): + def setUp(self): + super(TestNatProxy, self).setUp() + self.proxy = _proxy.Proxy(self.session) + + +class TestNatGateway(TestNatProxy): + def test_gateway_create(self): + self.verify_create(self.proxy.create_gateway, gateway.Gateway, + method_kwargs={'name': 'id'}, + expected_kwargs={'name': 'id'}) + + def test_gateway_delete(self): + self.verify_delete(self.proxy.delete_gateway, + gateway.Gateway, True) + + def test_gateway_get(self): + self.verify_get(self.proxy.get_gateway, gateway.Gateway) + + def test_gateways(self): + self.verify_list(self.proxy.gateways, gateway.Gateway) + + def test_gateway_update(self): + self.verify_update(self.proxy.update_gateway, gateway.Gateway) + + +class TestNatSnatRule(TestNatProxy): + def test_snat_rule_create(self): + self.verify_create(self.proxy.create_snat_rule, snat.Snat, + method_kwargs={'name': 'id'}, + expected_kwargs={'name': 'id'}) + + def test_snat_rule_delete(self): + self.verify_delete(self.proxy.delete_snat_rule, + snat.Snat, True) + + def test_snat_rule_get(self): + self.verify_get(self.proxy.get_snat_rule, snat.Snat) + + def test_snat_rules(self): + self.verify_list(self.proxy.snat_rules, snat.Snat) + + +class TestNatDnatRule(TestNatProxy): + def test_dnat_rule_create(self): + self.verify_create(self.proxy.create_dnat_rule, dnat.Dnat, + method_kwargs={'name': 'id'}, + expected_kwargs={'name': 'id'}) + + def test_dnat_rule_delete(self): + self.verify_delete(self.proxy.delete_dnat_rule, + dnat.Dnat, True) + + def test_dnat_rule_get(self): + self.verify_get(self.proxy.get_dnat_rule, dnat.Dnat) +# move + def test_dnat_rules(self): + self.verify_list(self.proxy.dnat_rules, dnat.Dnat) +>>>>>>> Stashed changes From a8d985cd5244dd264ffece8d44dccc87f47f789a Mon Sep 17 00:00:00 2001 From: "T. Schreiber" Date: Fri, 6 Dec 2019 15:36:04 +0000 Subject: [PATCH 12/12] stash status changed and proxy test added --- otcextensions/tests/unit/sdk/nat/v2/test_proxy.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/otcextensions/tests/unit/sdk/nat/v2/test_proxy.py b/otcextensions/tests/unit/sdk/nat/v2/test_proxy.py index 5d5ac33f5..9f5140483 100644 --- a/otcextensions/tests/unit/sdk/nat/v2/test_proxy.py +++ b/otcextensions/tests/unit/sdk/nat/v2/test_proxy.py @@ -1,5 +1,3 @@ -<<<<<<< Updated upstream -======= # 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 @@ -87,7 +85,6 @@ def test_dnat_rule_delete(self): def test_dnat_rule_get(self): self.verify_get(self.proxy.get_dnat_rule, dnat.Dnat) -# move + def test_dnat_rules(self): self.verify_list(self.proxy.dnat_rules, dnat.Dnat) ->>>>>>> Stashed changes