summaryrefslogtreecommitdiff
path: root/libs/glance.py
diff options
context:
space:
mode:
Diffstat (limited to 'libs/glance.py')
-rw-r--r--libs/glance.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/libs/glance.py b/libs/glance.py
new file mode 100644
index 0000000..b2a5c8d
--- /dev/null
+++ b/libs/glance.py
@@ -0,0 +1,38 @@
+from __future__ import print_function
+import datetime
+import glanceclient
+import json
+import time
+import traceback
+
+
+class Glance(object):
+ def __init__(self, keystone, endpoint_type="publicURL"):
+ self.keystone = keystone
+ self.glance = glanceclient.Client(keystone.os_image_api_version,
+ endpoint=keystone.get_glance_url(endpoint_type=endpoint_type),
+ session=keystone.session)
+
+ def find(self, image_name):
+ for image in self.glance.images.list():
+ if image.name == image_name:
+ return image
+ return None
+
+ def delete(self, image_name):
+ image = self.find(image_name)
+ if image:
+ self.glance.images.delete(image.id)
+
+ def upload(self, image_name, image_type, file_path, tag):
+ self.delete(image_name)
+ image = self.glance.images.create(name=image_name)
+ if image.status != "queued":
+ raise Exception("Image did not enter queued state upon create.")
+ image = self.glance.images.update(image.id, disk_format=image_type)
+ image = self.glance.images.update(image.id, container_format="bare")
+ image = self.glance.images.update(image.id, visibility="private")
+ image = self.glance.images.update(image.id, tags=[str(tag)])
+ with open(file_path, "rb") as myfile:
+ self.glance.images.upload(image.id, myfile)
+ return image.id