def create_backup_xml(backup_params, disk_xml_list=None): """ Create a backup xml :param backup_params: Params of backup :param disk_xml_list: A list of disk params used in backup xml :return: The backup xml """ backup_xml = BackupXML() backup_mode = backup_params.get("backup_mode") backup_incremental = backup_params.get("backup_incremental") backup_server = backup_params.get("backup_server") if backup_mode: backup_xml.mode = backup_mode if backup_incremental: backup_xml.incremental = backup_incremental if backup_server: if not isinstance(backup_server, dict): raise exceptions.TestError( "Backup server tag should be defined by a dict.") backup_xml.server = backup_server backup_xml.set_disks(disk_xml_list) backup_xml.xmltreefile.write() utils_misc.wait_for(lambda: os.path.exists(backup_xml.xml), 5) return backup_xml
def create_backup_disk_xml(backup_disk_params): """ Create a disk xml which is a subelement of a backup xml :param backup_disk_params: Params of disk xml :return: The disk xml """ backup_disk_xml = BackupXML.DiskXML() disk_name = backup_disk_params.get("disk_name") disk_type = backup_disk_params.get("disk_type") enable_backup = backup_disk_params.get("enable_backup") exportname = backup_disk_params.get("exportname") exportbitmap = backup_disk_params.get("exportbitmap") backupmode = backup_disk_params.get("backupmode") incremental = backup_disk_params.get("incremental") backup_target = backup_disk_params.get("backup_target") # dict backup_driver = backup_disk_params.get("backup_driver") # dict backup_scratch = backup_disk_params.get("backup_scratch") # dict if not disk_name: raise exceptions.TestError("Disk name must be provided for backup disk xml.") backup_disk_xml.name = disk_name if disk_type: backup_disk_xml.type = disk_type if enable_backup: backup_disk_xml.backup = enable_backup if exportname: backup_disk_xml.exportname = exportname if exportbitmap: backup_disk_xml.exportbitmap = exportbitmap if backupmode: backup_disk_xml.backupmode = backupmode if incremental: backup_disk_xml.incremental = incremental if backup_target: if not isinstance(backup_target, dict): raise exceptions.TestError("disk target tag should be defined by a dict.") disk_target = BackupXML.DiskXML.DiskTarget() disk_target.attrs = backup_target["attrs"] if "encryption" in list(backup_target.keys()): disk_target.encryption = disk_target.new_encryption(**backup_target["encryption"]) backup_disk_xml.target = disk_target if backup_driver: if not isinstance(backup_driver, dict): raise exceptions.TestError("disk driver tag should be defined by a dict.") backup_disk_xml.driver = backup_driver if backup_scratch: if not isinstance(backup_scratch, dict): raise exceptions.TestError("disk scratch tag should be defined by a dict.") disk_scratch = BackupXML.DiskXML.DiskScratch() disk_scratch.attrs = backup_scratch["attrs"] if "encryption" in list(backup_scratch.keys()): disk_scratch.encryption = disk_scratch.new_encryption(**backup_scratch["encryption"]) backup_disk_xml.scratch = disk_scratch backup_disk_xml.xmltreefile.write() utils_misc.wait_for(lambda: os.path.exists(backup_disk_xml.xml), 5) return backup_disk_xml