From: Denis Puchkin Date: Fri, 16 Oct 2015 12:55:30 +0000 (+0300) Subject: fix all urls by changing their scheme from 'swift+http(s)' to 'swift+config'. X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F06%2F12906%2F2;p=tools%2Fsustaining.git fix all urls by changing their scheme from 'swift+http(s)' to 'swift+config'. Change-Id: I7eb7d8cd1ab2a7f7bde2fae00c26ec8df93cfc49 --- diff --git a/bugs/1498615/fix_urls.py b/bugs/1498615/fix_urls.py new file mode 100644 index 0000000..25e132b --- /dev/null +++ b/bugs/1498615/fix_urls.py @@ -0,0 +1,53 @@ +from six.moves import urllib + +try: + from glance.openstack.common import gettextutils + gettextutils.install('glance') +except ImportError: + from glance.openstack.common import _i18n + + +from glance.registry.client.v2 import client + +OS_AUTH_TOKEN = "5434dde70b0a4bcc91c6f0455dafff03" +OS_REGISTRY_HOST = '192.168.0.3' +OS_REGISTRY_PORT = 9191 + + +def fix_url(loc): + url = loc['url'] + pieces = urllib.parse.urlparse(url) + + schemes = ('swift+http', 'swift+https') + + if pieces.scheme not in schemes: + return None + + scheme = 'swift+config' + ref = 'ref1' + _, path = pieces.path.lstrip('/').split('/', 1) + parts = (scheme, ref, path, None, None, None) + new_url = urllib.parse.urlunparse(parts) + loc['url'] = new_url + return loc + +if __name__ == '__main__': + try: + c = client.RegistryClient( + OS_REGISTRY_HOST, OS_REGISTRY_PORT, auth_tok=OS_AUTH_TOKEN) + except TypeError: + c = client.RegistryClient( + OS_REGISTRY_HOST, OS_REGISTRY_PORT, auth_token=OS_AUTH_TOKEN) + + images = c.image_get_all() + + for image in images: + if image['status'] != 'active': + continue + locations = image['locations'] + image_id = image['id'] + for location in locations: + fix_url(location) + + c.image_update(image_id=image_id, values={'locations': locations }) +