Add removal confirmations and zap disk before add

This commit is contained in:
Joshua Boniface 2019-06-21 15:52:28 -04:00
parent 26a4b3b757
commit ef272b0b7d
2 changed files with 82 additions and 35 deletions

View File

@ -1133,11 +1133,22 @@ def ceph_osd():
default=1.0, show_default=True, default=1.0, show_default=True,
help='Weight of the OSD within the CRUSH map.' help='Weight of the OSD within the CRUSH map.'
) )
def ceph_osd_add(node, device, weight): @click.option(
'--yes', 'yes',
is_flag=True, default=False,
help='Pre-confirm the disk destruction.'
)
def ceph_osd_add(node, device, weight, yes):
""" """
Add a new Ceph OSD on node NODE with block device DEVICE to the cluster. Add a new Ceph OSD on node NODE with block device DEVICE to the cluster.
""" """
if not yes:
click.echo('DANGER: This will completely destroy all data on disk {}.'.format(device))
choice = input('Are you sure you want to do this? (y/N) ')
if choice != 'y' and choice != 'Y':
exit(0)
zk_conn = pvc_common.startZKConnection(zk_host) zk_conn = pvc_common.startZKConnection(zk_host)
retcode, retmsg = pvc_ceph.add_osd(zk_conn, node, device, weight) retcode, retmsg = pvc_ceph.add_osd(zk_conn, node, device, weight)
cleanup(retcode, retmsg, zk_conn) cleanup(retcode, retmsg, zk_conn)
@ -1149,11 +1160,22 @@ def ceph_osd_add(node, device, weight):
@click.argument( @click.argument(
'osdid' 'osdid'
) )
def ceph_osd_remove(osdid): @click.option(
'--yes', 'yes',
is_flag=True, default=False,
help='Pre-confirm the removal.'
)
def ceph_osd_remove(osdid, yes):
""" """
Remove a Ceph OSD with ID OSDID from the cluster. Remove a Ceph OSD with ID OSDID from the cluster.
""" """
if not yes:
click.echo('DANGER: This will completely remove OSD {} from cluster. OSDs will rebalance.'.format(osdid))
choice = input('Are you sure you want to do this? (y/N) ')
if choice != 'y' and choice != 'Y':
exit(0)
zk_conn = pvc_common.startZKConnection(zk_host) zk_conn = pvc_common.startZKConnection(zk_host)
retcode, retmsg = pvc_ceph.remove_osd(zk_conn, osdid) retcode, retmsg = pvc_ceph.remove_osd(zk_conn, osdid)
cleanup(retcode, retmsg, zk_conn) cleanup(retcode, retmsg, zk_conn)
@ -1282,23 +1304,27 @@ def ceph_pool_add(name, pgs):
@click.argument( @click.argument(
'name' 'name'
) )
def ceph_pool_remove(name): @click.option(
'--yes', 'yes',
is_flag=True, default=False,
help='Pre-confirm the removal.'
)
def ceph_pool_remove(name, yes):
""" """
Remove a Ceph RBD pool with name NAME and all volumes on it. Remove a Ceph RBD pool with name NAME and all volumes on it.
""" """
click.echo('DANGER: This will completely remove pool {} and all data contained in it.'.format(name)) if not yes:
choice = input('Are you sure you want to do this? (y/N) ') click.echo('DANGER: This will completely remove pool {} and all data contained in it.'.format(name))
if choice == 'y' or choice == 'Y': choice = input('Are you sure you want to do this? (y/N) ')
pool_name_check = input('Please enter the pool name to confirm: ') if choice != 'y' and choice != 'Y':
if pool_name_check == name: pool_name_check = input('Please enter the pool name to confirm: ')
zk_conn = pvc_common.startZKConnection(zk_host) if pool_name_check != name:
retcode, retmsg = pvc_ceph.remove_pool(zk_conn, name) exit(0)
cleanup(retcode, retmsg, zk_conn)
else: zk_conn = pvc_common.startZKConnection(zk_host)
click.echo('Aborting.') retcode, retmsg = pvc_ceph.remove_pool(zk_conn, name)
else: cleanup(retcode, retmsg, zk_conn)
click.echo('Aborting.')
############################################################################### ###############################################################################
# pvc ceph pool list # pvc ceph pool list
@ -1358,19 +1384,25 @@ def ceph_volume_add(pool, name, size):
@click.argument( @click.argument(
'name' 'name'
) )
def ceph_volume_remove(pool, name): @click.option(
'--yes', 'yes',
is_flag=True, default=False,
help='Pre-confirm the removal.'
)
def ceph_volume_remove(pool, name, yes):
""" """
Remove a Ceph RBD volume with name NAME from pool POOL. Remove a Ceph RBD volume with name NAME from pool POOL.
""" """
click.echo('DANGER: This will completely remove volume {} from pool {} and all data contained in it.'.format(name, pool)) if not yes:
choice = input('Are you sure you want to do this? (y/N) ') click.echo('DANGER: This will completely remove volume {} from pool {} and all data contained in it.'.format(name, pool))
if choice == 'y' or choice == 'Y': choice = input('Are you sure you want to do this? (y/N) ')
zk_conn = pvc_common.startZKConnection(zk_host) if choice != 'y' and choice != 'Y':
retcode, retmsg = pvc_ceph.remove_volume(zk_conn, pool, name) exit(0)
cleanup(retcode, retmsg, zk_conn)
else: zk_conn = pvc_common.startZKConnection(zk_host)
click.echo('Aborting.') retcode, retmsg = pvc_ceph.remove_volume(zk_conn, pool, name)
cleanup(retcode, retmsg, zk_conn)
############################################################################### ###############################################################################
# pvc ceph volume list # pvc ceph volume list
@ -1438,19 +1470,25 @@ def ceph_volume_snapshot_add(pool, volume, name):
@click.argument( @click.argument(
'name' 'name'
) )
def ceph_volume_snapshot_remove(pool, volume, name): @click.option(
'--yes', 'yes',
is_flag=True, default=False,
help='Pre-confirm the removal.'
)
def ceph_volume_snapshot_remove(pool, volume, name, yes):
""" """
Remove a Ceph RBD volume with name NAME from pool POOL. Remove a Ceph RBD volume with name NAME from pool POOL.
""" """
click.echo('DANGER: This will completely remove snapshot {} from volume {}/{} and all data contained in it.'.format(name, pool, volume)) if not yes:
choice = input('Are you sure you want to do this? (y/N) ') click.echo('DANGER: This will completely remove snapshot {} from volume {}/{} and all data contained in it.'.format(name, pool, volume))
if choice == 'y' or choice == 'Y': choice = input('Are you sure you want to do this? (y/N) ')
zk_conn = pvc_common.startZKConnection(zk_host) if choice != 'y' and choice != 'Y':
retcode, retmsg = pvc_ceph.remove_snapshot(zk_conn, pool, volume, name) exit(0)
cleanup(retcode, retmsg, zk_conn)
else: zk_conn = pvc_common.startZKConnection(zk_host)
click.echo('Aborting.') retcode, retmsg = pvc_ceph.remove_snapshot(zk_conn, pool, volume, name)
cleanup(retcode, retmsg, zk_conn)
############################################################################### ###############################################################################
# pvc ceph volume snapshot list # pvc ceph volume snapshot list
@ -1512,7 +1550,7 @@ def init_cluster(yes):
if not yes: if not yes:
click.echo('DANGER: This will remove any existing cluster on these coordinators and create a new cluster. Any existing resources on the old cluster will be left abandoned.') click.echo('DANGER: This will remove any existing cluster on these coordinators and create a new cluster. Any existing resources on the old cluster will be left abandoned.')
choice = input('Are you sure you want to do this? (y/N) ') choice = input('Are you sure you want to do this? (y/N) ')
if choice != 'y' or choice != 'Y': if choice != 'y' and choice != 'Y':
exit(0) exit(0)
import pvc_init import pvc_init

View File

@ -89,7 +89,16 @@ def add_osd(zk_conn, logger, node, device, weight):
print(stderr) print(stderr)
raise raise
# 3. Create the OSD for real # 3a. Zap the disk to ensure it is ready to go
logger.out('Zapping disk {}'.format(device), state='i')
retcode, stdout, stderr = common.run_os_command('ceph-volume lvm zap --destroy {}'.format(device))
if retcode:
print('ceph-volume lvm zap')
print(stdout)
print(stderr)
raise
# 3b. Create the OSD for real
logger.out('Preparing LVM for new OSD disk with ID {} on {}'.format(osd_id, device), state='i') logger.out('Preparing LVM for new OSD disk with ID {} on {}'.format(osd_id, device), state='i')
retcode, stdout, stderr = common.run_os_command( retcode, stdout, stderr = common.run_os_command(
'ceph-volume lvm prepare --bluestore --data {device}'.format( 'ceph-volume lvm prepare --bluestore --data {device}'.format(