Add missing stuff
This commit is contained in:
parent
61cc06c0dd
commit
74ef1f103a
71
hooks/charmhelpers/contrib/openstack/ip.py
Normal file
71
hooks/charmhelpers/contrib/openstack/ip.py
Normal file
@ -0,0 +1,71 @@
|
||||
from charmhelpers.core.hookenv import (
|
||||
config,
|
||||
unit_get,
|
||||
)
|
||||
|
||||
from charmhelpers.contrib.network.ip import (
|
||||
get_address_in_network,
|
||||
is_address_in_network,
|
||||
)
|
||||
|
||||
from charmhelpers.contrib.hahelpers.cluster import is_clustered
|
||||
|
||||
PUBLIC = 'public'
|
||||
INTERNAL = 'int'
|
||||
ADMIN = 'admin'
|
||||
|
||||
_address_map = {
|
||||
PUBLIC: {
|
||||
'config': 'os-public-network',
|
||||
'fallback': 'public-address'
|
||||
},
|
||||
INTERNAL: {
|
||||
'config': 'os-internal-network',
|
||||
'fallback': 'private-address'
|
||||
},
|
||||
ADMIN: {
|
||||
'config': 'os-admin-network',
|
||||
'fallback': 'private-address'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def canonical_url(configs, endpoint_type=PUBLIC):
|
||||
'''
|
||||
Returns the correct HTTP URL to this host given the state of HTTPS
|
||||
configuration, hacluster and charm configuration.
|
||||
|
||||
:configs OSTemplateRenderer: A config tempating object to inspect for
|
||||
a complete https context.
|
||||
:endpoint_type str: The endpoint type to resolve.
|
||||
|
||||
:returns str: Base URL for services on the current service unit.
|
||||
'''
|
||||
scheme = 'http'
|
||||
if 'https' in configs.complete_contexts():
|
||||
scheme = 'https'
|
||||
return '%s://%s' % (scheme, resolve_address(endpoint_type))
|
||||
|
||||
|
||||
def resolve_address(endpoint_type=PUBLIC):
|
||||
resolved_address = None
|
||||
if is_clustered():
|
||||
if config(_address_map[endpoint_type]['config']) is None:
|
||||
# Assume vip is simple and pass back directly
|
||||
resolved_address = config('vip')
|
||||
else:
|
||||
for vip in config('vip').split():
|
||||
if is_address_in_network(
|
||||
config(_address_map[endpoint_type]['config']),
|
||||
vip):
|
||||
resolved_address = vip
|
||||
else:
|
||||
resolved_address = get_address_in_network(
|
||||
config(_address_map[endpoint_type]['config']),
|
||||
unit_get(_address_map[endpoint_type]['fallback'])
|
||||
)
|
||||
if resolved_address is None:
|
||||
raise ValueError('Unable to resolve a suitable IP address'
|
||||
' based on charm state and configuration')
|
||||
else:
|
||||
return resolved_address
|
1
hooks/cluster-relation-joined
Symbolic link
1
hooks/cluster-relation-joined
Symbolic link
@ -0,0 +1 @@
|
||||
glance_relations.py
|
@ -294,6 +294,15 @@ def config_changed():
|
||||
# configuration
|
||||
[keystone_joined(rid) for rid in relation_ids('identity-service')]
|
||||
[image_service_joined(rid) for rid in relation_ids('image-service')]
|
||||
[cluster_joined(rid) for rid in relation_ids('cluster')]
|
||||
|
||||
|
||||
@hooks.hook('cluster-relation-joined')
|
||||
def cluster_joined(relation_id=None):
|
||||
address = get_address_in_network(config('os-internal-network'),
|
||||
unit_get('private-address'))
|
||||
relation_set(relation_id=relation_id,
|
||||
relation_settings={'private-address': address})
|
||||
|
||||
|
||||
@hooks.hook('cluster-relation-changed')
|
||||
|
Loading…
x
Reference in New Issue
Block a user