Add support for use of directories instead of devices for OSD's
This commit is contained in:
parent
a0fc027f36
commit
dd7ba749ed
|
@ -7,6 +7,9 @@ options:
|
|||
.
|
||||
These devices are the range of devices that will be checked for and
|
||||
used across all service units.
|
||||
.
|
||||
For ceph >= 0.56.6 these can also be directories instead of devices - the
|
||||
charm assumes anything not starting with /dev is a directory instead.
|
||||
osd-journal:
|
||||
type: string
|
||||
description: |
|
||||
|
|
|
@ -15,14 +15,18 @@ import apt_pkg as apt
|
|||
from charmhelpers.core.host import (
|
||||
mkdir,
|
||||
service_restart,
|
||||
log
|
||||
)
|
||||
from charmhelpers.core.hookenv import (
|
||||
log,
|
||||
ERROR,
|
||||
config,
|
||||
)
|
||||
from charmhelpers.contrib.storage.linux.utils import (
|
||||
zap_disk,
|
||||
is_block_device
|
||||
is_block_device,
|
||||
)
|
||||
from utils import (
|
||||
get_unit_hostname
|
||||
get_unit_hostname,
|
||||
)
|
||||
|
||||
LEADER = 'leader'
|
||||
|
@ -119,6 +123,16 @@ def is_osd_disk(dev):
|
|||
return False
|
||||
|
||||
|
||||
def start_osds(devices):
|
||||
if get_ceph_version() < "0.56.6":
|
||||
# Only supports block devices - force a rescan
|
||||
rescan_osd_devices()
|
||||
else:
|
||||
# Use ceph-disk-activate for later ceph versions
|
||||
for dev_or_path in devices:
|
||||
subprocess.check_call(['ceph-disk-activate', dev_or_path])
|
||||
|
||||
|
||||
def rescan_osd_devices():
|
||||
cmd = [
|
||||
'udevadm', 'trigger',
|
||||
|
@ -291,6 +305,13 @@ def update_monfs():
|
|||
|
||||
|
||||
def osdize(dev, osd_format, osd_journal, reformat_osd=False):
|
||||
if dev.startswith('/dev'):
|
||||
osdize_dev(dev, osd_format, osd_journal, reformat_osd)
|
||||
else:
|
||||
osdize_dir(dev)
|
||||
|
||||
|
||||
def osdize_dev(dev, osd_format, osd_journal, reformat_osd=False):
|
||||
if not os.path.exists(dev):
|
||||
log('Path {} does not exist - bailing'.format(dev))
|
||||
return
|
||||
|
@ -327,6 +348,25 @@ def osdize(dev, osd_format, osd_journal, reformat_osd=False):
|
|||
subprocess.check_call(cmd)
|
||||
|
||||
|
||||
def osdize_dir(path):
|
||||
if os.path.exists(os.path.join(path, 'upstart')):
|
||||
log('Path {} is already configured as an OSD - bailing'.format(path))
|
||||
return
|
||||
|
||||
if get_ceph_version() < "0.56.6":
|
||||
log('Unable to use directories for OSDs with ceph < 0.56.6',
|
||||
level=ERROR)
|
||||
raise
|
||||
|
||||
mkdir(path)
|
||||
cmd = [
|
||||
'ceph-disk-prepare',
|
||||
'--data-dir',
|
||||
path
|
||||
]
|
||||
subprocess.check_call(cmd)
|
||||
|
||||
|
||||
def device_mounted(dev):
|
||||
return subprocess.call(['grep', '-wqs', dev + '1', '/proc/mounts']) == 0
|
||||
|
||||
|
|
|
@ -96,10 +96,10 @@ def config_changed():
|
|||
if ceph.is_bootstrapped():
|
||||
log('ceph bootstrapped, rescanning disks')
|
||||
emit_cephconf()
|
||||
for dev in config('osd-devices').split(' '):
|
||||
for dev in get_devices():
|
||||
ceph.osdize(dev, config('osd-format'),
|
||||
config('osd-journal'), config('osd-reformat'))
|
||||
ceph.rescan_osd_devices()
|
||||
ceph.start_osds(get_devices())
|
||||
|
||||
log('End config-changed hook.')
|
||||
|
||||
|
@ -142,6 +142,12 @@ def reformat_osd():
|
|||
return False
|
||||
|
||||
|
||||
def get_devices():
|
||||
if config('osd-devices'):
|
||||
return config('osd-devices').split(' ')
|
||||
else:
|
||||
return []
|
||||
|
||||
@hooks.hook('mon-relation-changed',
|
||||
'mon-relation-departed')
|
||||
def mon_relation():
|
||||
|
@ -152,10 +158,10 @@ def mon_relation():
|
|||
log('mon has provided conf- scanning disks')
|
||||
emit_cephconf()
|
||||
ceph.import_osd_bootstrap_key(bootstrap_key)
|
||||
for dev in config('osd-devices').split(' '):
|
||||
for dev in get_devices():
|
||||
ceph.osdize(dev, config('osd-format'),
|
||||
config('osd-journal'), config('osd-reformat'))
|
||||
ceph.rescan_osd_devices()
|
||||
ceph.start_osds(get_devices())
|
||||
else:
|
||||
log('mon cluster has not yet provided conf')
|
||||
|
||||
|
|
Loading…
Reference in New Issue