aboutsummaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorMorgan Richomme <morgan.richomme@orange.com>2016-08-26 06:48:26 +0000
committerGerrit Code Review <gerrit@172.30.200.206>2016-08-26 06:48:26 +0000
commit874eac1d00c9624d084b3c7b01075a7645c5b840 (patch)
treee5716aad90288dfaa9d39fc550571862381f6e87 /utils
parent2b22d89b5a3dc212774d0a426e53d569f98173a7 (diff)
parent5f5af6b1d8d0af19db143e67f04f67a643af863c (diff)
Merge "refactor create or get image process to eliminate reduplicate"
Diffstat (limited to 'utils')
-rwxr-xr-xutils/openstack_utils.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/utils/openstack_utils.py b/utils/openstack_utils.py
index d30ca629..a7bc899a 100755
--- a/utils/openstack_utils.py
+++ b/utils/openstack_utils.py
@@ -889,6 +889,26 @@ def create_glance_image(glance_client, image_name, file_path, disk="qcow2",
return None
+def get_or_create_image(name, path, format):
+ image_exists = False
+ glance_client = get_glance_client()
+
+ image_id = get_image_id(glance_client, name)
+ if image_id != '':
+ logger.info("Using existing image '%s'..." % name)
+ image_exists = True
+ else:
+ logger.info("Creating image '%s' from '%s'..." % (name, path))
+ image_id = create_glance_image(glance_client, name, path, format)
+ if not image_id:
+ logger.error("Failed to create a Glance image...")
+ else:
+ logger.debug("Image '%s' with ID=%s created successfully."
+ % (name, image_id))
+
+ return image_exists, image_id
+
+
def delete_glance_image(nova_client, image_id):
try:
nova_client.images.delete(image_id)