diff --git a/hooks/ceph_hooks.py b/hooks/ceph_hooks.py index 1c402796..912abc11 100755 --- a/hooks/ceph_hooks.py +++ b/hooks/ceph_hooks.py @@ -12,6 +12,7 @@ import os import shutil import sys import tempfile +import socket import ceph from charmhelpers.core.hookenv import ( @@ -73,6 +74,12 @@ def install(): install_upstart_scripts() +def az_info(): + az_info = os.environ.get('JUJU_AVAILABILITY_ZONE') + log("AZ Info: " + az_info) + return az_info + + def emit_cephconf(): mon_hosts = get_mon_hosts() log('Monitor hosts are ' + repr(mon_hosts)) @@ -103,6 +110,10 @@ def emit_cephconf(): if not cluster_network: cephcontext['cluster_addr'] = dynamic_ipv6_address + if az_info(): + cephcontext['crush_location'] = "root=default rack={} host={}" \ + .format(az_info(), socket.gethostname()) + # Install ceph.conf as an alternative to support # co-existence with other charms that write this file charm_ceph_conf = "/var/lib/charm/{}/ceph.conf".format(service_name()) diff --git a/templates/ceph.conf b/templates/ceph.conf index edd4f646..66da0aca 100644 --- a/templates/ceph.conf +++ b/templates/ceph.conf @@ -29,6 +29,10 @@ public addr = {{ public_addr }} cluster addr = {{ cluster_addr }} {%- endif %} +{% if crush_location %} +osd crush location = {{crush_location}} +{% endif %} + [mon] keyring = /var/lib/ceph/mon/$cluster-$id/keyring