|
| 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