diff options
author | 2016-05-19 14:08:47 +0300 | |
---|---|---|
committer | 2016-05-19 12:00:26 +0000 | |
commit | e12f3661b74d998bdd5b75761f9700fcbb837534 (patch) | |
tree | 72cf5c361c393c6ebefdd6bb3d39324a9ffb3fca /utils/clean_openstack.py | |
parent | 58c7d61bd5ceca0aed2b9e3888d0380970700029 (diff) |
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 <viktor.tikkanen@nokia.com>
Diffstat (limited to 'utils/clean_openstack.py')
-rw-r--r-- | utils/clean_openstack.py | 30 |
1 files 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): |