Ejemplo n.º 1
0
def io_tune_to_dom(tune):
    """
    This method converts the VmDiskDeviceTuneLimits structure from the
    dictionary representation to the XML representation.

    :param tune: Dictionary representation of VmDiskDeviceTuneLimits
    :return: DOM XML of device node filled with values
    """
    device = vmxml.Element("device")

    if "name" in tune and tune["name"]:
        vmxml.set_attr(device, "name", tune["name"])

    if "path" in tune and tune["path"]:
        vmxml.set_attr(device, "path", tune["path"])

    if "maximum" in tune:
        maximum = vmxml.Element("maximum")
        vmxml.append_child(device, maximum)
        io_tune_values_to_dom(tune["maximum"], maximum)

    if "guaranteed" in tune:
        guaranteed = vmxml.Element("guaranteed")
        vmxml.append_child(device, guaranteed)
        io_tune_values_to_dom(tune["guaranteed"], guaranteed)

    return device
Ejemplo n.º 2
0
Archivo: vmtune.py Proyecto: EdDev/vdsm
def io_tune_to_dom(tune):
    """
    This method converts the VmDiskDeviceTuneLimits structure from the
    dictionary representation to the XML representation.

    :param tune: Dictionary representation of VmDiskDeviceTuneLimits
    :return: DOM XML of device node filled with values
    """
    device = vmxml.Element("device")

    if "name" in tune and tune["name"]:
        vmxml.set_attr(device, "name", tune["name"])

    if "path" in tune and tune["path"]:
        vmxml.set_attr(device, "path", tune["path"])

    if "maximum" in tune:
        maximum = vmxml.Element("maximum")
        vmxml.append_child(device, maximum)
        io_tune_values_to_dom(tune["maximum"], maximum)

    if "guaranteed" in tune:
        guaranteed = vmxml.Element("guaranteed")
        vmxml.append_child(device, guaranteed)
        io_tune_values_to_dom(tune["guaranteed"], guaranteed)

    return device
Ejemplo n.º 3
0
def update_port_xml(vnicXML, port_isolated):
    if port_isolated is None:
        try:
            port = vmxml.find_first(vnicXML, 'port')
        except vmxml.NotFound:
            pass
        else:
            vnicXML.remove(port)
    else:
        try:
            port = vmxml.find_first(vnicXML, 'port')
        except vmxml.NotFound:
            port = vnicXML.appendChildWithArgs('port')
        vmxml.set_attr(port, 'isolated', str(port_isolated))
Ejemplo n.º 4
0
def create_backup_xml(address, backup_disks, from_checkpoint_id=None):
    domainbackup = vmxml.Element('domainbackup', mode='pull')

    if from_checkpoint_id is not None:
        incremental = vmxml.Element('incremental')
        incremental.appendTextNode(from_checkpoint_id)
        domainbackup.appendChild(incremental)

    server = vmxml.Element('server',
                           transport=address.transport,
                           socket=address.path)

    domainbackup.appendChild(server)

    disks = vmxml.Element('disks')

    # fill the backup XML disks
    for backup_disk in backup_disks.values():
        disk = vmxml.Element('disk',
                             name=backup_disk.drive.name,
                             type=backup_disk.scratch_disk.type)

        # If backup mode reported by the engine it should be added
        # to the backup XML.
        if backup_disk.backup_mode is not None:
            vmxml.set_attr(disk, "backupmode", backup_disk.backup_mode)

            if backup_disk.backup_mode == MODE_INCREMENTAL:
                # if backupmode is 'incremental' we should also provide the
                # checkpoint ID we start the incremental backup from.
                vmxml.set_attr(disk, MODE_INCREMENTAL, from_checkpoint_id)

        # scratch element can have dev=/path/to/block/disk
        # or file=/path/to/file/disk attribute according to
        # the disk type.
        if backup_disk.scratch_disk.type == DISK_TYPE.BLOCK:
            scratch = vmxml.Element('scratch',
                                    dev=backup_disk.scratch_disk.path)
        else:
            scratch = vmxml.Element('scratch',
                                    file=backup_disk.scratch_disk.path)

        storage.disable_dynamic_ownership(scratch, write_type=False)
        disk.appendChild(scratch)

        disks.appendChild(disk)

    domainbackup.appendChild(disks)

    return xmlutils.tostring(domainbackup)
Ejemplo n.º 5
0
def update_disk_element_from_object(disk_element,
                                    vm_drive,
                                    log,
                                    replace_attribs=False):
    # key: (old_value, new_value)
    changes = {}

    # the only change relevant for floppies is the path,
    # because their only usage left is sysprep - aka payload devices.
    device = disk_element.attrib.get('device')
    old_disk_type = disk_element.attrib.get('type')
    disk_type = vm_drive.diskType

    if device != 'floppy':
        vmxml.set_attr(disk_element, 'type', disk_type)
        changes['type'] = (old_disk_type, disk_type)

    # update the path
    source = vmxml.find_first(disk_element, 'source')
    old_disk_attr = storage.SOURCE_ATTR[old_disk_type]
    # on resume, empty CDroms may lack the 'file' attribute
    old_path = source.attrib.get(old_disk_attr, None)
    if old_path is not None and replace_attribs:
        del source.attrib[old_disk_attr]
    disk_attr = storage.SOURCE_ATTR[disk_type]
    vmxml.set_attr(source, disk_attr, vm_drive.path)
    changes['path'] = (
        '%s=%s' % (old_disk_attr, '' if old_path is None else old_path),
        # We intentionally create the new value using a different format
        # - note leading asterisk - to force the _log_changes function to
        # always log this information.
        # We want to see how good is Engine at predicting drive paths,
        # and how often Vdsm needs to correct that.
        '*%s=%s' % (disk_attr, vm_drive.path),
    )

    if device != 'floppy':
        # update the format (the disk might have been collapsed)
        driver = vmxml.find_first(disk_element, 'driver')
        drive_format = 'qcow2' if vm_drive.format == 'cow' else 'raw'
        # on resume, CDroms may have minimal 'driver' attribute
        old_drive_format = driver.attrib.get('type')
        vmxml.set_attr(driver, 'type', drive_format)
        changes['format'] = (old_drive_format, drive_format)

    # dynamic_ownership workaround (required for 4.2 incoming migrations)
    # not needed once we only support https://bugzilla.redhat.com/1666795
    try:
        vmxml.find_first(source, 'seclabel')
    except vmxml.NotFound:
        if disk_type == storage.DISK_TYPE.NETWORK and \
                source.attrib.get('protocol') != 'gluster':
            # skip for non-gluster drives (CINDER) as per LibvirtVmXmlBuilder
            pass
        else:
            storage.disable_dynamic_ownership(source)

    _log_changes(log, 'drive', vm_drive.name, changes)
Ejemplo n.º 6
0
def update_disk_element_from_object(disk_element, vm_drive, log,
                                    replace_attribs=False):
    # key: (old_value, new_value)
    changes = {}

    # the only change relevant for floppies is the path,
    # because their only usage left is sysprep - aka payload devices.
    device = disk_element.attrib.get('device')
    old_disk_type = disk_element.attrib.get('type')
    disk_type = vm_drive.diskType

    if device != 'floppy':
        vmxml.set_attr(disk_element, 'type', disk_type)
        changes['type'] = (old_disk_type, disk_type)

    # update the path
    source = vmxml.find_first(disk_element, 'source')
    old_disk_attr = storage.SOURCE_ATTR[old_disk_type]
    # on resume, empty CDroms may lack the 'file' attribute
    old_path = source.attrib.get(old_disk_attr, None)
    if old_path is not None and replace_attribs:
        del source.attrib[old_disk_attr]
    disk_attr = storage.SOURCE_ATTR[disk_type]
    vmxml.set_attr(source, disk_attr, vm_drive.path)
    changes['path'] = (
        '%s=%s' % (old_disk_attr, '' if old_path is None else old_path),
        # We intentionally create the new value using a different format
        # - note leading asterisk - to force the _log_changes function to
        # always log this information.
        # We want to see how good is Engine at predicting drive paths,
        # and how often Vdsm needs to correct that.
        '*%s=%s' % (disk_attr, vm_drive.path),
    )

    if device != 'floppy':
        # update the format (the disk might have been collapsed)
        driver = vmxml.find_first(disk_element, 'driver')
        drive_format = 'qcow2' if vm_drive.format == 'cow' else 'raw'
        # on resume, CDroms may have minimal 'driver' attribute
        old_drive_format = driver.attrib.get('type')
        vmxml.set_attr(driver, 'type', drive_format)
        changes['format'] = (old_drive_format, drive_format)

    # dynamic_ownership workaround
    if (disk_type == storage.DISK_TYPE.FILE or
            disk_type == storage.DISK_TYPE.BLOCK):
        try:
            vmxml.find_first(source, 'seclabel')
        except vmxml.NotFound:
            storage.disable_dynamic_ownership(source)

    _log_changes(log, 'drive', vm_drive.name, changes)
Ejemplo n.º 7
0
def update_disk_element_from_object(disk_element,
                                    vm_drive,
                                    log,
                                    replace_attribs=False):
    # key: (old_value, new_value)
    changes = {}

    # the only change relevant for floppies is the path,
    # because their only usage left is sysprep - aka payload devices.
    device = disk_element.attrib.get('device')
    old_disk_type = disk_element.attrib.get('type')
    disk_type = vm_drive.diskType

    if device != 'floppy':
        vmxml.set_attr(disk_element, 'type', disk_type)
        changes['type'] = (old_disk_type, disk_type)

    # update the path
    source = vmxml.find_first(disk_element, 'source')
    old_disk_attr = storage.SOURCE_ATTR[old_disk_type]
    # on resume, empty CDroms may lack the 'file' attribute
    old_path = source.attrib.get(old_disk_attr, None)
    if old_path is not None and replace_attribs:
        del source.attrib[old_disk_attr]
    disk_attr = storage.SOURCE_ATTR[disk_type]
    vmxml.set_attr(source, disk_attr, vm_drive.path)
    changes['path'] = (
        '%s=%s' % (old_disk_attr, '' if old_path is None else old_path),
        # We intentionally create the new value using a different format
        # - note leading asterisk - to force the _log_changes function to
        # always log this information.
        # We want to see how good is Engine at predicting drive paths,
        # and how often Vdsm needs to correct that.
        '*%s=%s' % (disk_attr, vm_drive.path),
    )

    if device != 'floppy':
        # update the format (the disk might have been collapsed)
        driver = vmxml.find_first(disk_element, 'driver')
        drive_format = 'qcow2' if vm_drive.format == 'cow' else 'raw'
        # on resume, CDroms may have minimal 'driver' attribute
        old_drive_format = driver.attrib.get('type')
        vmxml.set_attr(driver, 'type', drive_format)
        changes['format'] = (old_drive_format, drive_format)

    _log_changes(log, 'drive', vm_drive.name, changes)