From 31dfd95a2d97086d3e56d524c53f4a5a2cf0eb45 Mon Sep 17 00:00:00 2001 From: Carlos Konstanski Date: Tue, 7 Nov 2017 16:00:14 -0700 Subject: adding glance gateway --- libs/environment.py | 12 ++---------- libs/glance.py | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 14 deletions(-) (limited to 'libs') diff --git a/libs/environment.py b/libs/environment.py index 7e9027f..137c51a 100644 --- a/libs/environment.py +++ b/libs/environment.py @@ -13,8 +13,6 @@ class Environment(object): os_user_domain_name, os_identity_api_version, os_image_api_version, - elements_path, - manifests_path, extra_envs={}): if os_auth_url is None or \ os_project_name is None or \ @@ -24,9 +22,7 @@ class Environment(object): os_project_domain_name is None or \ os_user_domain_name is None or \ os_identity_api_version is None or \ - os_image_api_version is None or \ - elements_path is None or \ - manifests_path is None: + os_image_api_version is None: print("All required environment arguments must have a value. You passed in:" + \ "\nos_auth_url = " + str(os_auth_url) + \ "\nos_project_name = " + str(os_project_name) + \ @@ -36,9 +32,7 @@ class Environment(object): "\nos_project_domain_name = " + str(os_project_domain_name) + \ "\nos_user_domain_name = " + str(os_user_domain_name) + \ "\nos_identity_api_version = " + str(os_identity_api_version) + \ - "\nos_image_api_version = " + str(os_image_api_version) + \ - "\nelements_path = " + str(elements_path) + \ - "\nmanifests_path = " + str(manifests_path)) + "\nos_image_api_version = " + str(os_image_api_version)) sys.exit(1) else: self.os_auth_url = os_auth_url @@ -50,8 +44,6 @@ class Environment(object): self.os_user_domain_name = os_user_domain_name self.os_identity_api_version = os_identity_api_version self.os_image_api_version = os_image_api_version - self.elements_path = elements_path - self.manifests_path = manifests_path self.extra_envs = {} for key, value in [(k, v) for (k, v) in extra_envs.items() if v]: self.extra_envs[key] = value diff --git a/libs/glance.py b/libs/glance.py index b2a5c8d..3adf64b 100644 --- a/libs/glance.py +++ b/libs/glance.py @@ -2,6 +2,7 @@ from __future__ import print_function import datetime import glanceclient import json +import os import time import traceback @@ -24,15 +25,24 @@ class Glance(object): if image: self.glance.images.delete(image.id) - def upload(self, image_name, image_type, file_path, tag): + def upload(self, image_name, image_type, file_path, visibility, 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, visibility=visibility) image = self.glance.images.update(image.id, tags=[str(tag)]) - with open(file_path, "rb") as myfile: - self.glance.images.upload(image.id, myfile) + with open(file_path, "rb") as stream: + self.glance.images.upload(image.id, stream) return image.id + + def download(self, image_name, file_path): + image = self.find(image_name) + if image: + data = self.glance.images.data(image.id) + os.remove(file_path) + with open(file_path, "w") as stream: + for chunk in data: + stream.write(chunk) -- cgit v1.3