Handle the list of node_limits even better

This commit is contained in:
Joshua Boniface 2019-12-19 13:22:38 -05:00
parent 684499cce3
commit 7901ffb5e3
4 changed files with 23 additions and 16 deletions

View File

@ -280,7 +280,7 @@ def api_vm_root():
# Set target limit metadata
if 'limit' in flask.request.values:
limit = flask.request.values['limit']
limit = flask.request.values['limit'].split(',')
else:
limit = None
@ -308,7 +308,7 @@ def api_vm_element(vm):
if flask.request.method == 'POST':
# Set target limit metadata
if 'limit' in flask.request.values:
limit = flask.request.values['limit']
limit = flask.request.values['limit'].split(',')
else:
limit = None

View File

@ -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.
"""
if node_limit:
node_limit = node_limit.split(',')
# Open the XML file
config_data = config.read()
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:
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)
retcode, retmsg = pvc_vm.modify_vm_metadata(zk_conn, domain, node_limit, node_selector, node_autostart)
cleanup(retcode, retmsg, zk_conn)

View File

@ -165,7 +165,7 @@ def getInformationFromXML(zk_conn, uuid):
domain_failedreason = zkhandler.readdata(zk_conn, '/domains/{}/failedreason'.format(uuid))
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:
domain_node_limit = None
try:

View File

@ -186,22 +186,16 @@ def define_vm(zk_conn, config_data, target_node, node_limit, node_selector, node
rbd_list.append(disk['name'])
# Join the limit
if isinstance(node_limit, list):
if isinstance(node_limit, list) and node_limit:
formatted_node_limit = ','.join(node_limit)
else:
if node_limit:
formatted_node_limit = node_limit
else:
formatted_node_limit = ''
formatted_node_limit = ''
# Join the RBD list
if isinstance(rbd_list, list):
if isinstance(rbd_list, list) and rbd_list:
formatted_rbd_list = ','.join(rbd_list)
else:
if rbd_list:
formatted_rbd_list = rbd_list
else:
formatted_rbd_list = ''
formatted_rbd_list = ''
# Add the new domain to Zookeeper
zkhandler.writedata(zk_conn, {
@ -226,10 +220,17 @@ def modify_vm_metadata(zk_conn, domain, node_limit, node_selector, node_autostar
if not dom_uuid:
return False, 'ERROR: Could not find VM "{}" in the cluster!'.format(domain)
if node_limit is not None:
zkhandler.writedata(zk_conn, {
'/domains/{}/node_limit'.format(dom_uuid): ','.join(node_limit)
})
# Join the limit
if isinstance(node_limit, list):
zkhandler.writedata(zk_conn, {
'/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:
zkhandler.writedata(zk_conn, {