Handle the list of node_limits even better
This commit is contained in:
parent
684499cce3
commit
7901ffb5e3
|
@ -280,7 +280,7 @@ def api_vm_root():
|
||||||
|
|
||||||
# Set target limit metadata
|
# Set target limit metadata
|
||||||
if 'limit' in flask.request.values:
|
if 'limit' in flask.request.values:
|
||||||
limit = flask.request.values['limit']
|
limit = flask.request.values['limit'].split(',')
|
||||||
else:
|
else:
|
||||||
limit = None
|
limit = None
|
||||||
|
|
||||||
|
@ -308,7 +308,7 @@ def api_vm_element(vm):
|
||||||
if flask.request.method == 'POST':
|
if flask.request.method == 'POST':
|
||||||
# Set target limit metadata
|
# Set target limit metadata
|
||||||
if 'limit' in flask.request.values:
|
if 'limit' in flask.request.values:
|
||||||
limit = flask.request.values['limit']
|
limit = flask.request.values['limit'].split(',')
|
||||||
else:
|
else:
|
||||||
limit = None
|
limit = None
|
||||||
|
|
||||||
|
|
|
@ -241,6 +241,9 @@ def vm_define(config, target_node, node_limit, node_selector, node_autostart):
|
||||||
Define a new virtual machine from Libvirt XML configuration file CONFIG.
|
Define a new virtual machine from Libvirt XML configuration file CONFIG.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
if node_limit:
|
||||||
|
node_limit = node_limit.split(',')
|
||||||
|
|
||||||
# Open the XML file
|
# Open the XML file
|
||||||
config_data = config.read()
|
config_data = config.read()
|
||||||
config.close()
|
config.close()
|
||||||
|
@ -277,6 +280,9 @@ def vm_meta(domain, node_limit, node_selector, node_autostart):
|
||||||
if node_limit is None and node_selector is None and node_autostart is None:
|
if node_limit is None and node_selector is None and node_autostart is None:
|
||||||
cleanup(False, 'At least one metadata option must be specified to update.')
|
cleanup(False, 'At least one metadata option must be specified to update.')
|
||||||
|
|
||||||
|
if node_limit:
|
||||||
|
node_limit = node_limit.split(',')
|
||||||
|
|
||||||
zk_conn = pvc_common.startZKConnection(zk_host)
|
zk_conn = pvc_common.startZKConnection(zk_host)
|
||||||
retcode, retmsg = pvc_vm.modify_vm_metadata(zk_conn, domain, node_limit, node_selector, node_autostart)
|
retcode, retmsg = pvc_vm.modify_vm_metadata(zk_conn, domain, node_limit, node_selector, node_autostart)
|
||||||
cleanup(retcode, retmsg, zk_conn)
|
cleanup(retcode, retmsg, zk_conn)
|
||||||
|
|
|
@ -165,7 +165,7 @@ def getInformationFromXML(zk_conn, uuid):
|
||||||
domain_failedreason = zkhandler.readdata(zk_conn, '/domains/{}/failedreason'.format(uuid))
|
domain_failedreason = zkhandler.readdata(zk_conn, '/domains/{}/failedreason'.format(uuid))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
domain_node_limit = zkhandler.readdata(zk_conn, '/domains/{}/node_limit'.format(uuid))
|
domain_node_limit = zkhandler.readdata(zk_conn, '/domains/{}/node_limit'.format(uuid)).split(',')
|
||||||
except:
|
except:
|
||||||
domain_node_limit = None
|
domain_node_limit = None
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -186,20 +186,14 @@ def define_vm(zk_conn, config_data, target_node, node_limit, node_selector, node
|
||||||
rbd_list.append(disk['name'])
|
rbd_list.append(disk['name'])
|
||||||
|
|
||||||
# Join the limit
|
# Join the limit
|
||||||
if isinstance(node_limit, list):
|
if isinstance(node_limit, list) and node_limit:
|
||||||
formatted_node_limit = ','.join(node_limit)
|
formatted_node_limit = ','.join(node_limit)
|
||||||
else:
|
|
||||||
if node_limit:
|
|
||||||
formatted_node_limit = node_limit
|
|
||||||
else:
|
else:
|
||||||
formatted_node_limit = ''
|
formatted_node_limit = ''
|
||||||
|
|
||||||
# Join the RBD list
|
# Join the RBD list
|
||||||
if isinstance(rbd_list, list):
|
if isinstance(rbd_list, list) and rbd_list:
|
||||||
formatted_rbd_list = ','.join(rbd_list)
|
formatted_rbd_list = ','.join(rbd_list)
|
||||||
else:
|
|
||||||
if rbd_list:
|
|
||||||
formatted_rbd_list = rbd_list
|
|
||||||
else:
|
else:
|
||||||
formatted_rbd_list = ''
|
formatted_rbd_list = ''
|
||||||
|
|
||||||
|
@ -226,10 +220,17 @@ def modify_vm_metadata(zk_conn, domain, node_limit, node_selector, node_autostar
|
||||||
if not dom_uuid:
|
if not dom_uuid:
|
||||||
return False, 'ERROR: Could not find VM "{}" in the cluster!'.format(domain)
|
return False, 'ERROR: Could not find VM "{}" in the cluster!'.format(domain)
|
||||||
|
|
||||||
|
|
||||||
if node_limit is not None:
|
if node_limit is not None:
|
||||||
|
# Join the limit
|
||||||
|
if isinstance(node_limit, list):
|
||||||
zkhandler.writedata(zk_conn, {
|
zkhandler.writedata(zk_conn, {
|
||||||
'/domains/{}/node_limit'.format(dom_uuid): ','.join(node_limit)
|
'/domains/{}/node_limit'.format(dom_uuid): ','.join(node_limit)
|
||||||
})
|
})
|
||||||
|
else:
|
||||||
|
zkhandler.writedata(zk_conn, {
|
||||||
|
'/domains/{}/node_limit'.format(dom_uuid): ''
|
||||||
|
})
|
||||||
|
|
||||||
if node_selector is not None:
|
if node_selector is not None:
|
||||||
zkhandler.writedata(zk_conn, {
|
zkhandler.writedata(zk_conn, {
|
||||||
|
|
Loading…
Reference in New Issue