add support for infernalis
This commit is contained in:
parent
204cf03269
commit
46fb69d94d
126
hooks/ceph.py
126
hooks/ceph.py
|
@ -11,16 +11,25 @@ import json
|
|||
import subprocess
|
||||
import time
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
from charmhelpers.core.host import (
|
||||
mkdir,
|
||||
chownr,
|
||||
service_restart,
|
||||
cmp_pkgrevno
|
||||
cmp_pkgrevno,
|
||||
lsb_release
|
||||
)
|
||||
from charmhelpers.core.hookenv import (
|
||||
log,
|
||||
ERROR, WARNING,
|
||||
ERROR,
|
||||
WARNING,
|
||||
cached,
|
||||
status_set,
|
||||
)
|
||||
from charmhelpers.fetch import (
|
||||
apt_cache
|
||||
)
|
||||
from charmhelpers.contrib.storage.linux.utils import (
|
||||
zap_disk,
|
||||
is_block_device,
|
||||
|
@ -37,9 +46,55 @@ QUORUM = [LEADER, PEON]
|
|||
PACKAGES = ['ceph', 'gdisk', 'ntp', 'btrfs-tools', 'python-ceph', 'xfsprogs']
|
||||
|
||||
|
||||
def ceph_user():
|
||||
if get_version() > 1:
|
||||
return 'ceph'
|
||||
else:
|
||||
return "root"
|
||||
|
||||
|
||||
def get_version():
|
||||
'''Derive Ceph release from an installed package.'''
|
||||
import apt_pkg as apt
|
||||
|
||||
cache = apt_cache()
|
||||
package = "ceph"
|
||||
try:
|
||||
pkg = cache[package]
|
||||
except:
|
||||
# the package is unknown to the current apt cache.
|
||||
e = 'Could not determine version of package with no installation '\
|
||||
'candidate: %s' % package
|
||||
error_out(e)
|
||||
|
||||
if not pkg.current_ver:
|
||||
# package is known, but no version is currently installed.
|
||||
e = 'Could not determine version of uninstalled package: %s' % package
|
||||
error_out(e)
|
||||
|
||||
vers = apt.upstream_version(pkg.current_ver.ver_str)
|
||||
|
||||
# x.y match only for 20XX.X
|
||||
# and ignore patch level for other packages
|
||||
match = re.match('^(\d+)\.(\d+)', vers)
|
||||
|
||||
if match:
|
||||
vers = match.group(0)
|
||||
return float(vers)
|
||||
|
||||
|
||||
def error_out(msg):
|
||||
log("FATAL ERROR: %s" % msg,
|
||||
level=ERROR)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def is_quorum():
|
||||
asok = "/var/run/ceph/ceph-mon.{}.asok".format(get_unit_hostname())
|
||||
cmd = [
|
||||
"sudo",
|
||||
"-u",
|
||||
ceph_user(),
|
||||
"ceph",
|
||||
"--admin-daemon",
|
||||
asok,
|
||||
|
@ -64,6 +119,9 @@ def is_quorum():
|
|||
def is_leader():
|
||||
asok = "/var/run/ceph/ceph-mon.{}.asok".format(get_unit_hostname())
|
||||
cmd = [
|
||||
"sudo",
|
||||
"-u",
|
||||
ceph_user(),
|
||||
"ceph",
|
||||
"--admin-daemon",
|
||||
asok,
|
||||
|
@ -93,6 +151,9 @@ def wait_for_quorum():
|
|||
def add_bootstrap_hint(peer):
|
||||
asok = "/var/run/ceph/ceph-mon.{}.asok".format(get_unit_hostname())
|
||||
cmd = [
|
||||
"sudo",
|
||||
"-u",
|
||||
ceph_user(),
|
||||
"ceph",
|
||||
"--admin-daemon",
|
||||
asok,
|
||||
|
@ -127,11 +188,11 @@ def is_osd_disk(dev):
|
|||
def start_osds(devices):
|
||||
# Scan for ceph block devices
|
||||
rescan_osd_devices()
|
||||
if cmp_pkgrevno('ceph', '0.56.6') >= 0:
|
||||
# Use ceph-disk-activate for directory based OSD's
|
||||
if cmp_pkgrevno('ceph', "0.56.6") >= 0:
|
||||
# Use ceph-disk activate for directory based OSD's
|
||||
for dev_or_path in devices:
|
||||
if os.path.exists(dev_or_path) and os.path.isdir(dev_or_path):
|
||||
subprocess.check_call(['ceph-disk-activate', dev_or_path])
|
||||
subprocess.check_call(['ceph-disk', 'activate', dev_or_path])
|
||||
|
||||
|
||||
def rescan_osd_devices():
|
||||
|
@ -158,6 +219,9 @@ def wait_for_bootstrap():
|
|||
def import_osd_bootstrap_key(key):
|
||||
if not os.path.exists(_bootstrap_keyring):
|
||||
cmd = [
|
||||
"sudo",
|
||||
"-u",
|
||||
ceph_user(),
|
||||
'ceph-authtool',
|
||||
_bootstrap_keyring,
|
||||
'--create-keyring',
|
||||
|
@ -216,6 +280,9 @@ _radosgw_keyring = "/etc/ceph/keyring.rados.gateway"
|
|||
def import_radosgw_key(key):
|
||||
if not os.path.exists(_radosgw_keyring):
|
||||
cmd = [
|
||||
"sudo",
|
||||
"-u",
|
||||
ceph_user(),
|
||||
'ceph-authtool',
|
||||
_radosgw_keyring,
|
||||
'--create-keyring',
|
||||
|
@ -244,6 +311,9 @@ _default_caps = {
|
|||
def get_named_key(name, caps=None):
|
||||
caps = caps or _default_caps
|
||||
cmd = [
|
||||
"sudo",
|
||||
"-u",
|
||||
ceph_user(),
|
||||
'ceph',
|
||||
'--name', 'mon.',
|
||||
'--keyring',
|
||||
|
@ -261,19 +331,29 @@ def get_named_key(name, caps=None):
|
|||
return parse_key(subprocess.check_output(cmd).strip()) # IGNORE:E1103
|
||||
|
||||
|
||||
@cached
|
||||
def systemd():
|
||||
return (lsb_release()['DISTRIB_CODENAME'] >= 'vivid')
|
||||
|
||||
|
||||
def bootstrap_monitor_cluster(secret):
|
||||
hostname = get_unit_hostname()
|
||||
path = '/var/lib/ceph/mon/ceph-{}'.format(hostname)
|
||||
done = '{}/done'.format(path)
|
||||
upstart = '{}/upstart'.format(path)
|
||||
if systemd():
|
||||
init_marker = '{}/systemd'.format(path)
|
||||
else:
|
||||
init_marker = '{}/upstart'.format(path)
|
||||
|
||||
keyring = '/var/lib/ceph/tmp/{}.mon.keyring'.format(hostname)
|
||||
|
||||
if os.path.exists(done):
|
||||
log('bootstrap_monitor_cluster: mon already initialized.')
|
||||
else:
|
||||
# Ceph >= 0.61.3 needs this for ceph-mon fs creation
|
||||
mkdir('/var/run/ceph', perms=0755)
|
||||
mkdir(path)
|
||||
mkdir('/var/run/ceph', owner=ceph_user(),
|
||||
group=ceph_user(), perms=0o755)
|
||||
mkdir(path, owner=ceph_user(), group=ceph_user())
|
||||
# end changes for Ceph >= 0.61.3
|
||||
try:
|
||||
subprocess.check_call(['ceph-authtool', keyring,
|
||||
|
@ -284,13 +364,17 @@ def bootstrap_monitor_cluster(secret):
|
|||
subprocess.check_call(['ceph-mon', '--mkfs',
|
||||
'-i', hostname,
|
||||
'--keyring', keyring])
|
||||
|
||||
chownr(path, ceph_user(), ceph_user())
|
||||
with open(done, 'w'):
|
||||
pass
|
||||
with open(upstart, 'w'):
|
||||
with open(init_marker, 'w'):
|
||||
pass
|
||||
|
||||
service_restart('ceph-mon-all')
|
||||
if systemd():
|
||||
subprocess.check_call(['systemctl', 'enable', 'ceph-mon'])
|
||||
service_restart('ceph-mon')
|
||||
else:
|
||||
service_restart('ceph-mon-all')
|
||||
except:
|
||||
raise
|
||||
finally:
|
||||
|
@ -300,11 +384,14 @@ def bootstrap_monitor_cluster(secret):
|
|||
def update_monfs():
|
||||
hostname = get_unit_hostname()
|
||||
monfs = '/var/lib/ceph/mon/ceph-{}'.format(hostname)
|
||||
upstart = '{}/upstart'.format(monfs)
|
||||
if os.path.exists(monfs) and not os.path.exists(upstart):
|
||||
if systemd():
|
||||
init_marker = '{}/systemd'.format(monfs)
|
||||
else:
|
||||
init_marker = '{}/upstart'.format(monfs)
|
||||
if os.path.exists(monfs) and not os.path.exists(init_marker):
|
||||
# Mark mon as managed by upstart so that
|
||||
# it gets start correctly on reboots
|
||||
with open(upstart, 'w'):
|
||||
with open(init_marker, 'w'):
|
||||
pass
|
||||
|
||||
|
||||
|
@ -335,7 +422,7 @@ def osdize_dev(dev, osd_format, osd_journal, reformat_osd=False,
|
|||
return
|
||||
|
||||
status_set('maintenance', 'Initializing device {}'.format(dev))
|
||||
cmd = ['ceph-disk-prepare']
|
||||
cmd = ['ceph-disk', 'prepare']
|
||||
# Later versions of ceph support more options
|
||||
if cmp_pkgrevno('ceph', '0.48.3') >= 0:
|
||||
if osd_format:
|
||||
|
@ -368,14 +455,17 @@ def osdize_dir(path):
|
|||
log('Path {} is already configured as an OSD - bailing'.format(path))
|
||||
return
|
||||
|
||||
if cmp_pkgrevno('ceph', '0.56.6') < 0:
|
||||
if cmp_pkgrevno('ceph', "0.56.6") < 0:
|
||||
log('Unable to use directories for OSDs with ceph < 0.56.6',
|
||||
level=ERROR)
|
||||
raise
|
||||
|
||||
mkdir(path)
|
||||
mkdir(path, owner=ceph_user(), group=ceph_user(), perms=0o755)
|
||||
chownr('/var/lib/ceph', ceph_user(), ceph_user())
|
||||
cmd = [
|
||||
'ceph-disk-prepare',
|
||||
'sudo', '-u', ceph_user(),
|
||||
'ceph-disk',
|
||||
'prepare',
|
||||
'--data-dir',
|
||||
path
|
||||
]
|
||||
|
|
|
@ -95,7 +95,8 @@ def emit_cephconf():
|
|||
# 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())
|
||||
mkdir(os.path.dirname(charm_ceph_conf))
|
||||
mkdir(os.path.dirname(charm_ceph_conf), owner=ceph.ceph_user(),
|
||||
group=ceph.ceph_user())
|
||||
with open(charm_ceph_conf, 'w') as cephconf:
|
||||
cephconf.write(render_template('ceph.conf', cephcontext))
|
||||
install_alternative('ceph.conf', '/etc/ceph/ceph.conf',
|
||||
|
|
Loading…
Reference in New Issue