-
Notifications
You must be signed in to change notification settings - Fork 29
Add new api for private_nat gateways. Only querying list #632
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
shhovhan
wants to merge
6
commits into
main
Choose a base branch
from
private_gateway_api_list
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+764
−9
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
816abfc
Add new api for private_nat gateways. Only querying list
shhovhan a0c3118
Add documentation and fix lint errors
shhovhan 1f6dec5
Fix tox docs errors
shhovhan 64e1bab
Add tests, fix doc issues, apply review comments
shhovhan ebf36b5
Remove unused data from test
shhovhan 18755f2
Fix test issue
shhovhan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,6 +43,7 @@ documentation of these services: | |
| modelarts | ||
| nat | ||
| obs | ||
| privatenat | ||
| rds_v3 | ||
| sdrs | ||
| smn | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 * |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
13
doc/source/sdk/resources/privatenat/v3/private_gateway.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
153
otcextensions/osclient/privatenat/v3/private_nat_gateway.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| ) | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.