Skip to content

Instantly share code, notes, and snippets.

@cholcombe973
Created June 7, 2016 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cholcombe973/2a6601456cd0ae1e6612695776b7e5a9 to your computer and use it in GitHub Desktop.
Save cholcombe973/2a6601456cd0ae1e6612695776b7e5a9 to your computer and use it in GitHub Desktop.
def related_osds(num_units=3):
'''
Determine whether there are OSD units currently related
@param num_units: The minimum number of units required
@return: boolean indicating whether the required number of
units where detected.
'''
for r_id in relation_ids('osd'):
if len(related_units(r_id)) >= num_units:
# Osds are related but have they actually come up?
try:
in_osds = osds_in_cluster()
up_osds = osds_up_in_cluster()
if in_osds >= num_units and up_osds >= num_units:
return True
else:
return False
except ValueError:
# Unable to query Ceph. Play it safe
return False
return False
def osds_in_cluster():
"""
Query Ceph and return how many osds are marked as IN in the cluster.
:return: The number of osds marked in in the cluster.
"""
# TODO: Refactor to use ceph_api once layers land
output = subprocess.check_output(['ceph', '-s', '--format=json'])
try:
j = json.loads(output)
if j['osdmap']['osdmap']['num_in_osds']:
return j['osdmap']['osdmap']['num_in_osds']
else:
return None
except ValueError as err:
log("Unable to decode json: {}".format(output), level=ERROR)
raise err
def osds_up_in_cluster():
"""
Query Ceph and return how many osds are marked as UP in the cluster.
:return: The number of osds marked up in the cluster.
"""
# TODO: Refactor to use ceph_api once layers land
output = subprocess.check_output(['ceph', '-s', '--format=json'])
try:
j = json.loads(output)
if j['osdmap']['osdmap']['num_up_osds']:
return j['osdmap']['osdmap']['num_up_osds']
else:
return None
except ValueError as err:
log("Unable to decode json: {}".format(output), level=ERROR)
raise err
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment