From e12f3661b74d998bdd5b75761f9700fcbb837534 Mon Sep 17 00:00:00 2001 From: vitikkan Date: Thu, 19 May 2016 14:08:47 +0300 Subject: Preserving Nova instances from os_defaults.yaml Previously clean_openstack deleted all the existing instances even if they were included into os_defaults.yaml. Change-Id: Id7c17ec86a5616c44bd2965844a4a8545054358b Signed-off-by: vitikkan --- utils/clean_openstack.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/utils/clean_openstack.py b/utils/clean_openstack.py index b3c0d351..70eced62 100644 --- a/utils/clean_openstack.py +++ b/utils/clean_openstack.py @@ -54,23 +54,29 @@ def remove_instances(nova_client, default_instances): for instance in instances: instance_name = getattr(instance, 'name') instance_id = getattr(instance, 'id') - logger.debug("Removing instance '%s', ID=%s ..." - % (instance_name, instance_id)) - if os_utils.delete_instance(nova_client, instance_id): - logger.debug(" > Done!") + logger.debug("'%s', ID=%s " % (instance_name, instance_id)) + if instance_id not in default_instances: + logger.debug("Removing instance '%s' ..." % instance_id) + if os_utils.delete_instance(nova_client, instance_id): + logger.debug(" > Request sent.") + else: + logger.error("There has been a problem removing the " + "instance %s..." % instance_id) else: - logger.error("There has been a problem removing the " - "instance %s..." % instance_id) + logger.debug(" > this is a default instance and will " + "NOT be deleted.") timeout = 50 while timeout > 0: instances = os_utils.get_instances(nova_client) - if instances is None or len(instances) == 0: - break - else: - logger.debug("Waiting for instances to be terminated...") - timeout -= 1 - time.sleep(1) + for instance in instances: + instance_id = getattr(instance, 'id') + if instance_id not in default_instances: + logger.debug("Waiting for instances to be terminated...") + timeout -= 1 + time.sleep(1) + continue + break def remove_images(nova_client, default_images): -- cgit 1.2.3-korg