Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/cli/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ documentation of these services:
modelarts
nat
obs
privatenat
rds_v3
sdrs
smn
Expand Down
19 changes: 19 additions & 0 deletions doc/source/cli/privatenat.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Private Network Address Translation (Private NAT)
=================================================

The Private NAT client is the command-line interface (CLI) for
the Private NAT API.

For help on a specific `privatenat` command, enter:

.. code-block:: console
$ openstack privatenat help SUBCOMMAND
.. _private_gateway:

Private NAT Gateway Operations
------------------------------

.. autoprogram-cliff:: openstack.privatenat.v3
:command: privatenat gateway *
1 change: 1 addition & 0 deletions doc/source/sdk/proxies/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Service Proxies
MapReduce Service (MRS) <mrs>
Modelarts Service (ModelArts) <modelarts>
Network Address Translation (NAT) <nat>
Private Network Address Translation (Private NAT) <privatenat>
Object Block Storage (OBS) <obs>
Relational Database Service RDS V1 (RDSv1) <rds_v1>
Relational Database Service RDS V3 (RDS) <rds_v3>
Expand Down
19 changes: 19 additions & 0 deletions doc/source/sdk/proxies/privatenat.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Private NAT API
===============

.. automodule:: otcextensions.sdk.natv3.v3._proxy

The Private NAT high-level interface
------------------------------------

The private NAT high-level interface is available through the ``natv3``
member of a :class:`~openstack.connection.Connection` object. The
``natv3`` member will only be added if the
``otcextensions.sdk.register_otc_extensions(conn)`` method is called.

Private NAT Gateway Operations
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. autoclass:: otcextensions.sdk.natv3.v3._proxy.Proxy
:noindex:
:members: private_nat_gateways
1 change: 1 addition & 0 deletions doc/source/sdk/resources/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Open Telekom Cloud Resources
MapReduce Service (MRS) <mrs/index>
ModelArts Service (MA) <modelarts/index>
Network Address Translation (NAT) <nat/index>
Private Network Address Translation (Private NAT) <privatenat/index>
Object Block Storage (OBS) <obs/index>
Relational Database Service (RDS) <rds/index>
Shared File System Turbo (SFS Turbo) <sfsturbo/index>
Expand Down
7 changes: 7 additions & 0 deletions doc/source/sdk/resources/privatenat/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Private NAT Resources
=====================

.. toctree::
:maxdepth: 1

v3/private_gateway
13 changes: 13 additions & 0 deletions doc/source/sdk/resources/privatenat/v3/private_gateway.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
otcextensions.sdk.natv3.v3.gateway
==================================

.. automodule:: otcextensions.sdk.natv3.v3.gateway

The Private NAT Gateway Class
-----------------------------

The ``PrivateNatGateway`` class inherits from
:class:`~openstack.resource.Resource`.

.. autoclass:: otcextensions.sdk.natv3.v3.gateway.PrivateNatGateway
:members:
23 changes: 23 additions & 0 deletions examples/natv3/list_private_gateways.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env python3
# 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.
"""
List all Private NAT Gateways
"""
import openstack


openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')

for gateway in conn.natv3.private_nat_gateways():
print(gateway)
Empty file.
52 changes: 52 additions & 0 deletions otcextensions/osclient/privatenat/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# 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.
#
import logging

from osc_lib import utils

from otcextensions import sdk
from otcextensions.i18n import _

LOG = logging.getLogger(__name__)

DEFAULT_API_VERSION = '3'
API_VERSION_OPTION = 'os_privatenat_api_version'
API_NAME = "privatenat"
API_VERSIONS = {
"3": "openstack.connection.Connection"
}


def make_client(instance):
"""Returns a private NAT proxy"""
conn = instance.sdk_connection

if getattr(conn, 'natv3', None) is None:
LOG.debug('OTC extensions are not registered. Do that now')
sdk.register_otc_extensions(conn)

LOG.debug('Private NAT client initialized using OpenStack OTC SDK: %s',
conn.natv3)
return conn.natv3


def build_option_parser(parser):
"""Hook to add global options"""
parser.add_argument(
'--os-privatenat-api-version',
metavar='<privatenat-api-version>',
default=utils.env('OS_PRIVATENAT_API_VERSION'),
help=_("Private NAT API version, default=%s "
"(Env: OS_PRIVATENAT_API_VERSION)") % DEFAULT_API_VERSION
)
return parser
Empty file.
153 changes: 153 additions & 0 deletions otcextensions/osclient/privatenat/v3/private_nat_gateway.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
# 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.
#
"""Private NAT Gateway v3 action implementations"""

import logging

from osc_lib import utils
from osc_lib.command import command

from otcextensions.i18n import _


LOG = logging.getLogger(__name__)


class ListPrivateNatGateways(command.Lister):

_description = _("List Private NAT Gateways.")
columns = (
'Id',
'Name',
'Spec',
'Status',
'Project Id',
'Enterprise Project Id',
)

def get_parser(self, prog_name):
parser = super(ListPrivateNatGateways, self).get_parser(prog_name)

parser.add_argument(
'--limit',
metavar='<limit>',
type=int,
help=_("Specifies the number of records displayed on each page."),
)
parser.add_argument(
'--marker',
metavar='<marker>',
help=_("Specifies the start resource ID of pagination query."),
)
parser.add_argument(
'--page-reverse',
action='store_true',
default=False,
help=_("Specifies whether to query resources"
" on the previous page."),
)
parser.add_argument(
'--id',
metavar='<id>',
nargs='+',
help=_("Specifies the private NAT gateway IDs."),
)
parser.add_argument(
'--name',
metavar='<name>',
nargs='+',
help=_("Specifies the private NAT gateway names."),
)
parser.add_argument(
'--description',
metavar='<description>',
nargs='+',
help=_("Provides supplementary information"
" about the private NAT gateway."),
)
parser.add_argument(
'--spec',
metavar='<spec>',
nargs='+',
help=_("Specifies the private NAT gateway specifications. "),
)
parser.add_argument(
'--project-id',
metavar='<project_id>',
nargs='+',
help=_("Specifies the project ID. Repeat for multiple values."),
)
parser.add_argument(
'--status',
metavar='<status>',
nargs='+',
help=_("Specifies the private NAT gateway status."),
)
parser.add_argument(
'--vpc-id',
metavar='<vpc_id>',
nargs='+',
help=_("Specifies the ID of the VPC."),
)
parser.add_argument(
'--virsubnet-id',
metavar='<virsubnet_id>',
nargs='+',
help=_("Specifies the ID of the subnet."),
)
parser.add_argument(
'--enterprise-project-id',
metavar='<enterprise_project_id>',
nargs='+',
help=_("Specifies the enterprise project ID "
"associated with the private NAT gateway."),
)

return parser

def take_action(self, parsed_args):
client = self.app.client_manager.privatenat

attrs = {}
args_list = [
'limit',
'marker',
'page_reverse',
'id',
'name',
'description',
'spec',
'project_id',
'status',
'vpc_id',
'virsubnet_id',
'enterprise_project_id',
]
for arg in args_list:
val = getattr(parsed_args, arg)
if arg == 'page_reverse':
# Only send flag if explicitly requested
if val:
attrs[arg] = val
elif val is not None and val != [] and val != '':
attrs[arg] = val

data = client.private_nat_gateways(**attrs)

return (
self.columns,
(
utils.get_item_properties(s, self.columns)
for s in data
)
)
1 change: 1 addition & 0 deletions otcextensions/sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@
},
'natv3': {
'service_type': 'natv3',
'append_project_id': True,
'endpoint_service_type': 'natv3'
},
'obs': {
Expand Down
11 changes: 11 additions & 0 deletions otcextensions/sdk/natv3/v3/_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from openstack import proxy

from otcextensions.common.utils import extract_url_parts
from otcextensions.sdk.natv3.v3 import gateway as _gateway


class Proxy(proxy.Proxy):
Expand All @@ -20,3 +21,13 @@ class Proxy(proxy.Proxy):

def _extract_name(self, url, service_type=None, project_id=None):
return extract_url_parts(url, project_id)

def private_nat_gateways(self, **query):
"""Return a generator of private NAT gateways.

:param dict query: Optional query parameters to be sent to limit
the resources being returned.

:returns: A generator of private NAT gateway objects.
"""
return self._list(_gateway.PrivateNatGateway, **query)
Loading