37
36
'config': 'os-public-network',
38
'fallback': 'public-address'
37
'fallback': 'public-address',
38
'override': 'os-public-hostname',
41
41
'config': 'os-internal-network',
42
'fallback': 'private-address'
42
'fallback': 'private-address',
43
'override': 'os-internal-hostname',
45
46
'config': 'os-admin-network',
46
'fallback': 'private-address'
47
'fallback': 'private-address',
48
'override': 'os-admin-hostname',
57
59
:param endpoint_type: str endpoint type to resolve.
58
60
:param returns: str base URL for services on the current service unit.
61
if 'https' in configs.complete_contexts():
62
scheme = _get_scheme(configs)
63
64
address = resolve_address(endpoint_type)
64
65
if is_ipv6(address):
65
66
address = "[{}]".format(address)
66
68
return '%s://%s' % (scheme, address)
71
def _get_scheme(configs):
72
"""Returns the scheme to use for the url (either http or https)
73
depending upon whether https is in the configs value.
75
:param configs: OSTemplateRenderer config templating object to inspect
76
for a complete https context.
77
:returns: either 'http' or 'https' depending on whether https is
78
configured within the configs context.
81
if configs and 'https' in configs.complete_contexts():
86
def _get_address_override(endpoint_type=PUBLIC):
87
"""Returns any address overrides that the user has defined based on the
90
Note: this function allows for the service name to be inserted into the
91
address if the user specifies {service_name}.somehost.org.
93
:param endpoint_type: the type of endpoint to retrieve the override
95
:returns: any endpoint address or hostname that the user has overridden
96
or None if an override is not present.
98
override_key = ADDRESS_MAP[endpoint_type]['override']
99
addr_override = config(override_key)
100
if not addr_override:
103
return addr_override.format(service_name=service_name())
69
106
def resolve_address(endpoint_type=PUBLIC):
70
107
"""Return unit address depending on net config.
109
149
"clustered=%s)" % (net_type, clustered))
111
151
return resolved_address
114
def endpoint_url(configs, url_template, port, endpoint_type=PUBLIC,
116
"""Returns the correct endpoint URL to advertise to Keystone.
118
This method provides the correct endpoint URL which should be advertised to
119
the keystone charm for endpoint creation. This method allows for the url to
120
be overridden to force a keystone endpoint to have specific URL for any of
121
the defined scopes (admin, internal, public).
123
:param configs: OSTemplateRenderer config templating object to inspect
124
for a complete https context.
125
:param url_template: str format string for creating the url template. Only
126
two values will be passed - the scheme+hostname
127
returned by the canonical_url and the port.
128
:param endpoint_type: str endpoint type to resolve.
129
:param override: str the name of the config option which overrides the
130
endpoint URL defined by the charm itself. None will
131
disable any overrides (default).
134
# Return any user-defined overrides for the keystone endpoint URL.
135
user_value = config(override)
137
return user_value.strip()
139
return url_template % (canonical_url(configs, endpoint_type), port)
142
public_endpoint = partial(endpoint_url, endpoint_type=PUBLIC)
144
internal_endpoint = partial(endpoint_url, endpoint_type=INTERNAL)
146
admin_endpoint = partial(endpoint_url, endpoint_type=ADMIN)