Skip to content

Commit ee64c2f

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add --os-endpoint-type cli optional argument"
2 parents d80deab + 5521e4c commit ee64c2f

15 files changed

Lines changed: 97 additions & 5 deletions

File tree

doc/source/configuration.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ The keys match the :program:`openstack` global options but without the
7878
username: openstack
7979
password: xyzpdq!lazydog
8080
region_name: DFW,ORD,IAD
81+
endpoint_type: internal
8182

8283
In the above example, the ``auth_url`` for the ``rackspace`` cloud is taken
8384
from :file:`clouds-public.yaml` (see below).
@@ -96,6 +97,7 @@ to the following options if the ``rackspace`` entry in :file:`clouds-public.yaml
9697
--os-username openstack
9798
--os-password xyzpdq!lazydog
9899
--os-region-name DFW
100+
--os-endpoint-type internal
99101

100102
and can be selected on the command line::
101103

@@ -105,13 +107,17 @@ Note that multiple regions are listed in the ``rackspace`` entry. An otherwise
105107
identical configuration is created for each region. If ``-os-region-name`` is not
106108
specified on the command line, the first region in the list is used by default.
107109

110+
The selection of ``endpoint_type`` (as seen above in the ``rackspace`` entry)
111+
is optional. For this configuration to work, every service for this cloud
112+
instance must already be configured to support this type of endpoint.
113+
108114
clouds-public.yaml
109115
~~~~~~~~~~~~~~~~~~
110116

111117
:file:`clouds-public.yaml` is a configuration file that is intended to contain
112118
public information about clouds that are common across a large number of users.
113119
The idea is that :file:`clouds-public.yaml` could easily be shared among users
114-
to simplify public could configuration.
120+
to simplify public cloud configuration.
115121

116122
Similar to :file:`clouds.yaml`, OpenStackClient looks for
117123
:file:`clouds-public.yaml` in the following locations:

doc/source/man/openstack.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ OPTIONS
120120
:option:`--os-XXXX-api-version` <XXXX-api-version>
121121
Additional API version options will be available depending on the installed API libraries.
122122

123+
:option:`--os-endpoint-type` <endpoint-type>
124+
Endpoint type. Valid options are `public`, `admin` and `internal`.
123125

124126
COMMANDS
125127
========
@@ -344,6 +346,9 @@ The following environment variables can be set to alter the behaviour of :progra
344346
:envvar:`OS_XXXX_API_VERSION`
345347
Additional API version options will be available depending on the installed API libraries.
346348

349+
:envvar:`OS_ENDPOINT_TYPE`
350+
Endpoint type. Valid options are `public`, `admin` and `internal`.
351+
347352

348353
BUGS
349354
====

openstackclient/common/clientmanager.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def __init__(
8686
self._pw_callback = pw_func
8787
self._url = self._cli_options.auth.get('url', None)
8888
self._region_name = self._cli_options.region_name
89+
self._endpoint_type = self._cli_options.endpoint_type
8990

9091
self.timing = self._cli_options.timing
9192

@@ -183,18 +184,23 @@ def auth_ref(self):
183184
self._auth_ref = self.auth.get_auth_ref(self.session)
184185
return self._auth_ref
185186

186-
def get_endpoint_for_service_type(self, service_type, region_name=None):
187+
def get_endpoint_for_service_type(self, service_type, region_name=None,
188+
endpoint_type='public'):
187189
"""Return the endpoint URL for the service type."""
190+
if not endpoint_type:
191+
endpoint_type = 'public'
188192
# See if we are using password flow auth, i.e. we have a
189193
# service catalog to select endpoints from
190194
if self.auth_ref:
191195
endpoint = self.auth_ref.service_catalog.url_for(
192196
service_type=service_type,
193197
region_name=region_name,
198+
endpoint_type=endpoint_type,
194199
)
195200
else:
196201
# Get the passed endpoint directly from the auth plugin
197-
endpoint = self.auth.get_endpoint(self.session)
202+
endpoint = self.auth.get_endpoint(self.session,
203+
interface=endpoint_type)
198204
return endpoint
199205

200206

openstackclient/common/utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,3 +368,11 @@ def read_blob_file_contents(blob_file):
368368
except IOError:
369369
msg = "Error occurred trying to read from file %s"
370370
raise exceptions.CommandError(msg % blob_file)
371+
372+
373+
def build_kwargs_dict(arg_name, value):
374+
"""Return a dictionary containing `arg_name` if `value` is set."""
375+
kwargs = {}
376+
if value:
377+
kwargs[arg_name] = value
378+
return kwargs

openstackclient/compute/client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,17 @@ def make_client(instance):
4848

4949
extensions = [extension.Extension('list_extensions', list_extensions)]
5050

51+
# Remember endpoint_type only if it is set
52+
kwargs = utils.build_kwargs_dict('endpoint_type',
53+
instance._endpoint_type)
54+
5155
client = compute_client(
5256
session=instance.session,
5357
extensions=extensions,
5458
http_log_debug=http_log_debug,
5559
timings=instance.timing,
5660
region_name=instance._region_name,
61+
**kwargs
5762
)
5863

5964
return client

openstackclient/identity/client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,15 @@ def make_client(instance):
4646
API_VERSIONS)
4747
LOG.debug('Instantiating identity client: %s', identity_client)
4848

49+
# Remember interface only if endpoint_type is set
50+
kwargs = utils.build_kwargs_dict('interface',
51+
instance._endpoint_type)
52+
4953
client = identity_client(
5054
session=instance.session,
5155
region_name=instance._region_name,
52-
)
56+
**kwargs
57+
)
5358

5459
return client
5560

openstackclient/image/client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def make_client(instance):
4646
endpoint = instance.get_endpoint_for_service_type(
4747
API_NAME,
4848
region_name=instance._region_name,
49+
endpoint_type=instance._endpoint_type,
4950
)
5051

5152
client = image_client(
@@ -68,6 +69,7 @@ def make_client(instance):
6869
endpoint=instance.get_endpoint_for_service_type(
6970
IMAGE_API_TYPE,
7071
region_name=instance._region_name,
72+
endpoint_type=instance._endpoint_type,
7173
)
7274
)
7375

openstackclient/network/client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,17 @@ def make_client(instance):
4747
endpoint = instance.get_endpoint_for_service_type(
4848
API_NAME,
4949
region_name=instance._region_name,
50+
endpoint_type=instance._endpoint_type,
5051
)
5152

53+
# Remember endpoint_type only if it is set
54+
kwargs = utils.build_kwargs_dict('endpoint_type',
55+
instance._endpoint_type)
56+
5257
client = network_client(
5358
session=instance.session,
5459
region_name=instance._region_name,
60+
**kwargs
5561
)
5662

5763
network_api = utils.get_client_class(

openstackclient/object/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def make_client(instance):
3636
endpoint = instance.get_endpoint_for_service_type(
3737
'object-store',
3838
region_name=instance._region_name,
39+
endpoint_type=instance._endpoint_type,
3940
)
4041

4142
client = object_store_v1.APIv1(

openstackclient/shell.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,15 @@ def build_option_parser(self, description, version):
208208
help='Default domain ID, default=' +
209209
DEFAULT_DOMAIN +
210210
' (Env: OS_DEFAULT_DOMAIN)')
211+
parser.add_argument(
212+
'--os-endpoint-type',
213+
metavar='<endpoint-type>',
214+
dest='endpoint_type',
215+
choices=['admin', 'public', 'internal'],
216+
default=utils.env('OS_ENDPOINT_TYPE'),
217+
help='Select an endpoint type.'
218+
' Valid endpoint types: [admin, public, internal].'
219+
' (Env: OS_ENDPOINT_TYPE)')
211220
parser.add_argument(
212221
'--timing',
213222
default=False,
@@ -254,7 +263,10 @@ def initialize_app(self, argv):
254263
self.options.project_name = tenant_name
255264

256265
# Do configuration file handling
257-
cc = cloud_config.OpenStackConfig()
266+
# Ignore the default value of endpoint_type. Only if it is set later
267+
# will it be used.
268+
cc = cloud_config.OpenStackConfig(
269+
override_defaults={'endpoint_type': None, })
258270
self.log.debug("defaults: %s", cc.defaults)
259271

260272
self.cloud = cc.get_one_cloud(

0 commit comments

Comments
 (0)