def domain_xml(identifier, xml, mounts, network_name=None): """Fills the XML file with the required fields. @param identifier: (str) UUID of the Environment. @param xml: (str) XML configuration of the domain. @param filesystem: (tuple) ((source, target), (source, target)) * name * uuid * devices * network * filesystem """ domain = etree.fromstring(xml) subelement(domain, './/name', 'name', identifier) subelement(domain, './/uuid', 'uuid', identifier) devices = subelement(domain, './/devices', 'devices', None) for mount in mounts: filesystem = etree.SubElement(devices, 'filesystem', type='mount') etree.SubElement(filesystem, 'source', dir=mount[0]) etree.SubElement(filesystem, 'target', dir=mount[1]) if network_name is not None: network = subelement(devices, './/interface[@type="network"]', 'interface', None, type='network') subelement(network, './/source', 'source', None, network=network_name) return etree.tostring(domain).decode('utf-8')
def domain_xml(identifier, xml, mounts, network_name=None): """Fills the XML file with the required fields. @param identifier: (str) UUID of the Environment. @param xml: (str) XML configuration of the domain. @param filesystem: (tuple) ((source, target), (source, target)) * name * uuid * devices * network * filesystem """ domain = etree.fromstring(xml) subelement(domain, ".//name", "name", identifier) subelement(domain, ".//uuid", "uuid", identifier) devices = subelement(domain, ".//devices", "devices", None) for mount in mounts: filesystem = etree.SubElement(devices, "filesystem", type="mount") etree.SubElement(filesystem, "source", dir=mount[0]) etree.SubElement(filesystem, "target", dir=mount[1]) if network_name is not None: network = subelement(devices, './/interface[@type="network"]', "interface", None, type="network") subelement(network, ".//source", "source", None, network=network_name) return etree.tostring(domain).decode("utf-8")
def domain_xml(identifier, xml, disk_path): """Fills the XML file with the required fields. * name * uuid * devices """ domain = etree.fromstring(xml) subelement(domain, './/name', 'name', identifier) subelement(domain, './/uuid', 'uuid', identifier) devices = subelement(domain, './/devices', 'devices', None) disk = subelement(devices, './/disk', 'disk', None, type='file', device='disk') subelement(disk, './/source', 'source', None, file=disk_path) return etree.tostring(domain).decode('utf-8')
def network_xml(identifier, xml, address=None): """Fills the XML file with the required fields. * name * uuid * bridge * ip ** dhcp """ netname = identifier[:8] network = etree.fromstring(xml) subelement(network, './/name', 'name', identifier) subelement(network, './/uuid', 'uuid', identifier) subelement(network, './/bridge', 'bridge', None, name='virbr-%s' % netname) if address is not None: set_address(network, address) return etree.tostring(network).decode('utf-8')
def domain_xml(identifier, xml, disk_path, network_name=None): """Fills the XML file with the required fields. * name * uuid * devices ** disk * network """ domain = etree.fromstring(xml) subelement(domain, './/name', 'name', identifier) subelement(domain, './/uuid', 'uuid', identifier) devices = subelement(domain, './/devices', 'devices', None) disk = subelement(devices, './/disk', 'disk', None, type='file', device='disk') subelement(disk, './/source', 'source', None, file=disk_path) if network_name is not None: net = subelement(devices, './/interface[@type="network"]', 'interface', None, type='network') subelement(net, './/source', 'source', None, network=network_name) return etree.tostring(domain).decode('utf-8')
def domain_xml(identifier, xml, disk_path, network_name=None): """Fills the XML file with the required fields. * name * uuid * devices ** disk * network """ domain = etree.fromstring(xml) subelement(domain, './/name', 'name', identifier) subelement(domain, './/uuid', 'uuid', identifier) devices = subelement(domain, './/devices', 'devices', None) disk = subelement(devices, './/disk', 'disk', None, type='file', device='disk') subelement(disk, './/source', 'source', None, file=disk_path) if network_name is not None: network = subelement(devices, './/interface[@type="network"]', 'interface', None, type='network') subelement(network, './/source', 'source', None, network=network_name) return etree.tostring(domain).decode('utf-8')
def domain_xml(identifier, xml, disk_path, network_name=None): """Fills the XML file with the required fields. * name * uuid * devices ** disk * network """ domain = etree.fromstring(xml) subelement(domain, ".//name", "name", identifier) subelement(domain, ".//uuid", "uuid", identifier) devices = subelement(domain, ".//devices", "devices", None) disk = subelement(devices, ".//disk", "disk", None, type="file", device="disk") subelement(disk, ".//source", "source", None, file=disk_path) if network_name is not None: network = subelement(devices, './/interface[@type="network"]', "interface", None, type="network") subelement(network, ".//source", "source", None, network=network_name) return etree.tostring(domain).decode("utf-8")