summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xglance-gateway.py103
-rwxr-xr-xglance-gateway.sh4
-rwxr-xr-ximage-foundry.py16
-rw-r--r--libs/environment.py12
-rw-r--r--libs/glance.py18
5 files changed, 129 insertions, 24 deletions
diff --git a/glance-gateway.py b/glance-gateway.py
new file mode 100755
index 0000000..9350421
--- /dev/null
+++ b/glance-gateway.py
@@ -0,0 +1,103 @@
+#!/usr/bin/env python2
+
+from __future__ import print_function
+from libs.environment import *
+from libs.glance import *
+from libs.keystone import *
+import argparse
+import glob
+import os
+import subprocess
+import sys
+import yaml
+
+
+def read_manifests(env):
+ manifests = {}
+ manifests_glob = "%s/*.yaml" % env.extra_envs["manifests_path"]
+ for manifest_file in glob.glob(manifests_glob):
+ with open(manifest_file, "r") as myfile:
+ manifest = yaml.load(myfile.read())
+ if manifest["image_name"] in manifests:
+ raise Exception("Duplicate image name in manifests: %s" % manifest["image_name"])
+ manifests[manifest["image_name"]] = manifest
+ return manifests
+
+
+def check_image_exists_up2date(glance, manifest):
+ image = glance.find("%s.%s" % (manifest["image_name"], manifest["image_type"]))
+ return image and str(manifest["tag"]) in image.tags
+
+
+def main(args):
+ env = Environment(args.os_auth_url,
+ args.os_project_name,
+ args.os_region,
+ args.os_username,
+ args.os_password,
+ args.os_project_domain_name,
+ args.os_user_domain_name,
+ args.os_identity_api_version,
+ args.os_image_api_version,
+ {"manifests_path": args.glance_gateway_manifests_path})
+ manifests = read_manifests(env)
+ keystone = Keystone(env)
+ glance = Glance(keystone, endpoint_type="publicURL")
+ for image_name, manifest in manifests.items():
+ if manifest["vetted"] and not check_image_exists_up2date(glance, manifest):
+ # download private image to /tmp
+ glance.download("%s.%s.unvetted" % (manifest["image_name"], manifest["image_type"]),
+ "/tmp/%s.%s" % (manifest["image_name"], manifest["image_type"]))
+ # upload image as public
+ glance.upload("%s.%s" % (manifest["image_name"], manifest["image_type"]),
+ manifest["image_type"],
+ "/tmp/%s.%s" % (manifest["image_name"], manifest["image_type"]),
+ "public",
+ manifest["tag"])
+
+
+if __name__ == "__main__":
+ parser = argparse.ArgumentParser(description="Glance Gateway CI Process")
+ parser.add_argument("--os-auth-url",
+ required=False,
+ default=os.environ.get("OS_AUTH_URL", None),
+ help="OpenStack openrc environment variable: OS_AUTH_URL")
+ parser.add_argument("--os-project-name",
+ required=False,
+ default=os.environ.get("OS_PROJECT_NAME", None),
+ help="OpenStack openrc environment variable: OS_PROJECT_NAME")
+ parser.add_argument("--os-region",
+ required=False,
+ default=os.environ.get("OS_REGION", None),
+ help="OpenStack openrc environment variable: OS_REGION")
+ parser.add_argument("--os-username",
+ required=False,
+ default=os.environ.get("OS_USERNAME", None),
+ help="OpenStack openrc environment variable: OS_USERNAME")
+ parser.add_argument("--os-password",
+ required=False,
+ default=os.environ.get("OS_PASSWORD", None),
+ help="OpenStack openrc environment variable: OS_PASSWORD")
+ parser.add_argument("--os-project-domain-name",
+ required=False,
+ default=os.environ.get("OS_PROJECT_DOMAIN_NAME", None),
+ help="OpenStack openrc environment variable: OS_PROJECT_DOMAIN_NAME")
+ parser.add_argument("--os-user-domain-name",
+ required=False,
+ default=os.environ.get("OS_USER_DOMAIN_NAME", None),
+ help="OpenStack openrc environment variable: OS_USER_DOMAIN_NAME")
+ parser.add_argument("--os-identity-api-version",
+ required=False,
+ default=os.environ.get("OS_IDENTITY_API_VERSION", None),
+ help="OpenStack openrc environment variable: OS_IDENTITY_API_VERSION")
+ parser.add_argument("--os-image-api-version",
+ required=False,
+ default=os.environ.get("OS_IMAGE_API_VERSION", None),
+ help="OpenStack openrc environment variable: OS_IMAGE_API_VERSION")
+ parser.add_argument("--glance-gateway-manifests-path",
+ required=False,
+ default=os.environ.get("GLANCE_GATEWAY_MANIFESTS_PATH", None),
+ help="image-foundry environment variable: GLANCE_GATEWAY_MANIFESTS_PATH")
+ args = parser.parse_args()
+ main(args)
+ sys.exit(0)
diff --git a/glance-gateway.sh b/glance-gateway.sh
new file mode 100755
index 0000000..0421e10
--- /dev/null
+++ b/glance-gateway.sh
@@ -0,0 +1,4 @@
+#!/bin/bash
+
+. /var/lib/jenkins/openrc-imagefoundry.sh
+./glance-gateway.py
diff --git a/image-foundry.py b/image-foundry.py
index 678f3b6..b4f38aa 100755
--- a/image-foundry.py
+++ b/image-foundry.py
@@ -12,13 +12,9 @@ import sys
import yaml
-def run_shell_command(cmd):
- return subprocess.check_output(cmd, shell=True)
-
-
def read_manifests(env):
manifests = {}
- manifests_glob = "%s/*.yaml" % env.manifests_path
+ manifests_glob = "%s/*.yaml" % env.extra_envs["manifests_path"]
for manifest_file in glob.glob(manifests_glob):
with open(manifest_file, "r") as myfile:
manifest = yaml.load(myfile.read())
@@ -29,14 +25,14 @@ def read_manifests(env):
def check_image_tag_current(glance, manifest):
- image = glance.find("%s.%s" % (manifest["image_name"], manifest["image_type"]))
+ image = glance.find("%s.%s.unvetted" % (manifest["image_name"], manifest["image_type"]))
return image and str(manifest["tag"]) in image.tags
def create_image(env, manifest):
cmd = "disk-image-create %s -t %s -o /tmp/%s.%s 2>&1" % (manifest["elements"], manifest["image_type"], manifest["image_name"], manifest["image_type"])
environ = manifest["extra_envs"] if "extra_envs" in manifest else {}
- environ["ELEMENTS_PATH"] = env.elements_path
+ environ["ELEMENTS_PATH"] = env.extra_envs["elements_path"]
p = subprocess.Popen([cmd], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=environ)
out, err = p.communicate()
if p.returncode != 0:
@@ -53,17 +49,17 @@ def main(args):
args.os_user_domain_name,
args.os_identity_api_version,
args.os_image_api_version,
- args.elements_path,
- args.manifests_path)
+ {"elements_path": args.elements_path, "manifests_path": args.manifests_path})
manifests = read_manifests(env)
keystone = Keystone(env)
glance = Glance(keystone, endpoint_type="publicURL")
for image_name, manifest in manifests.items():
if not check_image_tag_current(glance, manifest):
create_image(env, manifest)
- glance.upload("%s.%s" % (manifest["image_name"], manifest["image_type"]),
+ glance.upload("%s.%s.unvetted" % (manifest["image_name"], manifest["image_type"]),
manifest["image_type"],
"/tmp/%s.%s" % (manifest["image_name"], manifest["image_type"]),
+ "private",
manifest["tag"])
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)