Permalink
Browse files

Add support for Juju network spaces

This change adds support for binding ceph to specific networks using
Juju network spaces extra-bindings.  The networks supported are:

  - cluster: the Ceph cluster network used for inter-unit
             communication for re-syncs etc.
  - public:  the Ceph public network used by clients to access
             Ceph MON and OSD services.

This is only supported under Juju 2.0.
  • Loading branch information...
1 parent e80c509 commit f41254a65a0f77a19e1566b51324484cd7ec3576 @javacruft committed Mar 7, 2016
Showing with 90 additions and 12 deletions.
  1. +1 −0 .gitignore
  2. +4 −0 hooks/ceph_hooks.py
  3. +47 −0 hooks/charmhelpers/core/hookenv.py
  4. +28 −4 hooks/utils.py
  5. +3 −0 metadata.yaml
  6. +7 −8 templates/ceph.conf
View
@@ -4,3 +4,4 @@ bin
.testrepository
.tox
*.sw[nop]
+*.pyc
View
@@ -58,6 +58,7 @@
from utils import (
get_networks,
get_public_addr,
+ get_cluster_addr,
assert_charm_supports_ipv6
)
from ceph_broker import (
@@ -116,6 +117,9 @@ def emit_cephconf():
cephcontext['public_addr'] = dynamic_ipv6_address
if not cluster_network:
cephcontext['cluster_addr'] = dynamic_ipv6_address
+ else:
+ cephcontext['public_addr'] = get_public_addr()
+ cephcontext['cluster_addr'] = get_cluster_addr()
# Install ceph.conf as an alternative to support
# co-existence with other charms that write this file
@@ -976,3 +976,50 @@ def _run_atexit():
for callback, args, kwargs in reversed(_atexit):
callback(*args, **kwargs)
del _atexit[:]
+
+
+@translate_exc(from_exc=OSError, to_exc=NotImplementedError)
+def network_get_primary_address(relation_id=None,
+ extra_binding_name=None):
+ """For DEMO only. Juju network-get forcing --primary-address
+ network-get --primary-address currenlty returns a bald string
+ and does not honor --format json"""
+ cmd = ['network-get', '--primary-address']
+ if relation_id:
+ cmd.extend(['-r', relation_id])
+ if extra_binding_name:
+ cmd.extend([extra_binding_name])
+ return subprocess.check_output(cmd).strip()
+
+
+@translate_exc(from_exc=OSError, to_exc=NotImplementedError)
+def network_get(relation_id=None):
+ """Juju network-get"""
+ cmd = ['network-get', '--format=json']
+ if relation_id:
+ cmd.extend(['-r', relation_id])
+ return json.loads(subprocess.check_output(cmd).decode('UTF-8'))
+
+
+@translate_exc(from_exc=OSError, to_exc=NotImplementedError)
+def request_address(relation_id=None, address=None, shared=False, token=False):
+ """Juju request-address"""
+ cmd = ['request-address']
+ if relation_id:
+ cmd.extend(['-r', relation_id])
+ if address:
+ cmd.append(address)
+ if shared:
+ cmd.append('--shared')
+ if token:
+ cmd.extend(['--token', token])
+ return subprocess.check_output(cmd).decode('UTF-8')
+
+
+@translate_exc(from_exc=OSError, to_exc=NotImplementedError)
+def release_address(address, relation_id=None):
+ """Juju request-address"""
+ cmd = ['release-address', address]
+ if relation_id:
+ cmd.extend(['-r', relation_id])
+ return subprocess.check_call(cmd)
View
@@ -13,6 +13,8 @@
unit_get,
cached,
config,
+ network_get_primary_address,
+ log,
status_set,
)
from charmhelpers.fetch import (
@@ -72,6 +74,32 @@ def get_host_ip(hostname=None):
return answers[0].address
+@cached
+def get_public_addr():
+ if config('ceph-public-network'):
+ return get_network_addrs('ceph-public-network')[0]
+
+ try:
+ return network_get_primary_address(extra_binding_name='public')
+ except NotImplementedError:
+ log("DEBUG: network-get failed NotImplementedError", "DEBUG")
+
+ return get_host_ip()
+
+
+@cached
+def get_cluster_addr():
+ if config('ceph-cluster-network'):
+ return get_network_addrs('ceph-cluster-network')[0]
+
+ try:
+ return network_get_primary_address(extra_binding_name='cluster')
+ except NotImplementedError:
+ log("DEBUG: network-get failed NotImplementedError", "DEBUG")
+
+ return get_host_ip()
+
+
def get_networks(config_opt='ceph-public-network'):
"""Get all configured networks from provided config option.
@@ -86,10 +114,6 @@ def get_networks(config_opt='ceph-public-network'):
return []
-def get_public_addr():
- return get_network_addrs('ceph-public-network')[0]
-
-
def get_network_addrs(config_opt):
"""Get all configured public networks addresses.
View
@@ -12,6 +12,9 @@ tags:
peers:
mon:
interface: ceph
+extra-bindings:
+ cluster:
+ public:
provides:
nrpe-external-master:
interface: nrpe-external-master
View
@@ -1,11 +1,11 @@
[global]
-{% if old_auth %}
+{%- if old_auth %}
auth supported = {{ auth_supported }}
-{% else %}
+{%- else %}
auth cluster required = {{ auth_supported }}
auth service required = {{ auth_supported }}
auth client required = {{ auth_supported }}
-{% endif %}
+{%- endif %}
keyring = /etc/ceph/$cluster.$name.keyring
mon host = {{ mon_hosts }}
fsid = {{ fsid }}
@@ -17,17 +17,16 @@ mon cluster log to syslog = {{ use_syslog }}
debug mon = {{ loglevel }}/5
debug osd = {{ loglevel }}/5
-{%- if ceph_public_network is string %}
+{% if ceph_public_network is string %}
public network = {{ ceph_public_network }}
{%- endif %}
{%- if ceph_cluster_network is string %}
cluster network = {{ ceph_cluster_network }}
{%- endif %}
-
-{% if public_addr %}
+{%- if public_addr %}
public addr = {{ public_addr }}
-{% endif %}
-{% if cluster_addr %}
+{%- endif %}
+{%- if cluster_addr %}
cluster addr = {{ cluster_addr }}
{%- endif %}

0 comments on commit f41254a

Please sign in to comment.