From 64266077694fe0cd72cfe831830bdbec74a25296 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Tue, 9 Jul 2019 10:22:23 -0400 Subject: [PATCH] Store list of RBD disks in ZK Store a basic list of RBD disks in Zookeeper for access by the node subsystem to handle RBD locks. This avoids the need to implement complex parsing logic inside the fencing configuration (or elsewhere). Also handle a malformed XML content properly during VM define. --- client-common/vm.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/client-common/vm.py b/client-common/vm.py index f79f83d2..2e72f4c5 100644 --- a/client-common/vm.py +++ b/client-common/vm.py @@ -108,7 +108,10 @@ def getDomainName(zk_conn, domain): # def define_vm(zk_conn, config_data, target_node, selector): # Parse the XML data - parsed_xml = lxml.objectify.fromstring(config_data) + try: + parsed_xml = lxml.objectify.fromstring(config_data) + except: + return False, 'ERROR: Failed to parse XML data.' dom_uuid = parsed_xml.uuid.text dom_name = parsed_xml.name.text @@ -118,7 +121,14 @@ def define_vm(zk_conn, config_data, target_node, selector): # Verify node is valid valid_node = common.verifyNode(zk_conn, target_node) if not valid_node: - return False, 'Specified node "{}" is invalid.'.format(target_node) + return False, 'ERROR: Specified node "{}" is invalid.'.format(target_node) + + # Obtain the RBD disk list using the common functions + ddisks = common.getDomainDisks(parsed_xml) + rbd_list = [] + for disk in ddisks: + if disk['type'] == 'rbd': + rbd_list.append(disk['name']) # Add the new domain to Zookeeper zkhandler.writedata(zk_conn, { @@ -128,6 +138,7 @@ def define_vm(zk_conn, config_data, target_node, selector): '/domains/{}/lastnode'.format(dom_uuid): '', '/domains/{}/failedreason'.format(dom_uuid): '', '/domains/{}/consolelog'.format(dom_uuid): '', + '/domains/{}/rbdlist'.format(dom_uuid): ','.join(rbd_list), '/domains/{}/xml'.format(dom_uuid): config_data })