import ssl from contextlib import closing from http import client from urllib.parse import urlparse from ovirtsdk4 import types from helpers import common from helpers import imagetransfer parser = common.ArgumentParser(description="Compute disk checksum") parser.add_argument("disk_uuid", help="Disk UUID.") args = parser.parse_args() common.configure_logging(args) connection = common.create_connection(args) with closing(connection): system_service = connection.system_service() disks_service = connection.system_service().disks_service() disk_service = disks_service.disk_service(args.disk_uuid) disk = disk_service.get() transfer = imagetransfer.create_transfer( connection, disk, types.ImageTransferDirection.DOWNLOAD) try: url = urlparse(transfer.transfer_url) con = client.HTTPSConnection( url.netloc, context=ssl.create_default_context(cafile=args.cafile)) with closing(con):
def main(): parser = common.ArgumentParser(description="Backup VM disks") subparsers = parser.add_subparsers(title="commands") full_parser = subparsers.add_parser( "full", help="Run full backup.") full_parser.set_defaults(command=cmd_full) add_download_args(full_parser) full_parser.add_argument( "vm_uuid", help="UUID of the VM to backup.") full_parser.add_argument( "--disk-uuid", action="append", help="Disk UUID to backup. May be used multiple times to backup " "multiple disks. If not specified, backup all VM disks."), incremental_parser = subparsers.add_parser( "incremental", help="Run incremental backup.") incremental_parser.set_defaults(command=cmd_incremental) add_download_args(incremental_parser) incremental_parser.add_argument( "vm_uuid", help="UUID of the VM to backup.") incremental_parser.add_argument( "--from-checkpoint-uuid", required=True, help="Perform incremental backup since the specified checkpoint " "UUID.") incremental_parser.add_argument( "--disk-uuid", action="append", help="Disk UUID to backup. May be used multiple times to backup " "multiple disks. If not specified, backup all VM disks."), start_parser = subparsers.add_parser( "start", help="Start VM backup.") start_parser.set_defaults(command=cmd_start) start_parser.add_argument( "vm_uuid", help="UUID of the VM to backup.") start_parser.add_argument( "--disk-uuid", action="append", help="Disk UUID to backup. May be used multiple times to backup " "multiple disks. If not specified, backup all VM disks.") start_parser.add_argument( "--from-checkpoint-uuid", help="Perform incremental backup since the specified checkpoint " "UUID.") download_parser = subparsers.add_parser( "download", help="Download VM backup disk.") download_parser.set_defaults(command=cmd_download) add_download_args(download_parser) download_parser.add_argument( "vm_uuid", help="UUID of the VM for the backup.") download_parser.add_argument( "--backup-uuid", required=True, help="UUID of the backup to finalize.") download_parser.add_argument( "--incremental", action="store_true", help="Download incremental backup data in qcow2 format. The " "downloaded disk should be rebased on the previous backup " "to restore the disk contents. Can be used only if the " "backup was started with --from-checkpoint-uuid.") stop_parser = subparsers.add_parser( "stop", help="Stop VM backup.") stop_parser.set_defaults(command=cmd_stop) stop_parser.add_argument( "vm_uuid", help="UUID of the VM for the backup.") stop_parser.add_argument( "backup_uuid", help="UUID of the backup to finalize.") args = parser.parse_args() common.configure_logging(args) args.command(args)