Resync with ceph charm, updates for raring
This commit is contained in:
parent
e1d4165e4e
commit
80b4985348
17
config.yaml
17
config.yaml
@ -7,6 +7,23 @@ options:
|
|||||||
.
|
.
|
||||||
These devices are the range of devices that will be checked for and
|
These devices are the range of devices that will be checked for and
|
||||||
used across all service units.
|
used across all service units.
|
||||||
|
osd-journal:
|
||||||
|
type: string
|
||||||
|
description: |
|
||||||
|
The device to use as a shared journal drive for all OSD's. By default
|
||||||
|
no journal device will be used.
|
||||||
|
.
|
||||||
|
Only supported with ceph >= 0.55.
|
||||||
|
osd-format:
|
||||||
|
type: string
|
||||||
|
default: xfs
|
||||||
|
description: |
|
||||||
|
Format of filesystem to use for OSD devices; supported formats include:
|
||||||
|
.
|
||||||
|
xfs (Default >= 0.55)
|
||||||
|
ext4 (Only option < 0.55)
|
||||||
|
.
|
||||||
|
Only supported with ceph >= 0.55.
|
||||||
osd-reformat:
|
osd-reformat:
|
||||||
type: string
|
type: string
|
||||||
description: |
|
description: |
|
||||||
|
108
hooks/ceph.py
108
hooks/ceph.py
@ -12,8 +12,11 @@ import subprocess
|
|||||||
import time
|
import time
|
||||||
import utils
|
import utils
|
||||||
import os
|
import os
|
||||||
|
import apt_pkg as apt
|
||||||
|
|
||||||
QUORUM = ['leader', 'peon']
|
LEADER = 'leader'
|
||||||
|
PEON = 'peon'
|
||||||
|
QUORUM = [LEADER, PEON]
|
||||||
|
|
||||||
|
|
||||||
def is_quorum():
|
def is_quorum():
|
||||||
@ -40,6 +43,30 @@ def is_quorum():
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def is_leader():
|
||||||
|
asok = "/var/run/ceph/ceph-mon.{}.asok".format(utils.get_unit_hostname())
|
||||||
|
cmd = [
|
||||||
|
"ceph",
|
||||||
|
"--admin-daemon",
|
||||||
|
asok,
|
||||||
|
"mon_status"
|
||||||
|
]
|
||||||
|
if os.path.exists(asok):
|
||||||
|
try:
|
||||||
|
result = json.loads(subprocess.check_output(cmd))
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
return False
|
||||||
|
except ValueError:
|
||||||
|
# Non JSON response from mon_status
|
||||||
|
return False
|
||||||
|
if result['state'] == LEADER:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def wait_for_quorum():
|
def wait_for_quorum():
|
||||||
while not is_quorum():
|
while not is_quorum():
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
@ -81,6 +108,7 @@ def rescan_osd_devices():
|
|||||||
|
|
||||||
subprocess.call(cmd)
|
subprocess.call(cmd)
|
||||||
|
|
||||||
|
|
||||||
_bootstrap_keyring = "/var/lib/ceph/bootstrap-osd/ceph.keyring"
|
_bootstrap_keyring = "/var/lib/ceph/bootstrap-osd/ceph.keyring"
|
||||||
|
|
||||||
|
|
||||||
@ -88,6 +116,11 @@ def is_bootstrapped():
|
|||||||
return os.path.exists(_bootstrap_keyring)
|
return os.path.exists(_bootstrap_keyring)
|
||||||
|
|
||||||
|
|
||||||
|
def wait_for_bootstrap():
|
||||||
|
while (not is_bootstrapped()):
|
||||||
|
time.sleep(3)
|
||||||
|
|
||||||
|
|
||||||
def import_osd_bootstrap_key(key):
|
def import_osd_bootstrap_key(key):
|
||||||
if not os.path.exists(_bootstrap_keyring):
|
if not os.path.exists(_bootstrap_keyring):
|
||||||
cmd = [
|
cmd = [
|
||||||
@ -100,15 +133,53 @@ def import_osd_bootstrap_key(key):
|
|||||||
subprocess.check_call(cmd)
|
subprocess.check_call(cmd)
|
||||||
|
|
||||||
# OSD caps taken from ceph-create-keys
|
# OSD caps taken from ceph-create-keys
|
||||||
_osd_bootstrap_caps = [
|
_osd_bootstrap_caps = {
|
||||||
'allow command osd create ...',
|
'mon': [
|
||||||
'allow command osd crush set ...',
|
'allow command osd create ...',
|
||||||
r'allow command auth add * osd allow\ * mon allow\ rwx',
|
'allow command osd crush set ...',
|
||||||
'allow command mon getmap'
|
r'allow command auth add * osd allow\ * mon allow\ rwx',
|
||||||
]
|
'allow command mon getmap'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def get_osd_bootstrap_key():
|
def get_osd_bootstrap_key():
|
||||||
|
return get_named_key('bootstrap-osd', _osd_bootstrap_caps)
|
||||||
|
|
||||||
|
|
||||||
|
_radosgw_keyring = "/etc/ceph/keyring.rados.gateway"
|
||||||
|
|
||||||
|
|
||||||
|
def import_radosgw_key(key):
|
||||||
|
if not os.path.exists(_radosgw_keyring):
|
||||||
|
cmd = [
|
||||||
|
'ceph-authtool',
|
||||||
|
_radosgw_keyring,
|
||||||
|
'--create-keyring',
|
||||||
|
'--name=client.radosgw.gateway',
|
||||||
|
'--add-key={}'.format(key)
|
||||||
|
]
|
||||||
|
subprocess.check_call(cmd)
|
||||||
|
|
||||||
|
# OSD caps taken from ceph-create-keys
|
||||||
|
_radosgw_caps = {
|
||||||
|
'mon': ['allow r'],
|
||||||
|
'osd': ['allow rwx']
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def get_radosgw_key():
|
||||||
|
return get_named_key('radosgw.gateway', _radosgw_caps)
|
||||||
|
|
||||||
|
|
||||||
|
_default_caps = {
|
||||||
|
'mon': ['allow r'],
|
||||||
|
'osd': ['allow rwx']
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def get_named_key(name, caps=None):
|
||||||
|
caps = caps or _default_caps
|
||||||
cmd = [
|
cmd = [
|
||||||
'ceph',
|
'ceph',
|
||||||
'--name', 'mon.',
|
'--name', 'mon.',
|
||||||
@ -116,9 +187,14 @@ def get_osd_bootstrap_key():
|
|||||||
'/var/lib/ceph/mon/ceph-{}/keyring'.format(
|
'/var/lib/ceph/mon/ceph-{}/keyring'.format(
|
||||||
utils.get_unit_hostname()
|
utils.get_unit_hostname()
|
||||||
),
|
),
|
||||||
'auth', 'get-or-create', 'client.bootstrap-osd',
|
'auth', 'get-or-create', 'client.{}'.format(name),
|
||||||
'mon', '; '.join(_osd_bootstrap_caps)
|
|
||||||
]
|
]
|
||||||
|
# Add capabilities
|
||||||
|
for subsystem, subcaps in caps.iteritems():
|
||||||
|
cmd.extend([
|
||||||
|
subsystem,
|
||||||
|
'; '.join(subcaps),
|
||||||
|
])
|
||||||
output = subprocess.check_output(cmd).strip() # IGNORE:E1103
|
output = subprocess.check_output(cmd).strip() # IGNORE:E1103
|
||||||
# get-or-create appears to have different output depending
|
# get-or-create appears to have different output depending
|
||||||
# on whether its 'get' or 'create'
|
# on whether its 'get' or 'create'
|
||||||
@ -132,3 +208,17 @@ def get_osd_bootstrap_key():
|
|||||||
if 'key' in element:
|
if 'key' in element:
|
||||||
key = element.split(' = ')[1].strip() # IGNORE:E1103
|
key = element.split(' = ')[1].strip() # IGNORE:E1103
|
||||||
return key
|
return key
|
||||||
|
|
||||||
|
|
||||||
|
def get_ceph_version():
|
||||||
|
apt.init()
|
||||||
|
cache = apt.Cache()
|
||||||
|
pkg = cache['ceph']
|
||||||
|
if pkg.current_ver:
|
||||||
|
return apt.upstream_version(pkg.current_ver.ver_str)
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def version_compare(a, b):
|
||||||
|
return apt.version_compare(a, b)
|
||||||
|
@ -18,8 +18,11 @@ import utils
|
|||||||
|
|
||||||
|
|
||||||
def install_upstart_scripts():
|
def install_upstart_scripts():
|
||||||
for x in glob.glob('files/upstart/*.conf'):
|
# Only install upstart configurations for older versions
|
||||||
shutil.copy(x, '/etc/init/')
|
if ceph.version_compare(ceph.get_ceph_version(),
|
||||||
|
"0.55.1") < 0:
|
||||||
|
for x in glob.glob('files/upstart/*.conf'):
|
||||||
|
shutil.copy(x, '/etc/init/')
|
||||||
|
|
||||||
|
|
||||||
def install():
|
def install():
|
||||||
@ -37,7 +40,8 @@ def emit_cephconf():
|
|||||||
cephcontext = {
|
cephcontext = {
|
||||||
'auth_supported': get_auth(),
|
'auth_supported': get_auth(),
|
||||||
'mon_hosts': ' '.join(mon_hosts),
|
'mon_hosts': ' '.join(mon_hosts),
|
||||||
'fsid': get_fsid()
|
'fsid': get_fsid(),
|
||||||
|
'version': ceph.get_ceph_version()
|
||||||
}
|
}
|
||||||
|
|
||||||
with open('/etc/ceph/ceph.conf', 'w') as cephconf:
|
with open('/etc/ceph/ceph.conf', 'w') as cephconf:
|
||||||
@ -48,7 +52,7 @@ def config_changed():
|
|||||||
utils.juju_log('INFO', 'Begin config-changed hook.')
|
utils.juju_log('INFO', 'Begin config-changed hook.')
|
||||||
|
|
||||||
e_mountpoint = utils.config_get('ephemeral-unmount')
|
e_mountpoint = utils.config_get('ephemeral-unmount')
|
||||||
if (e_mountpoint != "" and
|
if (e_mountpoint and
|
||||||
filesystem_mounted(e_mountpoint)):
|
filesystem_mounted(e_mountpoint)):
|
||||||
subprocess.call(['umount', e_mountpoint])
|
subprocess.call(['umount', e_mountpoint])
|
||||||
|
|
||||||
@ -89,13 +93,13 @@ def get_conf(name):
|
|||||||
for unit in utils.relation_list(relid):
|
for unit in utils.relation_list(relid):
|
||||||
conf = utils.relation_get(name,
|
conf = utils.relation_get(name,
|
||||||
unit, relid)
|
unit, relid)
|
||||||
if conf != "":
|
if conf:
|
||||||
return conf
|
return conf
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def reformat_osd():
|
def reformat_osd():
|
||||||
if utils.config_get('osd-reformat') != "":
|
if utils.config_get('osd-reformat'):
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
@ -119,7 +123,24 @@ def osdize(dev):
|
|||||||
'Looks like {} is in use, skipping.'.format(dev))
|
'Looks like {} is in use, skipping.'.format(dev))
|
||||||
return
|
return
|
||||||
|
|
||||||
subprocess.call(['ceph-disk-prepare', dev])
|
cmd = ['ceph-disk-prepare']
|
||||||
|
# Later versions of ceph support more options
|
||||||
|
if ceph.version_compare(ceph.get_ceph_version(),
|
||||||
|
"0.55") >= 0:
|
||||||
|
osd_format = utils.config_get('osd-format')
|
||||||
|
if osd_format:
|
||||||
|
cmd.append('--fs-type')
|
||||||
|
cmd.append(osd_format)
|
||||||
|
cmd.append(dev)
|
||||||
|
osd_journal = utils.config_get('osd-journal')
|
||||||
|
if (osd_journal and
|
||||||
|
os.path.exists(osd_journal)):
|
||||||
|
cmd.append(osd_journal)
|
||||||
|
else:
|
||||||
|
# Just provide the device - no other options
|
||||||
|
# for older versions of ceph
|
||||||
|
cmd.append(dev)
|
||||||
|
subprocess.call(cmd)
|
||||||
|
|
||||||
|
|
||||||
def device_mounted(dev):
|
def device_mounted(dev):
|
||||||
@ -136,7 +157,7 @@ def mon_relation():
|
|||||||
bootstrap_key = utils.relation_get('osd_bootstrap_key')
|
bootstrap_key = utils.relation_get('osd_bootstrap_key')
|
||||||
if (get_fsid() and
|
if (get_fsid() and
|
||||||
get_auth() and
|
get_auth() and
|
||||||
bootstrap_key != ""):
|
bootstrap_key):
|
||||||
utils.juju_log('INFO', 'mon has provided conf- scanning disks')
|
utils.juju_log('INFO', 'mon has provided conf- scanning disks')
|
||||||
emit_cephconf()
|
emit_cephconf()
|
||||||
ceph.import_osd_bootstrap_key(bootstrap_key)
|
ceph.import_osd_bootstrap_key(bootstrap_key)
|
||||||
@ -159,18 +180,11 @@ def upgrade_charm():
|
|||||||
utils.juju_log('INFO', 'End upgrade-charm hook.')
|
utils.juju_log('INFO', 'End upgrade-charm hook.')
|
||||||
|
|
||||||
|
|
||||||
def start():
|
|
||||||
# In case we're being redeployed to the same machines, try
|
|
||||||
# to make sure everything is running as soon as possible.
|
|
||||||
ceph.rescan_osd_devices()
|
|
||||||
|
|
||||||
|
|
||||||
utils.do_hooks({
|
utils.do_hooks({
|
||||||
'config-changed': config_changed,
|
'config-changed': config_changed,
|
||||||
'install': install,
|
'install': install,
|
||||||
'mon-relation-departed': mon_relation,
|
'mon-relation-departed': mon_relation,
|
||||||
'mon-relation-changed': mon_relation,
|
'mon-relation-changed': mon_relation,
|
||||||
'start': start,
|
|
||||||
'upgrade-charm': upgrade_charm,
|
'upgrade-charm': upgrade_charm,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -136,7 +136,11 @@ def relation_get(attribute, unit=None, rid=None):
|
|||||||
cmd.append(attribute)
|
cmd.append(attribute)
|
||||||
if unit:
|
if unit:
|
||||||
cmd.append(unit)
|
cmd.append(unit)
|
||||||
return subprocess.check_output(cmd).strip() # IGNORE:E1103
|
value = str(subprocess.check_output(cmd)).strip()
|
||||||
|
if value == "":
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
def relation_set(**kwargs):
|
def relation_set(**kwargs):
|
||||||
@ -159,7 +163,11 @@ def unit_get(attribute):
|
|||||||
'unit-get',
|
'unit-get',
|
||||||
attribute
|
attribute
|
||||||
]
|
]
|
||||||
return subprocess.check_output(cmd).strip() # IGNORE:E1103
|
value = str(subprocess.check_output(cmd)).strip()
|
||||||
|
if value == "":
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
def config_get(attribute):
|
def config_get(attribute):
|
||||||
@ -167,7 +175,11 @@ def config_get(attribute):
|
|||||||
'config-get',
|
'config-get',
|
||||||
attribute
|
attribute
|
||||||
]
|
]
|
||||||
return subprocess.check_output(cmd).strip() # IGNORE:E1103
|
value = str(subprocess.check_output(cmd)).strip()
|
||||||
|
if value == "":
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
def get_unit_hostname():
|
def get_unit_hostname():
|
||||||
|
@ -1,5 +1,11 @@
|
|||||||
[global]
|
[global]
|
||||||
|
{% if version < "0.51" %}
|
||||||
auth supported = {{ auth_supported }}
|
auth supported = {{ auth_supported }}
|
||||||
|
{% else %}
|
||||||
|
auth cluster required = {{ auth_supported }}
|
||||||
|
auth service required = {{ auth_supported }}
|
||||||
|
auth client required = {{ auth_supported }}
|
||||||
|
{% endif %}
|
||||||
keyring = /etc/ceph/$cluster.$name.keyring
|
keyring = /etc/ceph/$cluster.$name.keyring
|
||||||
mon host = {{ mon_hosts }}
|
mon host = {{ mon_hosts }}
|
||||||
fsid = {{ fsid }}
|
fsid = {{ fsid }}
|
||||||
|
Loading…
Reference in New Issue
Block a user