~billy-olsen/charms/trusty/nova-cloud-controller/public-endpoint-host

« back to all changes in this revision

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

  • Committer: Billy Olsen
  • Date: 2015-06-04 23:30:46 UTC
  • Revision ID: billy.olsen@canonical.com-20150604233046-d0u25emehp7hqahq
c-h sync

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
from charmhelpers.core.hookenv import (
18
18
    config,
19
19
    unit_get,
 
20
    service_name,
20
21
)
21
22
from charmhelpers.contrib.network.ip import (
22
23
    get_address_in_network,
82
83
    return scheme
83
84
 
84
85
 
 
86
def _get_address_override(endpoint_type=PUBLIC):
 
87
    """Returns any address overrides that the user has defined based on the
 
88
    endpoint type.
 
89
 
 
90
    Note: this function allows for the service name to be inserted into the
 
91
    address if the user specifies {service_name}.somehost.org.
 
92
 
 
93
    :param endpoint_type: the type of endpoint to retrieve the override
 
94
                          value for.
 
95
    :returns: any endpoint address or hostname that the user has overridden
 
96
              or None if an override is not present.
 
97
    """
 
98
    override_key = ADDRESS_MAP[endpoint_type]['override']
 
99
    addr_override = config(override_key)
 
100
    if not addr_override:
 
101
        return None
 
102
    else:
 
103
        return addr_override.format(service_name=service_name())
 
104
 
 
105
 
85
106
def resolve_address(endpoint_type=PUBLIC):
86
107
    """Return unit address depending on net config.
87
108
 
93
114
 
94
115
    :param endpoint_type: Network endpoing type
95
116
    """
96
 
    resolved_address = None
97
 
 
98
 
    # Allow the user to override the address which is used. This is
99
 
    # useful for proxy services or exposing a public endpoint url, etc.
100
 
    override_key = ADDRESS_MAP[endpoint_type]['override']
101
 
    addr_override = config(override_key)
102
 
    if addr_override:
103
 
        return addr_override
 
117
    resolved_address = _get_address_override(endpoint_type)
 
118
    if resolved_address:
 
119
        return resolved_address
104
120
 
105
121
    vips = config('vip')
106
122
    if vips: