]> review.fuel-infra Code Review - tools/sustaining.git/commitdiff
fix all urls by changing their scheme from 'swift+http(s)' to 'swift+config'. 06/12906/2
authorDenis Puchkin <dpuchkin@mirantis.com>
Fri, 16 Oct 2015 12:55:30 +0000 (15:55 +0300)
committerDenis Puchkin <dpuchkin@mirantis.com>
Mon, 19 Oct 2015 16:13:05 +0000 (19:13 +0300)
Change-Id: I7eb7d8cd1ab2a7f7bde2fae00c26ec8df93cfc49

bugs/1498615/fix_urls.py [new file with mode: 0644]

diff --git a/bugs/1498615/fix_urls.py b/bugs/1498615/fix_urls.py
new file mode 100644 (file)
index 0000000..25e132b
--- /dev/null
@@ -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 })
+