From 7901ffb5e37909585fe4925dd6236d5a0a4e094e Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Thu, 19 Dec 2019 13:22:38 -0500 Subject: [PATCH] Handle the list of node_limits even better --- client-api/pvc-api.py | 4 ++-- client-cli/pvc.py | 6 ++++++ client-common/common.py | 2 +- client-common/vm.py | 27 ++++++++++++++------------- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/client-api/pvc-api.py b/client-api/pvc-api.py index 280ce98c..2c1fbfc5 100755 --- a/client-api/pvc-api.py +++ b/client-api/pvc-api.py @@ -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 diff --git a/client-cli/pvc.py b/client-cli/pvc.py index 14430936..3741d214 100755 --- a/client-cli/pvc.py +++ b/client-cli/pvc.py @@ -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) diff --git a/client-common/common.py b/client-common/common.py index 182f3d96..49edf6d2 100644 --- a/client-common/common.py +++ b/client-common/common.py @@ -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: diff --git a/client-common/vm.py b/client-common/vm.py index b6482b56..e760c3bc 100644 --- a/client-common/vm.py +++ b/client-common/vm.py @@ -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, {