parent
07577a52a9
commit
99f579e41a
|
@ -1264,7 +1264,8 @@ class API_VM_State(Resource):
|
||||||
return api_helper.vm_state(vm)
|
return api_helper.vm_state(vm)
|
||||||
|
|
||||||
@RequestParser([
|
@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
|
@Authenticator
|
||||||
def post(self, vm, reqargs):
|
def post(self, vm, reqargs):
|
||||||
|
@ -1285,6 +1286,10 @@ class API_VM_State(Resource):
|
||||||
- stop
|
- stop
|
||||||
- restart
|
- restart
|
||||||
- disable
|
- disable
|
||||||
|
- in: query
|
||||||
|
name: wait
|
||||||
|
type: boolean
|
||||||
|
description: Whether to block waiting for the state change to complete
|
||||||
responses:
|
responses:
|
||||||
200:
|
200:
|
||||||
description: OK
|
description: OK
|
||||||
|
@ -1298,15 +1303,16 @@ class API_VM_State(Resource):
|
||||||
id: Message
|
id: Message
|
||||||
"""
|
"""
|
||||||
state = reqargs.get('state', None)
|
state = reqargs.get('state', None)
|
||||||
|
wait = bool(strtobool(reqargs.get('wait', 'false')))
|
||||||
|
|
||||||
if state == 'start':
|
if state == 'start':
|
||||||
return api_helper.vm_start(vm)
|
return api_helper.vm_start(vm)
|
||||||
if state == 'shutdown':
|
if state == 'shutdown':
|
||||||
return api_helper.vm_shutdown(vm)
|
return api_helper.vm_shutdown(vm, wait)
|
||||||
if state == 'stop':
|
if state == 'stop':
|
||||||
return api_helper.vm_stop(vm)
|
return api_helper.vm_stop(vm)
|
||||||
if state == 'restart':
|
if state == 'restart':
|
||||||
return api_helper.vm_restart(vm)
|
return api_helper.vm_restart(vm, wait)
|
||||||
if state == 'disable':
|
if state == 'disable':
|
||||||
return api_helper.vm_disable(vm)
|
return api_helper.vm_disable(vm)
|
||||||
abort(400)
|
abort(400)
|
||||||
|
@ -1348,7 +1354,8 @@ class API_VM_Node(Resource):
|
||||||
@RequestParser([
|
@RequestParser([
|
||||||
{ 'name': 'action', 'choices': ('migrate', 'unmigrate', 'move'), 'helptext': "A valid action must be specified", 'required': True },
|
{ 'name': 'action', 'choices': ('migrate', 'unmigrate', 'move'), 'helptext': "A valid action must be specified", 'required': True },
|
||||||
{ 'name': 'node' },
|
{ 'name': 'node' },
|
||||||
{ 'name': 'force' }
|
{ 'name': 'force' },
|
||||||
|
{ 'name': 'wait' }
|
||||||
])
|
])
|
||||||
@Authenticator
|
@Authenticator
|
||||||
def post(self, vm, reqargs):
|
def post(self, vm, reqargs):
|
||||||
|
@ -1375,6 +1382,10 @@ class API_VM_Node(Resource):
|
||||||
name: force
|
name: force
|
||||||
type: boolean
|
type: boolean
|
||||||
description: Whether to force an already-migrated VM to a new node
|
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:
|
responses:
|
||||||
200:
|
200:
|
||||||
description: OK
|
description: OK
|
||||||
|
@ -1390,13 +1401,14 @@ class API_VM_Node(Resource):
|
||||||
action = reqargs.get('action', None)
|
action = reqargs.get('action', None)
|
||||||
node = reqargs.get('node', None)
|
node = reqargs.get('node', None)
|
||||||
force = bool(strtobool(reqargs.get('force', 'false')))
|
force = bool(strtobool(reqargs.get('force', 'false')))
|
||||||
|
wait = bool(strtobool(reqargs.get('wait', 'false')))
|
||||||
|
|
||||||
if action == 'move':
|
if action == 'move':
|
||||||
return api_helper.vm_move(vm, node)
|
return api_helper.vm_move(vm, node, wait)
|
||||||
if action == 'migrate':
|
if action == 'migrate':
|
||||||
return api_helper.vm_migrate(vm, node, force)
|
return api_helper.vm_migrate(vm, node, force, wait)
|
||||||
if action == 'unmigrate':
|
if action == 'unmigrate':
|
||||||
return api_helper.vm_unmigrate(vm)
|
return api_helper.vm_unmigrate(vm, wait)
|
||||||
abort(400)
|
abort(400)
|
||||||
api.add_resource(API_VM_Node, '/vm/<vm>/node')
|
api.add_resource(API_VM_Node, '/vm/<vm>/node')
|
||||||
|
|
||||||
|
|
|
@ -579,12 +579,12 @@ def vm_start(name):
|
||||||
}
|
}
|
||||||
return output, retcode
|
return output, retcode
|
||||||
|
|
||||||
def vm_restart(name):
|
def vm_restart(name, wait):
|
||||||
"""
|
"""
|
||||||
Restart a VM in the PVC cluster.
|
Restart a VM in the PVC cluster.
|
||||||
"""
|
"""
|
||||||
zk_conn = pvc_common.startZKConnection(config['coordinators'])
|
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)
|
pvc_common.stopZKConnection(zk_conn)
|
||||||
|
|
||||||
if retflag:
|
if retflag:
|
||||||
|
@ -597,12 +597,12 @@ def vm_restart(name):
|
||||||
}
|
}
|
||||||
return output, retcode
|
return output, retcode
|
||||||
|
|
||||||
def vm_shutdown(name):
|
def vm_shutdown(name, wait):
|
||||||
"""
|
"""
|
||||||
Shutdown a VM in the PVC cluster.
|
Shutdown a VM in the PVC cluster.
|
||||||
"""
|
"""
|
||||||
zk_conn = pvc_common.startZKConnection(config['coordinators'])
|
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)
|
pvc_common.stopZKConnection(zk_conn)
|
||||||
|
|
||||||
if retflag:
|
if retflag:
|
||||||
|
@ -651,12 +651,12 @@ def vm_disable(name):
|
||||||
}
|
}
|
||||||
return output, retcode
|
return output, retcode
|
||||||
|
|
||||||
def vm_move(name, node):
|
def vm_move(name, node, wait):
|
||||||
"""
|
"""
|
||||||
Move a VM to another node.
|
Move a VM to another node.
|
||||||
"""
|
"""
|
||||||
zk_conn = pvc_common.startZKConnection(config['coordinators'])
|
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)
|
pvc_common.stopZKConnection(zk_conn)
|
||||||
|
|
||||||
if retflag:
|
if retflag:
|
||||||
|
@ -669,12 +669,12 @@ def vm_move(name, node):
|
||||||
}
|
}
|
||||||
return output, retcode
|
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.
|
Temporarily migrate a VM to another node.
|
||||||
"""
|
"""
|
||||||
zk_conn = pvc_common.startZKConnection(config['coordinators'])
|
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)
|
pvc_common.stopZKConnection(zk_conn)
|
||||||
|
|
||||||
if retflag:
|
if retflag:
|
||||||
|
@ -687,12 +687,12 @@ def vm_migrate(name, node, flag_force):
|
||||||
}
|
}
|
||||||
return output, retcode
|
return output, retcode
|
||||||
|
|
||||||
def vm_unmigrate(name):
|
def vm_unmigrate(name, wait):
|
||||||
"""
|
"""
|
||||||
Unmigrate a migrated VM.
|
Unmigrate a migrated VM.
|
||||||
"""
|
"""
|
||||||
zk_conn = pvc_common.startZKConnection(config['coordinators'])
|
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)
|
pvc_common.stopZKConnection(zk_conn)
|
||||||
|
|
||||||
if retflag:
|
if retflag:
|
||||||
|
|
|
@ -5491,6 +5491,12 @@
|
||||||
"in": "query",
|
"in": "query",
|
||||||
"name": "force",
|
"name": "force",
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Whether to block waiting for the migration to complete",
|
||||||
|
"in": "query",
|
||||||
|
"name": "wait",
|
||||||
|
"type": "boolean"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
|
@ -5551,6 +5557,12 @@
|
||||||
"name": "state",
|
"name": "state",
|
||||||
"required": true,
|
"required": true,
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Whether to block waiting for the state change to complete",
|
||||||
|
"in": "query",
|
||||||
|
"name": "wait",
|
||||||
|
"type": "boolean"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
|
|
Loading…
Reference in New Issue