Esempio n. 1
0
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')
Esempio n. 2
0
File: lxc.py Progetto: zdzhjx/see
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')
Esempio n. 3
0
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")
Esempio n. 4
0
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')
Esempio n. 5
0
File: vbox.py Progetto: zdzhjx/see
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')
Esempio n. 6
0
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')
Esempio n. 7
0
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')
Esempio n. 8
0
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')
Esempio n. 9
0
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')
Esempio n. 10
0
File: qemu.py Progetto: noxdafox/see
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")