Skip to content
3 changes: 3 additions & 0 deletions otcextensions/sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@
'service_type': 'kms',
'append_project_id': True,
},
'nat': {
'service_type': 'nat'
},
'obs': {
'service_type': 'obs',
'require_ak': True,
Expand Down
Empty file.
22 changes: 22 additions & 0 deletions otcextensions/sdk/nat/nat_service.py
Original file line number Diff line number Diff line change
@@ -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
}
Empty file.
178 changes: 178 additions & 0 deletions otcextensions/sdk/nat/v2/_proxy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
# 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 gateway as _gateway
from otcextensions.sdk.nat.v2 import snat as _snat
from otcextensions.sdk.nat.v2 import dnat as _dnat

from openstack import proxy


class Proxy(proxy.Proxy):

skip_discovery = True

# ======== 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.gateway.Gateway`
"""
return self._create(_gateway.Gateway, **attrs)

def delete_gateway(self, gateway, ignore_missing=True):
"""Delete a 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`
"""
return self._delete(_gateway.Gateway, gateway,
ignore_missing=ignore_missing)

def gateways(self, **query):
"""Return a generator of gateways

: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, **query)

def get_gateway(self, gateway):
"""Get a single gateway

: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.gateway.Gateway`
:raises: :class:`~openstack.exceptions.ResourceNotFound`
when no resource can be found.
"""
return self._get(_gateway.Gateway, gateway)

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.
: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 ========
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, snat, ignore_missing=True):
"""Delete a SNAT rule

: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`
"""
return self._delete(_snat.Snat, snat, ignore_missing=ignore_missing)

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, **query):
"""Return a generator of SNAT rules

:param dict query: Optional query parameters to be sent to limit
the resources being returned.
:returns: A generator of Snat rule objects
:rtype: :class:`~otcextensions.sdk.nat.v2.snat.Snat`
"""
return self._list(_snat.Snat, **query)

# ======== 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, dnat, ignore_missing=True):
"""Delete a DNAT rule

: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`
"""
return self._delete(_dnat.Dnat, dnat, ignore_missing=ignore_missing)

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, **query):
"""Return a generator of DNAT rules

: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, **query)
69 changes: 69 additions & 0 deletions otcextensions/sdk/nat/v2/dnat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# 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'
resource_key = 'dnat_rule'
base_path = '/dnat_rules'

# capabilities
allow_create = True
allow_fetch = True
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',
'project_id'
)

# Properties
#: 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', type=int)
#: 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.
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
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.
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')
61 changes: 61 additions & 0 deletions otcextensions/sdk/nat/v2/gateway.py
Original file line number Diff line number Diff line change
@@ -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 import resource


class Gateway(resource.Resource):
resources_key = 'nat_gateways'
resource_key = 'nat_gateway'
base_path = '/nat_gateways'

# capabilities
allow_create = True
allow_fetch = True
allow_commit = True
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', 'project_id'
)

# Properties
#: 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 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')
#: 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.
#: *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 status
status = resource.Body('status')
Loading