Skip to content

Commit 8d7edef

Browse files
committed
Add new api for private_nat gateways. Only querying list
1 parent 31ccae0 commit 8d7edef

31 files changed

Lines changed: 763 additions & 9 deletions

File tree

doc/source/cli/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ documentation of these services:
4343
modelarts
4444
nat
4545
obs
46+
privatenat
4647
rds_v3
4748
sdrs
4849
smn

doc/source/cli/privatenat.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Private Network Address Translation (Private NAT)
2+
=================================================
3+
4+
The Private NAT client is the command-line interface (CLI) for
5+
the Private NAT API.
6+
7+
For help on a specific `privatenat` command, enter:
8+
9+
.. code-block:: console
10+
11+
$ openstack privatenat help SUBCOMMAND
12+
13+
.. _private_gateway:
14+
15+
Private NAT Gateway Operations
16+
------------------------------
17+
18+
.. autoprogram-cliff:: openstack.privatenat.v3
19+
:command: privatenat gateway *

doc/source/sdk/proxies/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Service Proxies
2929
MapReduce Service (MRS) <mrs>
3030
Modelarts Service (ModelArts) <modelarts>
3131
Network Address Translation (NAT) <nat>
32+
Private Network Address Translation (Private NAT) <privatenat>
3233
Object Block Storage (OBS) <obs>
3334
Relational Database Service RDS V1 (RDSv1) <rds_v1>
3435
Relational Database Service RDS V3 (RDS) <rds_v3>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Private NAT API
2+
===============
3+
4+
.. automodule:: otcextensions.sdk.natv3.v3._proxy
5+
6+
The Private NAT high-level interface
7+
------------------------------------
8+
9+
The private NAT high-level interface is available through the ``natv3``
10+
member of a :class:`~openstack.connection.Connection` object. The
11+
``natv3`` member will only be added if the
12+
``otcextensions.sdk.register_otc_extensions(conn)`` method is called.
13+
14+
Private NAT Gateway Operations
15+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16+
17+
.. autoclass:: otcextensions.sdk.natv3.v3._proxy.Proxy
18+
:noindex:
19+
:members: private_nat_gateways

doc/source/sdk/resources/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Open Telekom Cloud Resources
3030
MapReduce Service (MRS) <mrs/index>
3131
ModelArts Service (MA) <modelarts/index>
3232
Network Address Translation (NAT) <nat/index>
33+
Private Network Address Translation (Private NAT) <privatenat/index>
3334
Object Block Storage (OBS) <obs/index>
3435
Relational Database Service (RDS) <rds/index>
3536
Shared File System Turbo (SFS Turbo) <sfsturbo/index>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Private NAT Resources
2+
=====================
3+
4+
.. toctree::
5+
:maxdepth: 1
6+
7+
v3/private_gateway
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
otcextensions.sdk.natv3.v3.gateway
2+
==================================
3+
4+
.. automodule:: otcextensions.sdk.natv3.v3.gateway
5+
6+
The Private NAT Gateway Class
7+
-----------------------------
8+
9+
The ``PrivateNatGateway`` class inherits from
10+
:class:`~openstack.resource.Resource`.
11+
12+
.. autoclass:: otcextensions.sdk.natv3.v3.gateway.PrivateNatGateway
13+
:members:
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env python3
2+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
3+
# not use this file except in compliance with the License. You may obtain
4+
# a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11+
# License for the specific language governing permissions and limitations
12+
# under the License.
13+
"""
14+
List all Private NAT Gateways
15+
"""
16+
import openstack
17+
18+
19+
openstack.enable_logging(True)
20+
conn = openstack.connect(cloud='otc')
21+
22+
for gateway in conn.natv3.private_nat_gateways():
23+
print(gateway)

otcextensions/osclient/privatenat/__init__.py

Whitespace-only changes.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
#
13+
import logging
14+
15+
from osc_lib import utils
16+
17+
from otcextensions import sdk
18+
from otcextensions.i18n import _
19+
20+
LOG = logging.getLogger(__name__)
21+
22+
DEFAULT_API_VERSION = '3'
23+
API_VERSION_OPTION = 'os_privatenat_api_version'
24+
API_NAME = "privatenat"
25+
API_VERSIONS = {
26+
"3": "openstack.connection.Connection"
27+
}
28+
29+
30+
def make_client(instance):
31+
"""Returns a private NAT proxy"""
32+
conn = instance.sdk_connection
33+
34+
if getattr(conn, 'natv3', None) is None:
35+
LOG.debug('OTC extensions are not registered. Do that now')
36+
sdk.register_otc_extensions(conn)
37+
38+
LOG.debug('Private NAT client initialized using OpenStack OTC SDK: %s',
39+
conn.natv3)
40+
return conn.natv3
41+
42+
43+
def build_option_parser(parser):
44+
"""Hook to add global options"""
45+
parser.add_argument(
46+
'--os-privatenat-api-version',
47+
metavar='<privatenat-api-version>',
48+
default=utils.env('OS_PRIVATENAT_API_VERSION'),
49+
help=_("Private NAT API version, default=%s "
50+
"(Env: OS_PRIVATENAT_API_VERSION)") % DEFAULT_API_VERSION
51+
)
52+
return parser

0 commit comments

Comments
 (0)