summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Wolf <throughnothing@gmail.com>2011-05-17 18:57:00 -0400
committerWilliam Wolf <throughnothing@gmail.com>2011-05-17 18:57:00 -0400
commit41ea2f4babc474cad64d81c9c95cf02e399a0a64 (patch)
treef9c711e27f4e07dab36cf95b6a2a1f5f6abba38a
parentd9a87dd0dcb703a84c5f642c323d7b2ff68410a6 (diff)
added util functions to get image service
-rw-r--r--nova/utils.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/nova/utils.py b/nova/utils.py
index 361fc9873..e7ce0a79b 100644
--- a/nova/utils.py
+++ b/nova/utils.py
@@ -724,3 +724,51 @@ def parse_server_string(server_str):
except:
LOG.debug(_('Invalid server_string: %s' % server_str))
return ('', '')
+
+
+def parse_image_ref(image_ref):
+ """
+ Parse an imageRef and return (id, host, port)
+
+ If the image_ref passed in is an integer, it will
+ return (image_ref, None, None), otherwise it will
+ return (id, host, port)
+
+ image_ref - imageRef for an image
+
+ """
+
+ if is_int(image_ref):
+ return (image_ref, None, None)
+
+ o = urlparse(image_ref)
+ # Default to port 80 if not passed, should this be 9292?
+ port = o.port or 80
+ host = o.netloc.split(':', 1)[0]
+ id = o.path.split('/')[-1]
+
+ return (id, host, port)
+
+
+def get_image_service(image_ref):
+ """
+ Get the proper image_service for an image_id
+
+ image_ref - image ref/id for an image
+ """
+
+ (image_id, host, port) = parse_image_ref(image_ref)
+
+ image_service = None
+
+ if host:
+ GlanceImageService = utils.import_class(FLAGS.glance_image_service)
+ GlanceClient = utils.import_class('glance.client.Client')
+
+ glance_client = GlanceClient(host, port)
+ image_service = GlanceImageService(glance_client)
+ else:
+ ImageService = utils.import_class(FLAGS.image_service)
+ image_service = ImageService()
+
+ return (image_id, image_service)