Remove ceph-base layer

This migrates the required functionality from the
Ceph base layer into this one to remove the
requirement on ceph-base

Change-Id: I136aeeb24a5dddadf4c9306ffe324653ed5b1a66
This commit is contained in:
Chris MacNaughton 2017-02-21 14:59:07 -05:00
parent 074e02ab94
commit b5064bd226
3 changed files with 72 additions and 4 deletions

View File

@ -16,6 +16,12 @@ options:
Note that a minimum ceph version of 0.48.2 is required for use with this
charm which is NOT provided by the packages in the main Ubuntu archive
for precise but is provided in the Ubuntu cloud archive.
key:
type: string
default:
description: |
Key ID to import to the apt keyring to support use with arbitary source
configuration from outside of Launchpad archives or PPA's.
use-syslog:
type: boolean
default: False

View File

@ -1,4 +1,4 @@
includes: ['layer:apt', 'layer:ceph-base', 'interface:ceph-mds']
includes: ['layer:basic', 'layer:apt', 'interface:ceph-mds']
options:
apt:
packages:

View File

@ -16,10 +16,12 @@ import os
import socket
import subprocess
from charms.reactive import when, when_not, set_state
from charms import reactive
from charms.reactive import when, when_not, set_state, is_state
from charmhelpers.core import hookenv
from charmhelpers.core.hookenv import (
application_version_set, config, log, ERROR, cached, DEBUG, unit_get,
network_get_primary_address,
network_get_primary_address, relation_ids,
status_set)
from charmhelpers.core.host import service_restart
from charmhelpers.contrib.network.ip import (
@ -31,7 +33,9 @@ from charmhelpers.fetch import (
apt_install, filter_installed_packages)
import jinja2
from charms.apt import queue_install
from charms.apt import queue_install, add_source
PACKAGES = ['ceph', 'gdisk', 'ntp', 'btrfs-tools', 'python-ceph', 'xfsprogs']
try:
import dns.resolver
@ -50,6 +54,12 @@ def render_template(template_name, context, template_dir=TEMPLATES_DIR):
return template.render(context)
@when_not('apt.installed.ceph')
def install_ceph_base():
add_source(config('source'), key=config('key'))
queue_install(PACKAGES)
@when_not('apt.installed.ceph-mds')
def install_cephfs():
queue_install(['ceph-mds'])
@ -189,3 +199,55 @@ def get_network_addrs(config_opt):
return [get_host_ip()]
return addrs
def assess_status():
"""Assess status of current unit"""
statuses = set([])
messages = set([])
if is_state('cephfs.started'):
(status, message) = log_mds()
statuses.add(status)
messages.add(message)
if 'blocked' in statuses:
status = 'blocked'
elif 'waiting' in statuses:
status = 'waiting'
else:
status = 'active'
message = '; '.join(messages)
status_set(status, message)
def get_running_mds():
"""Returns a list of the pids of the current running MDS daemons"""
cmd = ['pgrep', 'ceph-mds']
try:
result = subprocess.check_output(cmd).decode('utf-8')
return result.split()
except subprocess.CalledProcessError:
return []
def log_mds():
if len(relation_ids('ceph-mds')) < 1:
return 'blocked', 'Missing relation: monitor'
running_mds = get_running_mds()
if not running_mds:
return 'blocked', 'No MDS detected using current configuration'
else:
return 'active', 'Unit is ready ({} MDS)'.format(len(running_mds))
# Per https://github.com/juju-solutions/charms.reactive/issues/33,
# this module may be imported multiple times so ensure the
# initialization hook is only registered once. I have to piggy back
# onto the namespace of a module imported before reactive discovery
# to do this.
if not hasattr(reactive, '_ceph_log_registered'):
# We need to register this to run every hook, not just during install
# and config-changed, to protect against race conditions. If we don't
# do this, then the config in the hook environment may show updates
# to running hooks well before the config-changed hook has been invoked
# and the intialization provided an opertunity to be run.
hookenv.atexit(assess_status)
reactive._ceph_log_registered = True