Add wait support to API commands

References #72
This commit is contained in:
Joshua Boniface 2020-02-19 09:51:19 -05:00
parent 07577a52a9
commit 99f579e41a
3 changed files with 41 additions and 17 deletions

View File

@ -1264,7 +1264,8 @@ class API_VM_State(Resource):
return api_helper.vm_state(vm)
@RequestParser([
{ 'name': 'state', 'choices': ('start', 'shutdown', 'stop', 'restart', 'disable'), 'helptext': "A valid state must be specified", 'required': True }
{ 'name': 'state', 'choices': ('start', 'shutdown', 'stop', 'restart', 'disable'), 'helptext': "A valid state must be specified", 'required': True },
{ 'name': 'wait' }
])
@Authenticator
def post(self, vm, reqargs):
@ -1285,6 +1286,10 @@ class API_VM_State(Resource):
- stop
- restart
- disable
- in: query
name: wait
type: boolean
description: Whether to block waiting for the state change to complete
responses:
200:
description: OK
@ -1298,15 +1303,16 @@ class API_VM_State(Resource):
id: Message
"""
state = reqargs.get('state', None)
wait = bool(strtobool(reqargs.get('wait', 'false')))
if state == 'start':
return api_helper.vm_start(vm)
if state == 'shutdown':
return api_helper.vm_shutdown(vm)
return api_helper.vm_shutdown(vm, wait)
if state == 'stop':
return api_helper.vm_stop(vm)
if state == 'restart':
return api_helper.vm_restart(vm)
return api_helper.vm_restart(vm, wait)
if state == 'disable':
return api_helper.vm_disable(vm)
abort(400)
@ -1348,7 +1354,8 @@ class API_VM_Node(Resource):
@RequestParser([
{ 'name': 'action', 'choices': ('migrate', 'unmigrate', 'move'), 'helptext': "A valid action must be specified", 'required': True },
{ 'name': 'node' },
{ 'name': 'force' }
{ 'name': 'force' },
{ 'name': 'wait' }
])
@Authenticator
def post(self, vm, reqargs):
@ -1375,6 +1382,10 @@ class API_VM_Node(Resource):
name: force
type: boolean
description: Whether to force an already-migrated VM to a new node
- in: query
name: wait
type: boolean
description: Whether to block waiting for the migration to complete
responses:
200:
description: OK
@ -1390,13 +1401,14 @@ class API_VM_Node(Resource):
action = reqargs.get('action', None)
node = reqargs.get('node', None)
force = bool(strtobool(reqargs.get('force', 'false')))
wait = bool(strtobool(reqargs.get('wait', 'false')))
if action == 'move':
return api_helper.vm_move(vm, node)
return api_helper.vm_move(vm, node, wait)
if action == 'migrate':
return api_helper.vm_migrate(vm, node, force)
return api_helper.vm_migrate(vm, node, force, wait)
if action == 'unmigrate':
return api_helper.vm_unmigrate(vm)
return api_helper.vm_unmigrate(vm, wait)
abort(400)
api.add_resource(API_VM_Node, '/vm/<vm>/node')

View File

@ -579,12 +579,12 @@ def vm_start(name):
}
return output, retcode
def vm_restart(name):
def vm_restart(name, wait):
"""
Restart a VM in the PVC cluster.
"""
zk_conn = pvc_common.startZKConnection(config['coordinators'])
retflag, retdata = pvc_vm.restart_vm(zk_conn, name)
retflag, retdata = pvc_vm.restart_vm(zk_conn, name, wait)
pvc_common.stopZKConnection(zk_conn)
if retflag:
@ -597,12 +597,12 @@ def vm_restart(name):
}
return output, retcode
def vm_shutdown(name):
def vm_shutdown(name, wait):
"""
Shutdown a VM in the PVC cluster.
"""
zk_conn = pvc_common.startZKConnection(config['coordinators'])
retflag, retdata = pvc_vm.shutdown_vm(zk_conn, name)
retflag, retdata = pvc_vm.shutdown_vm(zk_conn, name, wait)
pvc_common.stopZKConnection(zk_conn)
if retflag:
@ -651,12 +651,12 @@ def vm_disable(name):
}
return output, retcode
def vm_move(name, node):
def vm_move(name, node, wait):
"""
Move a VM to another node.
"""
zk_conn = pvc_common.startZKConnection(config['coordinators'])
retflag, retdata = pvc_vm.move_vm(zk_conn, name, node)
retflag, retdata = pvc_vm.move_vm(zk_conn, name, node, wait)
pvc_common.stopZKConnection(zk_conn)
if retflag:
@ -669,12 +669,12 @@ def vm_move(name, node):
}
return output, retcode
def vm_migrate(name, node, flag_force):
def vm_migrate(name, node, flag_force, wait):
"""
Temporarily migrate a VM to another node.
"""
zk_conn = pvc_common.startZKConnection(config['coordinators'])
retflag, retdata = pvc_vm.migrate_vm(zk_conn, name, node, flag_force)
retflag, retdata = pvc_vm.migrate_vm(zk_conn, name, node, flag_force, wait)
pvc_common.stopZKConnection(zk_conn)
if retflag:
@ -687,12 +687,12 @@ def vm_migrate(name, node, flag_force):
}
return output, retcode
def vm_unmigrate(name):
def vm_unmigrate(name, wait):
"""
Unmigrate a migrated VM.
"""
zk_conn = pvc_common.startZKConnection(config['coordinators'])
retflag, retdata = pvc_vm.unmigrate_vm(zk_conn, name)
retflag, retdata = pvc_vm.unmigrate_vm(zk_conn, name, wait)
pvc_common.stopZKConnection(zk_conn)
if retflag:

View File

@ -5491,6 +5491,12 @@
"in": "query",
"name": "force",
"type": "boolean"
},
{
"description": "Whether to block waiting for the migration to complete",
"in": "query",
"name": "wait",
"type": "boolean"
}
],
"responses": {
@ -5551,6 +5557,12 @@
"name": "state",
"required": true,
"type": "string"
},
{
"description": "Whether to block waiting for the state change to complete",
"in": "query",
"name": "wait",
"type": "boolean"
}
],
"responses": {