diff options
| author | Naveed Massjouni <naveedm9@gmail.com> | 2011-10-26 14:32:48 -0400 |
|---|---|---|
| committer | Dan Prince <dan.prince@rackspace.com> | 2011-10-26 14:48:46 -0400 |
| commit | 1b7fba648aa3eb4cdda345237c9f77dc0b229329 (patch) | |
| tree | 2903b2cb0e77879fed81d4fec8f06df7dd76133f /plugins | |
| parent | 5e9e3873e5ee3cf87b8aec801705ee24cedcd1aa (diff) | |
| download | nova-1b7fba648aa3eb4cdda345237c9f77dc0b229329.tar.gz nova-1b7fba648aa3eb4cdda345237c9f77dc0b229329.tar.xz nova-1b7fba648aa3eb4cdda345237c9f77dc0b229329.zip | |
Adding support for retrying glance image downloads.
Change-Id: Ifff40d90f7dc61a6d41ae2d6908d6e1e6f0aea7e
Diffstat (limited to 'plugins')
| -rwxr-xr-x | plugins/xenserver/xenapi/etc/xapi.d/plugins/glance | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance index d45a0b1c4..47052905d 100755 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance @@ -33,6 +33,7 @@ import shlex import shutil import subprocess import tempfile +import time import XenAPIPlugin @@ -67,7 +68,7 @@ def _copy_kernel_vdi(dest, copy_args): def _download_tarball(sr_path, staging_path, image_id, glance_host, - glance_port, auth_token): + glance_port, auth_token, num_retries): """Download the tarball image from Glance and extract it into the staging area. """ @@ -77,12 +78,17 @@ def _download_tarball(sr_path, staging_path, image_id, glance_host, headers['x-auth-token'] = auth_token conn = httplib.HTTPConnection(glance_host, glance_port) - conn.request('GET', '/v1/images/%s' % image_id, headers=headers) - resp = conn.getresponse() - if resp.status == httplib.NOT_FOUND: - raise Exception("Image '%s' not found in Glance" % image_id) - elif resp.status != httplib.OK: - raise Exception("Unexpected response from Glance %i" % resp.status) + + for count in xrange(1 + num_retries): + conn.request('GET', '/v1/images/%s' % image_id, headers=headers) + resp = conn.getresponse() + if resp.status == httplib.OK: + break + elif resp.status == httplib.NOT_FOUND: + raise Exception("Image '%s' not found in Glance" % image_id) + elif count == num_retries: + raise Exception("Unexpected response from Glance %i" % resp.status) + time.sleep(1) tar_cmd = "tar -zx --directory=%(staging_path)s" % locals() tar_proc = _make_subprocess(tar_cmd, stderr=True, stdin=True) @@ -404,11 +410,12 @@ def download_vhd(session, args): uuid_stack = params["uuid_stack"] sr_path = params["sr_path"] auth_token = params["auth_token"] + num_retries = params["num_retries"] staging_path = _make_staging_area(sr_path) try: _download_tarball(sr_path, staging_path, image_id, glance_host, - glance_port, auth_token) + glance_port, auth_token, num_retries) # Right now, it's easier to return a single string via XenAPI, # so we'll json encode the list of VHDs. return json.dumps(_import_vhds(sr_path, staging_path, uuid_stack)) |
