
From: Royce Lv <lvroyce@linux.vnet.ibm.com> Construct xml to query storage targets information from storage server. Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- src/kimchi/model.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/kimchi/model.py b/src/kimchi/model.py index 20f68f6..f79dc37 100644 --- a/src/kimchi/model.py +++ b/src/kimchi/model.py @@ -1233,6 +1233,20 @@ class Model(object): return server_list + def storagetargets_get_list(self, storage_server, target_type): + xml = _get_storage_server_spec(server=storage_server, target_type=target_type) + conn = self.conn.get() + + try: + ret = conn.findStoragePoolSources(target_type, xml, 0) + except libvirt.libvirtError as e: + kimchi_log.warning("Query storage pool source fails because of %s", + e.get_error_message()) + return list() + + target_list = _parse_target_source_result(target_type, ret) + return target_list + def _get_screenshot(self, vm_uuid): with self.objstore as session: try: @@ -1442,6 +1456,34 @@ class LibvirtVMScreenshot(VMScreenshot): finally: os.close(fd) +def _parse_target_source_result(target_type, xml_str): + root = ElementTree.fromstring(xml_str) + ret = [] + for source in root.getchildren(): + if target_type == 'netfs': + host_name = source.find('host').attrib.values()[0] + target_path = source.find('dir').attrib.values()[0] + type = source.find('format').attrib.values()[0] + ret.append(dict(host=host_name, type=type, target=target_path)) + + return ret + +def _get_storage_server_spec(**kwargs): + # Required parameters: + # server: + # target_type: + if kwargs['target_type'] == 'netfs': + kwargs['format_type'] = """<format type='nfs'/>""" + else: + kwargs['format_type'] = "" + xml = """ + <source> + <host name='%(server)s'/> + %(format_type)s + </source> + """ % kwargs + return xml + def _get_pool_xml(**kwargs): # Required parameters # name: -- 1.8.1.2