diff --git a/api-daemon/pvcapid/flaskapi.py b/api-daemon/pvcapid/flaskapi.py index 6458a022..4605cca3 100755 --- a/api-daemon/pvcapid/flaskapi.py +++ b/api-daemon/pvcapid/flaskapi.py @@ -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//node') diff --git a/api-daemon/pvcapid/helper.py b/api-daemon/pvcapid/helper.py index d39a43e8..c3ab0bf7 100755 --- a/api-daemon/pvcapid/helper.py +++ b/api-daemon/pvcapid/helper.py @@ -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: diff --git a/docs/manuals/swagger.json b/docs/manuals/swagger.json index 45b38dcf..61ceb3e6 100644 --- a/docs/manuals/swagger.json +++ b/docs/manuals/swagger.json @@ -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": {