Add basic status support

This commit is contained in:
James Page
2015-10-06 11:44:28 +01:00
parent cac9d656b8
commit 94fd9f7bc1
2 changed files with 41 additions and 2 deletions

View File

@@ -18,7 +18,8 @@ from charmhelpers.core.host import (
)
from charmhelpers.core.hookenv import (
log,
ERROR, WARNING
ERROR, WARNING,
status_set,
)
from charmhelpers.contrib.storage.linux.utils import (
zap_disk,
@@ -333,6 +334,7 @@ def osdize_dev(dev, osd_format, osd_journal, reformat_osd=False,
log('Looks like {} is in use, skipping.'.format(dev))
return
status_set('maintenance', 'Initializing device {}'.format(dev))
cmd = ['ceph-disk-prepare']
# Later versions of ceph support more options
if cmp_pkgrevno('ceph', '0.48.3') >= 0:
@@ -382,3 +384,13 @@ def osdize_dir(path):
def filesystem_mounted(fs):
return subprocess.call(['grep', '-wqs', fs, '/proc/mounts']) == 0
def get_running_osds():
'''Returns a list of the pids of the current running OSD daemons'''
cmd = ['pgrep', 'ceph-osd']
try:
result = subprocess.check_output(cmd)
return result.split()
except subprocess.CalledProcessError:
return []

View File

@@ -22,7 +22,8 @@ from charmhelpers.core.hookenv import (
relation_get,
Hooks,
UnregisteredHookError,
service_name
service_name,
status_set,
)
from charmhelpers.core.host import (
umount,
@@ -227,8 +228,34 @@ def update_nrpe_config():
nrpe_setup.write()
def assess_status():
'''Assess status of current unit'''
# Check for mon relation
if len(relation_ids('mon')) < 1:
status_set('blocked', 'Missing relation: monitor')
return
# Check for monitors with presented addresses
# Check for bootstrap key presentation
monitors = get_mon_hosts()
if len(monitors) < 1 or not get_conf('osd_bootstrap_key'):
status_set('waiting', 'Incomplete relation: monitor')
return
# Check for OSD device creation parity i.e. at least some devices
# must have been presented and used for this charm to be operational
running_osds = ceph.get_running_osds()
if not running_osds:
status_set('blocked',
'No block devices detected using current configuration')
else:
status_set('active',
'Unit is ready ({} OSD)'.format(len(running_osds)))
if __name__ == '__main__':
try:
hooks.execute(sys.argv)
except UnregisteredHookError as e:
log('Unknown hook {} - skipping.'.format(e))
assess_status()