Support OSD out/in and commands
This commit is contained in:
@ -241,6 +241,86 @@ def remove_osd(zk_conn, logger, osd_id, osd_obj):
|
||||
logger.out('Failed to purge OSD disk with ID {}: {}'.format(osd_id, e), state='e')
|
||||
return False
|
||||
|
||||
def in_osd(zk_conn, logger, osd_id):
|
||||
# We are ready to create a new pool on this node
|
||||
logger.out('Setting OSD {} in'.format(osd_id), state='i')
|
||||
try:
|
||||
# 1. Set it in
|
||||
retcode, stdout, stderr = common.run_os_command('ceph osd in {}'.format(osd_id))
|
||||
if retcode:
|
||||
print('ceph osd in')
|
||||
print(stdout)
|
||||
print(stderr)
|
||||
raise
|
||||
|
||||
# Log it
|
||||
logger.out('Set OSD {} in'.format(osd_id), state='o')
|
||||
return True
|
||||
except Exception as e:
|
||||
# Log it
|
||||
logger.out('Failed to set OSD {} in: {}'.format(osd_id, e), state='e')
|
||||
return False
|
||||
|
||||
def out_osd(zk_conn, logger, osd_id):
|
||||
# We are ready to create a new pool on this node
|
||||
logger.out('Settoutg OSD {} out'.format(osd_id), state='i')
|
||||
try:
|
||||
# 1. Set it out
|
||||
retcode, stdout, stderr = common.run_os_command('ceph osd out {}'.format(osd_id))
|
||||
if retcode:
|
||||
proutt('ceph osd out')
|
||||
proutt(stdout)
|
||||
proutt(stderr)
|
||||
raise
|
||||
|
||||
# Log it
|
||||
logger.out('Set OSD {} out'.format(osd_id), state='o')
|
||||
return True
|
||||
except Exception as e:
|
||||
# Log it
|
||||
logger.out('Failed to set OSD {} out: {}'.format(osd_id, e), state='e')
|
||||
return False
|
||||
|
||||
def set_property(zk_conn, logger, option):
|
||||
# We are ready to create a new pool on this node
|
||||
logger.out('Setting OSD property {}'.format(option), state='i')
|
||||
try:
|
||||
# 1. Set it in
|
||||
retcode, stdout, stderr = common.run_os_command('ceph osd set {}'.format(option))
|
||||
if retcode:
|
||||
prsett('ceph osd set')
|
||||
print(stdout)
|
||||
print(stderr)
|
||||
raise
|
||||
|
||||
# Log it
|
||||
logger.out('Set OSD property {}'.format(option), state='o')
|
||||
return True
|
||||
except Exception as e:
|
||||
# Log it
|
||||
logger.out('Failed to set OSD property {}: {}'.format(option, e), state='e')
|
||||
return False
|
||||
|
||||
def unset_property(zk_conn, logger, option):
|
||||
# We are ready to create a new pool on this node
|
||||
logger.out('Unsetting OSD property {}'.format(option), state='i')
|
||||
try:
|
||||
# 1. Set it in
|
||||
retcode, stdout, stderr = common.run_os_command('ceph osd unset {}'.format(option))
|
||||
if retcode:
|
||||
prunsett('ceph osd unset')
|
||||
print(stdout)
|
||||
print(stderr)
|
||||
raise
|
||||
|
||||
# Log it
|
||||
logger.out('Unset OSD property {}'.format(option), state='o')
|
||||
return True
|
||||
except Exception as e:
|
||||
# Log it
|
||||
logger.out('Failed to unset OSD property {}: {}'.format(option, e), state='e')
|
||||
return False
|
||||
|
||||
class CephPoolInstance(object):
|
||||
def __init__(self, zk_conn, this_node, name):
|
||||
self.zk_conn = zk_conn
|
||||
|
@ -707,6 +707,89 @@ def cmd(data, stat, event=''):
|
||||
zkhandler.writedata(zk_conn, {'/ceph/cmd': 'failure-{}'.format(data)})
|
||||
# Wait 0.5 seconds before we free the lock, to ensure the client hits the lock
|
||||
time.sleep(0.5)
|
||||
# Online an OSD
|
||||
elif command == 'osd_in':
|
||||
osd_id = args
|
||||
|
||||
# Verify osd_id is in the list
|
||||
if d_osd[osd_id] and d_osd[osd_id].node == this_node.name:
|
||||
# Lock the command queue
|
||||
lock = zkhandler.writelock(zk_conn, '/ceph/cmd')
|
||||
with lock:
|
||||
# Online the OSD
|
||||
result = CephInstance.in_osd(zk_conn, logger, osd_id)
|
||||
# Command succeeded
|
||||
if result:
|
||||
# Update the command queue
|
||||
zkhandler.writedata(zk_conn, {'/ceph/cmd': 'success-{}'.format(data)})
|
||||
# Command failed
|
||||
else:
|
||||
# Update the command queue
|
||||
zkhandler.writedata(zk_conn, {'/ceph/cmd': 'failure-{}'.format(data)})
|
||||
# Wait 0.5 seconds before we free the lock, to ensure the client hits the lock
|
||||
time.sleep(0.5)
|
||||
# Offline an OSD
|
||||
elif command == 'osd_out':
|
||||
osd_id = args
|
||||
|
||||
# Verify osd_id is in the list
|
||||
if d_osd[osd_id] and d_osd[osd_id].node == this_node.name:
|
||||
# Lock the command queue
|
||||
lock = zkhandler.writelock(zk_conn, '/ceph/cmd')
|
||||
with lock:
|
||||
# Offline the OSD
|
||||
result = CephInstance.out_osd(zk_conn, logger, osd_id)
|
||||
# Command succeeded
|
||||
if result:
|
||||
# Update the command queue
|
||||
zkhandler.writedata(zk_conn, {'/ceph/cmd': 'success-{}'.format(data)})
|
||||
# Command failed
|
||||
else:
|
||||
# Update the command queue
|
||||
zkhandler.writedata(zk_conn, {'/ceph/cmd': 'failure-{}'.format(data)})
|
||||
# Wait 0.5 seconds before we free the lock, to ensure the client hits the lock
|
||||
time.sleep(0.5)
|
||||
# Set a property
|
||||
elif command == 'osd_set':
|
||||
option = args
|
||||
|
||||
if this_node.router_state == 'primary':
|
||||
# Lock the command queue
|
||||
lock = zkhandler.writelock(zk_conn, '/ceph/cmd')
|
||||
with lock:
|
||||
# Set the property
|
||||
result = CephInstance.set_property(zk_conn, logger, option)
|
||||
# Command succeeded
|
||||
if result:
|
||||
# Update the command queue
|
||||
zkhandler.writedata(zk_conn, {'/ceph/cmd': 'success-{}'.format(data)})
|
||||
# Command failed
|
||||
else:
|
||||
# Update the command queue
|
||||
zkhandler.writedata(zk_conn, {'/ceph/cmd': 'failure-{}'.format(data)})
|
||||
# Wait 0.5 seconds before we free the lock, to ensure the client hits the lock
|
||||
time.sleep(0.5)
|
||||
# Unset a property
|
||||
elif command == 'osd_unset':
|
||||
option = args
|
||||
|
||||
if this_node.router_state == 'primary':
|
||||
# Lock the command queue
|
||||
lock = zkhandler.writelock(zk_conn, '/ceph/cmd')
|
||||
with lock:
|
||||
# Unset the property
|
||||
result = CephInstance.unset_property(zk_conn, logger, option)
|
||||
# Command succeeded
|
||||
if result:
|
||||
# Update the command queue
|
||||
zkhandler.writedata(zk_conn, {'/ceph/cmd': 'success-{}'.format(data)})
|
||||
# Command failed
|
||||
else:
|
||||
# Update the command queue
|
||||
zkhandler.writedata(zk_conn, {'/ceph/cmd': 'failure-{}'.format(data)})
|
||||
# Wait 0.5 seconds before we free the lock, to ensure the client hits the lock
|
||||
time.sleep(0.5)
|
||||
|
||||
# Adding a new pool
|
||||
if command == 'pool_add':
|
||||
name, pgs = args.split(',')
|
||||
|
Reference in New Issue
Block a user