Ejemplo n.º 1
0
def download_disk(connection,
                  backup_uuid,
                  disk,
                  disk_path,
                  args,
                  incremental=False):
    progress("Creating image transfer for disk %s" % disk.id)
    transfer = imagetransfer.create_transfer(
        connection,
        disk,
        types.ImageTransferDirection.DOWNLOAD,
        backup=types.Backup(id=backup_uuid))
    try:
        progress("Image transfer %s is ready" % transfer.id)
        download_url = transfer.transfer_url

        extra_args = {}

        parameters = inspect.signature(client.download).parameters

        # Use multiple workers to speed up the download.
        if "max_workers" in parameters:
            extra_args["max_workers"] = args.max_workers

        # Use proxy_url if available. Download will use proxy_url if
        # transfer_url is not available.
        if "proxy_url" in parameters:
            extra_args["proxy_url"] = transfer.proxy_url

        with client.ProgressBar() as pb:
            client.download(download_url,
                            disk_path,
                            args.cafile,
                            incremental=incremental,
                            secure=args.secure,
                            buffer_size=args.buffer_size,
                            progress=pb,
                            **extra_args)
    finally:
        progress("Finalizing image transfer")
        imagetransfer.finalize_transfer(connection, transfer, disk)
Ejemplo n.º 2
0
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):
            con.request("GET", url.path + "/checksum")
            res = con.getresponse()

            if res.status != client.OK:
                error = res.read().decode("utf-8", "replace")
                raise RuntimeError(
                    "Error computing checksum: {}".format(error))

            result = json.loads(res.read())
            print(json.dumps(result, indent=4))
    time.sleep(1)
    disk = disk_service.get()
    if disk.status == types.DiskStatus.OK:
        break

progress("Disk ID: %s" % disk.id)

progress("Creating image transfer...")

# Find a host for this transfer. This is an optional step allowing optimizing
# the transfer using unix socket when running this code on a oVirt hypervisor
# in the same data center.
host = imagetransfer.find_host(connection, args.sd_name)

transfer = imagetransfer.create_transfer(connection,
                                         disk,
                                         types.ImageTransferDirection.UPLOAD,
                                         host=host)

progress("Transfer ID: %s" % transfer.id)
progress("Transfer host name: %s" % transfer.host.name)

# At this stage, the SDK granted the permission to start transferring the disk, and the
# user should choose its preferred tool for doing it. We use the recommended
# way, ovirt-imageio client library.

extra_args = {}

parameters = inspect.signature(client.download).parameters

# Use multiple workers to speed up the upload.
if "max_workers" in parameters:
        disk_snapshot = ds_service.get()
    except sdk.NotFoundError:
        raise RuntimeError("No such disk snapshot: {}".format(
            args.disk_snapshot_uuid)) from None

    # Find a host for this transfer. This is an optional step allowing optimizing
    # the transfer using unix socket when running this code on a oVirt hypervisor
    # in the same data center.
    host = imagetransfer.find_host(connection, storage_domain.name)

    progress("Creating image transfer...")

    transfer = imagetransfer.create_transfer(
        connection,
        disk_snapshot=disk_snapshot,
        direction=types.ImageTransferDirection.DOWNLOAD,
        host=host,
        shallow=bool(args.backing_file),
        timeout_policy=types.ImageTransferTimeoutPolicy(args.timeout_policy))
    try:

        progress("Transfer ID: %s" % transfer.id)
        progress("Transfer host name: %s" % transfer.host.name)

        extra_args = {}

        if args.use_proxy:
            download_url = transfer.proxy_url
        else:
            download_url = transfer.transfer_url
            extra_args["proxy_url"] = transfer.proxy_url
Ejemplo n.º 5
0
    progress("Looking up disk %s" % args.disk_uuid)
    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()

    progress("Creating image transfer for %s" % args.direction)
    if args.direction == "upload":
        direction = types.ImageTransferDirection.UPLOAD
    else:
        direction = types.ImageTransferDirection.DOWNLOAD

    transfer = imagetransfer.create_transfer(
        connection,
        disk,
        direction,
        shallow=args.shallow,
        inactivity_timeout=args.inactivity_timeout)
    try:
        progress("Transfer ID: %s" % transfer.id)
        progress("Transfer host name: %s" % transfer.host.name)
        progress("Transfer URL: %s" % transfer.transfer_url)
        progress("Proxy URL: %s" % transfer.proxy_url)

        # The client will use transfer_url if possible, or fallback to
        # proxy_url.
        with ImageioClient(transfer.transfer_url,
                           cafile=args.cafile,
                           proxy_url=transfer.proxy_url) as client:
            progress("Conneted to imageio server")
Ejemplo n.º 6
0
with closing(connection):

    progress("Looking up disk %s" % args.disk_uuid)
    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()

    progress("Creating image transfer for %s" % args.direction)
    if args.direction == "upload":
        direction = types.ImageTransferDirection.UPLOAD
    else:
        direction = types.ImageTransferDirection.DOWNLOAD

    transfer = imagetransfer.create_transfer(connection,
                                             disk,
                                             direction,
                                             shallow=args.shallow)
    try:
        progress("Transfer ID: %s" % transfer.id)
        progress("Transfer host name: %s" % transfer.host.name)
        progress("Transfer URL: %s" % transfer.transfer_url)
        progress("Proxy URL: %s" % transfer.proxy_url)

        # The client will use transfer_url if possible, or fallback to
        # proxy_url.
        with ImageioClient(transfer.transfer_url,
                           cafile=args.cafile,
                           proxy_url=transfer.proxy_url) as client:
            progress("Conneted to imageio server")

            # Lets read one block every 50 seconds. Each time we access the
Ejemplo n.º 7
0
disk_service = disks_service.disk_service(args.disk_uuid)
disk = disk_service.get()

# Find a host for this transfer. This is an optional step allowing optimizing
# the transfer using unix socket when running this code on a oVirt hypervisor
# in the same data center.
sd_id = disk.storage_domains[0].id
sds_service = connection.system_service().storage_domains_service()
storage_domain = sds_service.storage_domain_service(sd_id).get()
host = imagetransfer.find_host(connection, storage_domain.name)

progress("Creating image transfer...")

transfer = imagetransfer.create_transfer(
    connection,
    disk,
    types.ImageTransferDirection.DOWNLOAD,
    host=host,
    timeout_policy=types.ImageTransferTimeoutPolicy(args.timeout_policy))

progress("Transfer ID: %s" % transfer.id)
progress("Transfer host name: %s" % transfer.host.name)

# At this stage, the SDK granted the permission to start transferring the disk, and the
# user should choose its preferred tool for doing it. We use the recommended
# way, ovirt-imageio client library.

extra_args = {}

parameters = inspect.signature(client.download).parameters

# Use multiple workers to speed up the download.