Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 1445774 Details for
Bug 1583698
Uninformative error message "Operation Failed" when trying to pause an image download via the API
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
download with pause-resume script
download_pause_resume_disk.py (text/x-python), 6.67 KB, created by
Avihai
on 2018-05-30 11:20:25 UTC
(
hide
)
Description:
download with pause-resume script
Filename:
MIME Type:
Creator:
Avihai
Created:
2018-05-30 11:20:25 UTC
Size:
6.67 KB
patch
obsolete
>#!/usr/bin/env python ># -*- coding: utf-8 -*- > ># ># Copyright (c) 2017 Red Hat, Inc. ># ># Licensed under the Apache License, Version 2.0 (the "License"); ># you may not use this file except in compliance with the License. ># You may obtain a copy of the License at ># ># http://www.apache.org/licenses/LICENSE-2.0 ># ># Unless required by applicable law or agreed to in writing, software ># distributed under the License is distributed on an "AS IS" BASIS, ># WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ># See the License for the specific language governing permissions and ># limitations under the License. ># > >import logging >import ovirtsdk4 as sdk >import ovirtsdk4.types as types >import ssl >import time > > >from httplib import HTTPSConnection > >try: > from urllib.parse import urlparse >except ImportError: > from urlparse import urlparse > > >logging.basicConfig(level=logging.DEBUG, filename='example.log') > >PAUSE_SLEEP = 60 >PAUSE_TRANSFER_PER = 50.00 >PAUSED_USER = types.ImageTransferPhase.PAUSED_USER >RESUMING = types.ImageTransferPhase.RESUMING >CA_FILE = 'storage-ge-04.cert' > > ># This example will connect to the server and download the data ># of the disk, to the local qcow2 file. > ># Create the connection to the server: >connection = sdk.Connection( > url='https://storage-ge-04.scl.lab.tlv.redhat.com/ovirt-engine/api', > username='admin@internal', > password='123456', > ca_file=CA_FILE, > debug=True, > log=logging.getLogger(), >) > ># Get the reference to the root service: >system_service = connection.system_service() > ># Get the reference to the disks service: >disks_service = connection.system_service().disks_service() > ># Find the disk we want to download by the id: ># disk_service = disks_service.disk_service('118fb69c-2584-4400-a285-220cdc9b4da1') >disk_id = '835c2bc8-8d41-4f18-83bc-bc7c17acbd99' >disk_service = disks_service.disk_service(disk_id) >disk = disk_service.get() > ># Get a reference to the service that manages the image ># transfer that was added in the previous step: >transfers_service = system_service.image_transfers_service() > ># Add a new image transfer: >transfer = transfers_service.add( > types.ImageTransfer( > image=types.Image( > id=disk.id > ), > direction=types.ImageTransferDirection.DOWNLOAD, > ) >) > ># Get reference to the created transfer service: >transfer_service = transfers_service.image_transfer_service(transfer.id) > ># After adding a new transfer for the disk, the transfer's status will be INITIALIZING. ># Wait until the init phase is over. The actual transfer can start when its status is "Transferring". >while transfer.phase == types.ImageTransferPhase.INITIALIZING: > time.sleep(1) > transfer = transfer_service.get() > ># Set needed headers for downloading: >transfer_headers = { > 'Authorization': transfer.signed_ticket, >} > ># At this stage, the SDK granted the permission to start transferring the disk, and the ># user should choose its preferred tool for doing it - regardless of the SDK. ># In this example, we will use Python's httplib.HTTPSConnection for transferring the data. >proxy_url = urlparse(transfer.proxy_url) >context = ssl.create_default_context() > ># Note that ovirt-imageio-proxy by default checks the certificates, so if you don't have ># your CA certificate of the engine in the system, you need to pass it to HTTPSConnection. >context.load_verify_locations(cafile=CA_FILE) > >proxy_connection = HTTPSConnection( > proxy_url.hostname, > proxy_url.port, > context=context, >) > >try: > path = "/home/aefrat/storage-ge-04.disk" > MiB_per_request = 8 > with open(path, "wb") as mydisk: > size = disk.provisioned_size > #size = 524288 > #size = 1073741824 > #print "apparentsize size: %s" % size > chunk_size = 1024 * 1024 * MiB_per_request > #chunk_size = MiB_per_request*1048576 > pos = 0 > while pos < size: > completed_transfer_per = pos / float(size) * 100 > # Extend the transfer session. > transfer_service.extend() > # Set the range, according to the chunk being downloaded. > transfer_headers['Range'] = 'bytes=%d-%d' % (pos, min(size, pos + chunk_size) - 1) > # Perform the request. > proxy_connection.request( > 'GET', > proxy_url.path, > headers=transfer_headers, > ) > # Get response > r = proxy_connection.getresponse() > > # Check the response status: > if r.status >= 300: > print "Error: %s" % r.read() > break > > # Write the content to file: > mydisk.write(r.read()) > print "Completed: %s%% on disk id %s" % ( > int(completed_transfer_per), disk_id > ) > # Continue to next chunk. > > # Start pause > if completed_transfer_per == PAUSE_TRANSFER_PER: > print "Pause transfer on image %s" % disk_id > transfer_service.pause() > start = time.time() > transfer = transfer_service.get() > # Check the transfer phase until it changes to "paused_user" > while transfer.phase != PAUSED_USER: > time.sleep(1) > print( > "Current Image %s transfer phase is not paused_user yet " > "but in phase: %s" % (disk_id, transfer.phase) > ) > transfer = transfer_service.get() > if transfer.phase == PAUSED_USER: > print( > "Image %s phase is %s" % (disk_id, transfer.phase) > ) > break > self.check_for_timeout(start, PAUSED_USER) > # Now that disk transfer is paused , sleep for a while , in this > # case for PAUSE_SLEEP > print "Sleeping for 1min on image %s" % disk_id > time.sleep(PAUSE_SLEEP) > # Resume disk transfer > print "Resume transfer on image %s" % disk_id > start = time.time() > transfer = transfer_service.get() > transfer_service.resume() > # Check the transfer phase until it changes to "resuming" > while transfer.phase == RESUMING: > time.sleep(1) > transfer = transfer_service.get() > print "Image %s is in phase %s" % (disk_id, transfer.phase) > self.check_for_timeout(start, RESUMING) > > pos += chunk_size > >finally: > # Finalize the session. > transfer_service.finalize() > >print "Completed", "{:.0%}".format(pos / float(size)) > ># Close the connection to the server: >connection.close()
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 1583698
: 1445774 |
1448223
|
1452342