~james-page/charms/trusty/glance/lp1456379

« back to all changes in this revision

Viewing changes to hooks/charmhelpers/contrib/openstack/ip.py

  • Committer: Edward Hope-Morley
  • Date: 2015-02-24 11:03:59 UTC
  • Revision ID: edward.hope-morley@canonical.com-20150224110359-jj3g2d044lk8uy69
[trivial] charmhelpers sync

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
)
27
27
from charmhelpers.contrib.hahelpers.cluster import is_clustered
28
28
 
 
29
from functools import partial
 
30
 
29
31
PUBLIC = 'public'
30
32
INTERNAL = 'int'
31
33
ADMIN = 'admin'
107
109
                         "clustered=%s)" % (net_type, clustered))
108
110
 
109
111
    return resolved_address
 
112
 
 
113
 
 
114
def endpoint_url(configs, url_template, port, endpoint_type=PUBLIC,
 
115
                 override=None):
 
116
    """Returns the correct endpoint URL to advertise to Keystone.
 
117
 
 
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).
 
122
 
 
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).
 
132
    """
 
133
    if override:
 
134
        # Return any user-defined overrides for the keystone endpoint URL.
 
135
        user_value = config(override)
 
136
        if user_value:
 
137
            return user_value.strip()
 
138
 
 
139
    return url_template % (canonical_url(configs, endpoint_type), port)
 
140
 
 
141
 
 
142
public_endpoint = partial(endpoint_url, endpoint_type=PUBLIC)
 
143
 
 
144
internal_endpoint = partial(endpoint_url, endpoint_type=INTERNAL)
 
145
 
 
146
admin_endpoint = partial(endpoint_url, endpoint_type=ADMIN)