Allow overwrite during init command
This commit is contained in:
@ -260,17 +260,27 @@ api.add_resource(API_Logout, '/logout')
|
||||
# /initialize
|
||||
class API_Initialize(Resource):
|
||||
@RequestParser([
|
||||
{'name': 'yes-i-really-mean-it', 'required': True, 'helptext': "Initialization is destructive; please confirm with the argument 'yes-i-really-mean-it'."}
|
||||
{'name': 'overwrite', 'required': False},
|
||||
{'name': 'yes-i-really-mean-it', 'required': True, 'helptext': "Initialization is destructive; please confirm with the argument 'yes-i-really-mean-it'."},
|
||||
])
|
||||
@Authenticator
|
||||
def post(self, reqargs):
|
||||
"""
|
||||
Initialize a new PVC cluster
|
||||
Note: Normally used only once during cluster bootstrap; checks for the existence of the "/primary_node" key before proceeding and returns 400 if found
|
||||
|
||||
If the 'overwrite' option is not True, the cluster will return 400 if the `/primary_node` key is found. If 'overwrite' is True, the existing cluster
|
||||
data will be erased and new, empty data written in its place.
|
||||
|
||||
All node daemons should be stopped before running this command, and the API daemon started manually to avoid undefined behavior.
|
||||
---
|
||||
tags:
|
||||
- root
|
||||
parameters:
|
||||
- in: query
|
||||
name: overwrite
|
||||
type: bool
|
||||
required: false
|
||||
description: A flag to enable or disable (default) overwriting existing data
|
||||
- in: query
|
||||
name: yes-i-really-mean-it
|
||||
type: string
|
||||
@ -289,7 +299,10 @@ class API_Initialize(Resource):
|
||||
400:
|
||||
description: Bad request
|
||||
"""
|
||||
if api_helper.initialize_cluster():
|
||||
if reqargs.get('overwrite', False):
|
||||
overwrite_flag = True
|
||||
|
||||
if api_helper.initialize_cluster(overwrite=overwrite_flag):
|
||||
return {"message": "Successfully initialized a new PVC cluster"}, 200
|
||||
else:
|
||||
return {"message": "PVC cluster already initialized"}, 400
|
||||
|
@ -41,16 +41,41 @@ import daemon_lib.ceph as pvc_ceph
|
||||
# Cluster base functions
|
||||
#
|
||||
@ZKConnection(config)
|
||||
def initialize_cluster(zkhandler):
|
||||
def initialize_cluster(zkhandler, overwrite=False):
|
||||
"""
|
||||
Initialize a new cluster
|
||||
"""
|
||||
# Abort if we've initialized the cluster before
|
||||
if zkhandler.exists('/primary_node'):
|
||||
if zkhandler.exists('/primary_node') and not overwrite:
|
||||
return False
|
||||
|
||||
if overwrite:
|
||||
# Delete the existing keys; ignore any errors
|
||||
status = zkhandler.delete([
|
||||
'/primary_node',
|
||||
'/upstream_ip',
|
||||
'/maintenance',
|
||||
'/nodes',
|
||||
'/domains',
|
||||
'/networks',
|
||||
'/ceph',
|
||||
'/ceph/osds',
|
||||
'/ceph/pools',
|
||||
'/ceph/volumes',
|
||||
'/ceph/snapshots',
|
||||
'/cmd',
|
||||
'/cmd/domains',
|
||||
'/cmd/ceph',
|
||||
'/locks',
|
||||
'/locks/flush_lock',
|
||||
'/locks/primary_node'
|
||||
], recursive=True)
|
||||
|
||||
if not status:
|
||||
return False
|
||||
|
||||
# Create the root keys
|
||||
zkhandler.write([
|
||||
status = zkhandler.write([
|
||||
('/primary_node', 'none'),
|
||||
('/upstream_ip', 'none'),
|
||||
('/maintenance', 'False'),
|
||||
@ -70,7 +95,7 @@ def initialize_cluster(zkhandler):
|
||||
('/locks/primary_node', ''),
|
||||
])
|
||||
|
||||
return True
|
||||
return status
|
||||
|
||||
|
||||
@ZKConnection(config)
|
||||
|
Reference in New Issue
Block a user