summaryrefslogtreecommitdiffstats
path: root/snaps/openstack/create_image.py
diff options
context:
space:
mode:
authorspisarski <s.pisarski@cablelabs.com>2017-04-20 14:15:30 -0600
committerspisarski <s.pisarski@cablelabs.com>2017-04-26 09:18:20 +0200
commitbecbbabc63b0eff15ed6979947aeb75ddf6819c9 (patch)
treee88dfc06420ddaa66745df6523a25ceb80f3417f /snaps/openstack/create_image.py
parent02fa5b4fcc78e8ea7cb34acd1175ede6af48df00 (diff)
Added support for Glance v2
Updated copyright date on new and edited files to current year. JIRA: SNAPS-66 Change-Id: I491157d6ced8bd9322f99272fc14e00168faaf29 Signed-off-by: spisarski <s.pisarski@cablelabs.com>
Diffstat (limited to 'snaps/openstack/create_image.py')
-rw-r--r--snaps/openstack/create_image.py31
1 files changed, 13 insertions, 18 deletions
diff --git a/snaps/openstack/create_image.py b/snaps/openstack/create_image.py
index bffa7de..6ced052 100644
--- a/snaps/openstack/create_image.py
+++ b/snaps/openstack/create_image.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2016 Cable Television Laboratories, Inc. ("CableLabs")
+# Copyright (c) 2017 Cable Television Laboratories, Inc. ("CableLabs")
# and others. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,7 +17,7 @@ import time
from glanceclient.exc import HTTPNotFound
-from snaps.openstack.utils import glance_utils, nova_utils
+from snaps.openstack.utils import glance_utils
__author__ = 'spisarski'
@@ -47,25 +47,22 @@ class OpenStackImage:
def create(self, cleanup=False):
"""
- Creates the image in OpenStack if it does not already exist
+ Creates the image in OpenStack if it does not already exist and returns the domain Image object
:param cleanup: Denotes whether or not this is being called for cleanup or not
:return: The OpenStack Image object
"""
- from snaps.openstack.utils import nova_utils
- nova = nova_utils.nova_client(self.__os_creds)
-
- self.__image = glance_utils.get_image(nova, self.__glance, self.image_settings.name)
+ self.__image = glance_utils.get_image(self.__glance, self.image_settings.name)
if self.__image:
logger.info('Found image with name - ' + self.image_settings.name)
return self.__image
elif not cleanup:
self.__image = glance_utils.create_image(self.__glance, self.image_settings)
logger.info('Creating image')
- if self.image_active(block=True):
+ if self.__image and self.image_active(block=True):
logger.info('Image is now active with name - ' + self.image_settings.name)
return self.__image
else:
- raise Exception('Image did not activate in the alloted amount of time')
+ raise Exception('Image was not created or activated in the alloted amount of time')
else:
logger.info('Did not create image due to cleanup mode')
@@ -85,7 +82,7 @@ class OpenStackImage:
def get_image(self):
"""
- Returns the OpenStack image object as it was populated when create() was called
+ Returns the domain Image object as it was populated when create() was called
:return: the object
"""
return self.__image
@@ -135,17 +132,15 @@ class OpenStackImage:
:return: T/F
"""
# TODO - Place this API call into glance_utils.
- nova = nova_utils.nova_client(self.__os_creds)
- instance = glance_utils.get_image(nova, self.__glance, self.image_settings.name)
- # instance = self.__glance.images.get(self.__image)
- if not instance:
- logger.warn('Cannot find instance with id - ' + self.__image.id)
+ status = glance_utils.get_image_status(self.__glance, self.__image)
+ if not status:
+ logger.warn('Cannot image status for image with ID - ' + self.__image.id)
return False
- if instance.status == 'ERROR':
+ if status == 'ERROR':
raise Exception('Instance had an error during deployment')
- logger.debug('Instance status is - ' + instance.status)
- return instance.status == expected_status_code
+ logger.debug('Instance status is - ' + status)
+ return status == expected_status_code
class ImageSettings: