Interface ImageTransferService

  • All Superinterfaces:
    Service
    All Known Implementing Classes:
    ImageTransferServiceImpl

    public interface ImageTransferService
    extends Service
    This service provides a mechanism to control an image transfer. The client will have to create a transfer by using <> of the <> service, stating the image to transfer data to/from. After doing that, the transfer is managed by this service. *Using oVirt's Python's SDK:* Uploading a `disk` with id `123` (on a random host in the data center): [source,python] ---- transfers_service = system_service.image_transfers_service() transfer = transfers_service.add( types.ImageTransfer( disk=types.Disk( id='123' ) ) ) ---- Uploading a `disk` with id `123` on `host` id `456`: [source,python] ---- transfers_service = system_service.image_transfers_service() transfer = transfers_service.add( types.ImageTransfer( disk=types.Disk( id='123' ), host=types.Host( id='456' ) ) ) ---- If the user wishes to download a disk rather than upload, he/she should specify `download` as the <> attribute of the transfer. This will grant a read permission from the image, instead of a write permission. E.g: [source,python] ---- transfers_service = system_service.image_transfers_service() transfer = transfers_service.add( types.ImageTransfer( disk=types.Disk( id='123' ), direction=types.ImageTransferDirection.DOWNLOAD ) ) ---- Transfers have phases, which govern the flow of the upload/download. A client implementing such a flow should poll/check the transfer's phase and act accordingly. All the possible phases can be found in <>. After adding a new transfer, its phase will be <>. The client will have to poll on the transfer's phase until it changes. When the phase becomes <>, the session is ready to start the transfer. For example: [source,python] ---- transfer_service = transfers_service.image_transfer_service(transfer.id) while transfer.phase == types.ImageTransferPhase.INITIALIZING: time.sleep(3) transfer = transfer_service.get() ---- At that stage, if the transfer's phase is <>, then the session was not successfully established. One possible reason for that is that the ovirt-imageio-daemon is not running in the host that was selected for transfer. The transfer can be resumed by calling <> of the service that manages it. If the session was successfully established - the returned transfer entity will contain the <> and <> attributes, which the client needs to use in order to transfer the required data. The client can choose whatever technique and tool for sending the HTTPS request with the image's data. - `transfer_url` is the address of an imageio server running on one of the hypervisors. - `proxy_url` is the address of an imageio proxy server that can be used if you cannot access transfer_url. To transfer the image, it is recommended to use the imageio client python library. [source,python] ---- from ovirt_imageio import client # Upload qcow2 image to virtual disk: client.upload("disk.qcow2", transfer.transfer_url) # Download virtual disk to qcow2 image: client.download(transfer.transfer_url, "disk.qcow2") ---- You can also upload and download using imageio REST API. For more info on this, see imageio API documentation: http://ovirt.github.io/ovirt-imageio/images.html When finishing the transfer, the user should call <>. This will make the final adjustments and verifications for finishing the transfer process. For example: [source,python] ---- transfer_service.finalize() ---- In case of an error, the transfer's phase will be changed to <>, and the disk's status will be changed to `Illegal`. Otherwise it will be changed to <>, and the disk will be ready to be used. In both cases, the transfer entity will be removed shortly after. *Using HTTP and cURL calls:* - For upload, create a new disk first: * Specify 'initial_size' and 'provisioned_size' in bytes. * 'initial_size' must be bigger or the same as the size of the uploaded data. [source] ---- POST /ovirt-engine/api/disks ---- With a request body as follows: [source,xml] ---- mydisk 1073741824 1073741824 raw ---- - Create a new image transfer for downloading/uploading a `disk` with id `456`: [source] ---- POST /ovirt-engine/api/imagetransfers ---- With a request body as follows: [source,xml] ---- upload|download ---- Will respond: [source,xml] ---- download|upload initializing|transferring https://proxy_fqdn:54323/images/41c732d4-2210-4e7b-9e5c-4e2805baadbb https://daemon_fqdn:54322/images/41c732d4-2210-4e7b-9e5c-4e2805baadbb ... ---- Note: If the phase is 'initializing', poll the `image_transfer` till its phase changes to 'transferring'. - Use the 'transfer_url' or 'proxy_url' to invoke a curl command: - use 'transfer_url' for transferring directly from/to ovirt-imageio-daemon, or, use 'proxy_url' for transferring from/to ovirt-imageio-proxy. Note: using the proxy would mitigate scenarios where there's no direct connectivity to the daemon machine, e.g. vdsm machines are on a different network than the engine. -- Download: [source,shell] ---- $ curl --cacert /etc/pki/ovirt-engine/ca.pem https://daemon_fqdn:54322/images/41c732d4-2210-4e7b-9e5c-4e2805baadbb -o ---- -- Upload: [source,shell] ---- $ curl --cacert /etc/pki/ovirt-engine/ca.pem --upload-file -X PUT https://daemon_fqdn:54322/images/41c732d4-2210-4e7b-9e5c-4e2805baadbb ---- - Finalize the image transfer by invoking the action: [source] ---- POST /ovirt-engine/api/imagetransfers/123/finalize ---- With a request body as follows: [source,xml] ---- ----
    • Method Detail

      • finalize_

        ImageTransferService.FinalizeRequest finalize_()
        After finishing to transfer the data, finalize the transfer. This will make sure that the data being transferred is valid and fits the image entity that was targeted in the transfer. Specifically, will verify that if the image entity is a QCOW disk, the data uploaded is indeed a QCOW file, and that the image doesn't have a backing file.
      • resume

        ImageTransferService.ResumeRequest resume()
        Resume the image transfer session. The client will need to poll the transfer's phase until it is different than `resuming`. For example: [source,python] ---- transfer_service = transfers_service.image_transfer_service(transfer.id) transfer_service.resume() transfer = transfer_service.get() while transfer.phase == types.ImageTransferPhase.RESUMING: time.sleep(1) transfer = transfer_service.get() ----
      • service

        Service service​(String path)
        Service locator method, returns individual service on which the URI is dispatched.