Allow overwrite during init command

This commit is contained in:
2021-05-30 23:59:17 -04:00
parent c7992000eb
commit a1969eb981
4 changed files with 62 additions and 12 deletions

View File

@ -25,16 +25,17 @@ import cli_lib.ansiprint as ansiprint
from cli_lib.common import call_api
def initialize(config):
def initialize(config, overwrite=False):
"""
Initialize the PVC cluster
API endpoint: GET /api/v1/initialize
API arguments: yes-i-really-mean-it
API arguments: overwrite, yes-i-really-mean-it
API schema: {json_data_object}
"""
params = {
'yes-i-really-mean-it': 'yes'
'yes-i-really-mean-it': 'yes',
'overwrite': overwrite
}
response = call_api(config, 'post', '/initialize', params=params)

View File

@ -4304,15 +4304,26 @@ def task_restore(filename, confirm_flag):
# pvc task init
###############################################################################
@click.command(name='init', short_help='Initialize a new cluster.')
@click.option(
'-o', '--overwite', 'overwrite_flag',
is_flag=True, default=False,
help='Remove and overwrite any existing data'
)
@click.option(
'-y', '--yes', 'confirm_flag',
is_flag=True, default=False,
help='Confirm the initialization'
)
@cluster_req
def task_init(confirm_flag):
def task_init(confirm_flag, overwrite_flag):
"""
Perform initialization of a new PVC cluster.
If the '-o'/'--overwrite' option is specified, all existing data in the cluster will be deleted
before new, empty data is written.
It is not advisable to do this against a running cluster - all node daemons should be stopped
first and the API daemon started manually before running this command.
"""
if not confirm_flag and not config['unsafe']:
@ -4324,7 +4335,7 @@ def task_init(confirm_flag):
# Easter-egg
click.echo("Some music while we're Layin' Pipe? https://youtu.be/sw8S_Kv89IU")
retcode, retmsg = pvc_cluster.initialize(config)
retcode, retmsg = pvc_cluster.initialize(config, overwrite_flag)
cleanup(retcode, retmsg)