Permalink
Browse files

Add support for network spaces

Add extra-bindings for public, internal and admin network spaces.

Change-Id: I7c3ec5a7a1b6f6c7e1cf26146360f1af1d9eaf3c
  • Loading branch information...
1 parent 9be4712 commit 665c34bca503edf80c0a5c108b2cf335ec48bcb1 @javacruft committed Mar 21, 2016
View
@@ -1,4 +1,4 @@
-branch: lp:charm-helpers
+branch: lp:~james-page/charm-helpers/network-spaces-api-endpoints
destination: hooks/charmhelpers
include:
- core
@@ -18,6 +18,7 @@
config,
unit_get,
service_name,
+ network_get_primary_address,
)
from charmhelpers.contrib.network.ip import (
get_address_in_network,
@@ -33,16 +34,19 @@
ADDRESS_MAP = {
PUBLIC: {
+ 'binding': 'public',
'config': 'os-public-network',
'fallback': 'public-address',
'override': 'os-public-hostname',
},
INTERNAL: {
+ 'binding': 'internal',
'config': 'os-internal-network',
'fallback': 'private-address',
'override': 'os-internal-hostname',
},
ADMIN: {
+ 'binding': 'admin',
'config': 'os-admin-network',
'fallback': 'private-address',
'override': 'os-admin-hostname',
@@ -110,7 +114,7 @@ def resolve_address(endpoint_type=PUBLIC):
correct network. If clustered with no nets defined, return primary vip.
If not clustered, return unit address ensuring address is on configured net
- split if one is configured.
+ split if one is configured, or a Juju 2.0 extra-binding has been used.
:param endpoint_type: Network endpoing type
"""
@@ -125,8 +129,16 @@ def resolve_address(endpoint_type=PUBLIC):
net_type = ADDRESS_MAP[endpoint_type]['config']
net_addr = config(net_type)
net_fallback = ADDRESS_MAP[endpoint_type]['fallback']
+ binding = ADDRESS_MAP[endpoint_type]['binding']
clustered = is_clustered()
+
+ if config('prefer-ipv6'):
+ fallback_addr = get_ipv6_addr(exc_list=vips)[0]
+ else:
+ fallback_addr = unit_get(net_fallback)
+
if clustered:
+ # TODO: needs to deal with extra-bindings as well
if not net_addr:
# If no net-splits defined, we expect a single vip
resolved_address = vips[0]
@@ -136,12 +148,15 @@ def resolve_address(endpoint_type=PUBLIC):
resolved_address = vip
break
else:
- if config('prefer-ipv6'):
- fallback_addr = get_ipv6_addr(exc_list=vips)[0]
+ if net_addr:
+ resolved_address = get_address_in_network(net_addr, fallback_addr)
else:
- fallback_addr = unit_get(net_fallback)
-
- resolved_address = get_address_in_network(net_addr, fallback_addr)
+ # NOTE: only try to use extra bindings if legacy network
+ # configuration is not in use
+ try:
+ resolved_address = network_get_primary_address(binding)
+ except NotImplementedError:
+ resolved_address = fallback_addr
if resolved_address is None:
raise ValueError("Unable to resolve a suitable IP address based on "
@@ -1,20 +1,12 @@
{% if auth_host -%}
-{% if api_version == '3' -%}
[keystone_authtoken]
-auth_url = {{ service_protocol }}://{{ service_host }}:{{ service_port }}
+auth_uri = {{ service_protocol }}://{{ service_host }}:{{ service_port }}
+auth_url = {{ auth_protocol }}://{{ auth_host }}:{{ auth_port }}
+auth_plugin = password
+project_domain_id = default
+user_domain_id = default
project_name = {{ admin_tenant_name }}
username = {{ admin_user }}
password = {{ admin_password }}
-project_domain_name = default
-user_domain_name = default
-auth_plugin = password
-{% else -%}
-[keystone_authtoken]
-identity_uri = {{ auth_protocol }}://{{ auth_host }}:{{ auth_port }}/{{ auth_admin_prefix }}
-auth_uri = {{ service_protocol }}://{{ service_host }}:{{ service_port }}/{{ service_admin_prefix }}
-admin_tenant_name = {{ admin_tenant_name }}
-admin_user = {{ admin_user }}
-admin_password = {{ admin_password }}
signing_dir = {{ signing_dir }}
{% endif -%}
-{% endif -%}
@@ -0,0 +1,10 @@
+{% if auth_host -%}
+[keystone_authtoken]
+# Juno specific config (Bug #1557223)
+auth_uri = {{ service_protocol }}://{{ service_host }}:{{ service_port }}/{{ service_admin_prefix }}
+identity_uri = {{ auth_protocol }}://{{ auth_host }}:{{ auth_port }}
+admin_tenant_name = {{ admin_tenant_name }}
+admin_user = {{ admin_user }}
+admin_password = {{ admin_password }}
+signing_dir = {{ signing_dir }}
+{% endif -%}
@@ -1007,3 +1007,16 @@ def network_get_primary_address(binding):
'''
cmd = ['network-get', '--primary-address', binding]
return subprocess.check_output(cmd).strip()
+
+
+@translate_exc(from_exc=OSError, to_exc=NotImplementedError)
+def network_get(binding):
+ '''
+ Retrieve all network information for a named binding
+
+ :param binding: string. The name of a relation of extra-binding
+ :return: dict. Key value pairs of network information
+ :raise: NotImplementedError if run on Juju < 2.0
+ '''
+ cmd = ['network-get', binding]
+ return json.loads(subprocess.check_output(cmd).decode('UTF-8'))
View
@@ -14,6 +14,10 @@ description: |
This charm provides the OpenStack Neutron API service.
tags:
- openstack
+extra-bindings:
+ public:
+ admin:
+ internal:
provides:
nrpe-external-master:
interface: nrpe-external-master
@@ -782,15 +782,20 @@ def get_uuid_epoch_stamp(self):
# amulet juju action helpers:
def run_action(self, unit_sentry, action,
- _check_output=subprocess.check_output):
+ _check_output=subprocess.check_output,
+ params=None):
"""Run the named action on a given unit sentry.
+ params a dict of parameters to use
_check_output parameter is used for dependency injection.
@return action_id.
"""
unit_id = unit_sentry.info["unit_name"]
command = ["juju", "action", "do", "--format=json", unit_id, action]
+ if params is not None:
+ for key, value in params.iteritems():
+ command.append("{}={}".format(key, value))
self.log.info("Running command: %s\n" % " ".join(command))
output = _check_output(command, universal_newlines=True)
data = json.loads(output)

0 comments on commit 665c34b

Please sign in to comment.