diff options
author | Morgan Richomme <morgan.richomme@orange.com> | 2016-08-26 06:48:26 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@172.30.200.206> | 2016-08-26 06:48:26 +0000 |
commit | 874eac1d00c9624d084b3c7b01075a7645c5b840 (patch) | |
tree | e5716aad90288dfaa9d39fc550571862381f6e87 /utils | |
parent | 2b22d89b5a3dc212774d0a426e53d569f98173a7 (diff) | |
parent | 5f5af6b1d8d0af19db143e67f04f67a643af863c (diff) |
Merge "refactor create or get image process to eliminate reduplicate"
Diffstat (limited to 'utils')
-rwxr-xr-x | utils/openstack_utils.py | 20 |
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) |