diff options
| author | Carlos Konstanski <ckonstanski@pippiandcarlos.com> | 2017-10-26 15:16:59 -0600 |
|---|---|---|
| committer | Carlos Konstanski <ckonstanski@pippiandcarlos.com> | 2017-10-26 15:16:59 -0600 |
| commit | 4a1c4e8c3e6ca4ffbcd9ef38f07a1527226d7430 (patch) | |
| tree | 2ce07ca014433fd0349514b065595db48be94e8d /libs/glance.py | |
initial commit
Diffstat (limited to 'libs/glance.py')
| -rw-r--r-- | libs/glance.py | 38 |
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 |
