Implement additional functions
1. VM state 2. VM node 3. Lock flush
This commit is contained in:
parent
b7546e3711
commit
ea2426fa73
|
@ -203,6 +203,55 @@ def vm_is_migrated(vm):
|
||||||
retdata = pvc_vm.is_migrated(zk_conn, vm)
|
retdata = pvc_vm.is_migrated(zk_conn, vm)
|
||||||
return retdata
|
return retdata
|
||||||
|
|
||||||
|
def vm_state(vm):
|
||||||
|
"""
|
||||||
|
Return the state of virtual machine VM.
|
||||||
|
"""
|
||||||
|
zk_conn = pvc_common.startZKConnection(config['coordinators'])
|
||||||
|
retflag, retdata = pvc_vm.get_list(zk_conn, None, None, vm, is_fuzzy=False)
|
||||||
|
if retflag:
|
||||||
|
if retdata:
|
||||||
|
retcode = 200
|
||||||
|
retdata = {
|
||||||
|
'name': vm,
|
||||||
|
'state': retdata[0]['state']
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
retcode = 404
|
||||||
|
retdata = {
|
||||||
|
'message': 'VM not found.'
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
retcode = 400
|
||||||
|
|
||||||
|
pvc_common.stopZKConnection(zk_conn)
|
||||||
|
return flask.jsonify(retdata), retcode
|
||||||
|
|
||||||
|
def vm_node(vm):
|
||||||
|
"""
|
||||||
|
Return the current node of virtual machine VM.
|
||||||
|
"""
|
||||||
|
zk_conn = pvc_common.startZKConnection(config['coordinators'])
|
||||||
|
retflag, retdata = pvc_vm.get_list(zk_conn, None, None, vm, is_fuzzy=False)
|
||||||
|
if retflag:
|
||||||
|
if retdata:
|
||||||
|
retcode = 200
|
||||||
|
retdata = {
|
||||||
|
'name': vm,
|
||||||
|
'node': retdata[0]['node'],
|
||||||
|
'last_node': retdata[0]['last_node']
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
retcode = 404
|
||||||
|
retdata = {
|
||||||
|
'message': 'VM not found.'
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
retcode = 400
|
||||||
|
|
||||||
|
pvc_common.stopZKConnection(zk_conn)
|
||||||
|
return flask.jsonify(retdata), retcode
|
||||||
|
|
||||||
def vm_list(node=None, state=None, limit=None, is_fuzzy=True):
|
def vm_list(node=None, state=None, limit=None, is_fuzzy=True):
|
||||||
"""
|
"""
|
||||||
Return a list of VMs with limit LIMIT.
|
Return a list of VMs with limit LIMIT.
|
||||||
|
@ -417,6 +466,23 @@ def vm_unmigrate(name):
|
||||||
}
|
}
|
||||||
return flask.jsonify(output), retcode
|
return flask.jsonify(output), retcode
|
||||||
|
|
||||||
|
def vm_flush_locks(name):
|
||||||
|
"""
|
||||||
|
Flush locks of a (stopped) VM.
|
||||||
|
"""
|
||||||
|
zk_conn = pvc_common.startZKConnection(config['coordinators'])
|
||||||
|
retflag, retdata = pvc_vm.flush_locks(zk_conn, name)
|
||||||
|
if retflag:
|
||||||
|
retcode = 200
|
||||||
|
else:
|
||||||
|
retcode = 400
|
||||||
|
|
||||||
|
pvc_common.stopZKConnection(zk_conn)
|
||||||
|
output = {
|
||||||
|
'message': retdata.replace('\"', '\'')
|
||||||
|
}
|
||||||
|
return flask.jsonify(output), retcode
|
||||||
|
|
||||||
#
|
#
|
||||||
# Network functions
|
# Network functions
|
||||||
#
|
#
|
||||||
|
|
|
@ -274,7 +274,7 @@ def api_vm_element(vm):
|
||||||
@authenticator
|
@authenticator
|
||||||
def api_vm_state(vm):
|
def api_vm_state(vm):
|
||||||
if flask.request.method == 'GET':
|
if flask.request.method == 'GET':
|
||||||
return "Test", 200
|
return pvcapi.vm_state(vm)
|
||||||
|
|
||||||
if flask.request.method == 'POST':
|
if flask.request.method == 'POST':
|
||||||
if not 'state' in flask.request.values:
|
if not 'state' in flask.request.values:
|
||||||
|
@ -294,7 +294,7 @@ def api_vm_state(vm):
|
||||||
@authenticator
|
@authenticator
|
||||||
def api_vm_node(vm):
|
def api_vm_node(vm):
|
||||||
if flask.request.method == 'GET':
|
if flask.request.method == 'GET':
|
||||||
return "Test", 200
|
return pvcapi.vm_node(vm)
|
||||||
|
|
||||||
if flask.request.method == 'POST':
|
if flask.request.method == 'POST':
|
||||||
if 'action' in flask.request.values:
|
if 'action' in flask.request.values:
|
||||||
|
@ -335,6 +335,15 @@ def api_vm_node(vm):
|
||||||
|
|
||||||
flask.abort(400)
|
flask.abort(400)
|
||||||
|
|
||||||
|
@api.route('/api/v1/vm/<vm>/locks', methods=['GET', 'POST'])
|
||||||
|
@authenticator
|
||||||
|
def api_vm_locks(vm):
|
||||||
|
if flask.request.method == 'GET':
|
||||||
|
return "Not implemented", 400
|
||||||
|
|
||||||
|
if flask.request.method == 'POST':
|
||||||
|
return pvcapi.vm_flush_locks(vm)
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Network endpoints
|
# Network endpoints
|
||||||
|
|
|
@ -325,7 +325,7 @@ Valid `state` values are: `start`, `shutdown`, `stop`, `restart`
|
||||||
* Mandatory values: N/A
|
* Mandatory values: N/A
|
||||||
* Optional values: N/A
|
* Optional values: N/A
|
||||||
|
|
||||||
Return the current host node and previous node, if applicable, for `<vm>`.
|
Return the current host node, and last host node if applicable, for `<vm>`.
|
||||||
|
|
||||||
###### `POST`
|
###### `POST`
|
||||||
* Mandatory values: `action`
|
* Mandatory values: `action`
|
||||||
|
@ -343,6 +343,21 @@ If `permanent` is specified, the PVC system will not track the previous node and
|
||||||
|
|
||||||
If `force` is specified, and the VM has been previously migrated, force through a new migration to the selected target and do not update the previous node value.
|
If `force` is specified, and the VM has been previously migrated, force through a new migration to the selected target and do not update the previous node value.
|
||||||
|
|
||||||
|
#### `/api/v1/vm/<vm>/locks`
|
||||||
|
* Methods: `GET`, `POST`
|
||||||
|
|
||||||
|
###### `GET`
|
||||||
|
* Mandatory values: N/A
|
||||||
|
* Optional values: N/A
|
||||||
|
|
||||||
|
Not yet implemented and not planned. Return the list of RBD locks for the VM.
|
||||||
|
|
||||||
|
###### `POST`
|
||||||
|
* Mandatory values: N/A
|
||||||
|
* Optional values: N/A
|
||||||
|
|
||||||
|
Clear all RBD locks for volumes attached to `<vm>`.
|
||||||
|
|
||||||
### Network endpoints
|
### Network endpoints
|
||||||
|
|
||||||
These endpoints manage PVC client virtual network state and operation.
|
These endpoints manage PVC client virtual network state and operation.
|
||||||
|
|
Loading…
Reference in New Issue