Merged is_osd_disk changes from pjdc, fixed up remaining pep8 errors

This commit is contained in:
James Page
2012-10-05 11:06:48 +01:00
4 changed files with 47 additions and 15 deletions

View File

@@ -57,3 +57,17 @@ def add_bootstrap_hint(peer):
if os.path.exists(asok):
# Ignore any errors for this call
subprocess.call(cmd)
def is_osd_disk(dev):
try:
info = subprocess.check_output(['sgdisk', '-i', '1', dev])
info = info.split("\n") # IGNORE:E1103
for line in info:
if line.startswith(
'Partition GUID code: 4FBD7E29-9D25-41B8-AFD0-062C0CEFF05D'
):
return True
except subprocess.CalledProcessError:
pass
return False

34
hooks/hooks.py Executable file → Normal file
View File

@@ -62,7 +62,9 @@ def config_changed():
if ceph.is_quorum():
for dev in utils.config_get('osd-devices').split(' '):
osdize_and_activate(dev)
osdize(dev)
subprocess.call(['udevadm', 'trigger',
'--subsystem-match=block', '--action=add'])
utils.juju_log('INFO', 'End config-changed hook.')
@@ -127,18 +129,23 @@ def bootstrap_monitor_cluster():
os.unlink(keyring)
def osdize_and_activate(dev):
def osdize(dev):
# XXX hack for instances
subprocess.call(['umount', '/mnt'])
if ceph.is_osd_disk(dev):
utils.juju_log('INFO',
'Looks like {} is already an OSD, skipping.'
.format(dev))
return
if subprocess.call(['grep', '-wqs', dev + '1', '/proc/mounts']) == 0:
utils.juju_log('INFO',
'Looks like {} is in use, skipping.'.format(dev))
else:
if os.path.exists(dev):
subprocess.call(['ceph-disk-prepare', dev])
subprocess.call(['udevadm', 'trigger',
'--subsystem-match=block', '--action=add'])
return
if os.path.exists(dev):
subprocess.call(['ceph-disk-prepare', dev])
def mon_relation():
@@ -151,7 +158,9 @@ def mon_relation():
ceph.wait_for_quorum()
for dev in utils.config_get('osd-devices').split(' '):
osdize_and_activate(dev)
osdize(dev)
subprocess.call(['udevadm', 'trigger',
'--subsystem-match=block', '--action=add'])
else:
utils.juju_log('INFO',
'Not enough mons ({}), punting.'.format(
@@ -167,11 +176,20 @@ def upgrade_charm():
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.
subprocess.call(['start', 'ceph-mon-all-starter'])
subprocess.call(['udevadm', 'trigger',
'--subsystem-match=block', '--action=add'])
hooks = {
'config-changed': config_changed,
'install': install,
'mon-relation-departed': mon_relation,
'mon-relation-joined': mon_relation,
'start': start,
'upgrade-charm': upgrade_charm,
}

View File

@@ -89,7 +89,7 @@ def relation_ids(relation):
'relation-ids',
relation
]
return subprocess.check_output(cmd).split()
return subprocess.check_output(cmd).split() # IGNORE:E1103
def relation_list(rid):
@@ -97,7 +97,7 @@ def relation_list(rid):
'relation-list',
'-r', rid,
]
return subprocess.check_output(cmd).split()
return subprocess.check_output(cmd).split() # IGNORE:E1103
def relation_get(attribute, unit=None, rid=None):
@@ -110,7 +110,7 @@ def relation_get(attribute, unit=None, rid=None):
cmd.append(attribute)
if unit:
cmd.append(unit)
return subprocess.check_output(cmd).strip()
return subprocess.check_output(cmd).strip() # IGNORE:E1103
def relation_set(**kwargs):
@@ -127,7 +127,7 @@ def unit_get(attribute):
'unit-get',
attribute
]
return subprocess.check_output(cmd).strip()
return subprocess.check_output(cmd).strip() # IGNORE:E1103
def config_get(attribute):
@@ -135,7 +135,7 @@ def config_get(attribute):
'config-get',
attribute
]
return subprocess.check_output(cmd).strip()
return subprocess.check_output(cmd).strip() # IGNORE:E1103
def get_unit_hostname():
@@ -148,4 +148,4 @@ def get_host_ip(hostname=unit_get('private-address')):
'+short',
hostname
]
return subprocess.check_output(cmd).strip()
return subprocess.check_output(cmd).strip() # IGNORE:E1103

View File

@@ -1 +1 @@
56
65