From 7ce18a33d8b53057a99739da345d02c39f94a130 Mon Sep 17 00:00:00 2001 From: Sergey Reshetnyak Date: Wed, 26 Oct 2016 19:51:26 +0300 Subject: [PATCH] Add glance images cleanup This patch adds deleting all glance images for ccp cleanup command Change-Id: Id0813980a65bc91a3b7adc9599ea76cadbbc4a9b --- fuel_ccp/cleanup.py | 18 ++++++++++++++++++ requirements.txt | 11 ++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/fuel_ccp/cleanup.py b/fuel_ccp/cleanup.py index 759c3d1f..8a45c747 100644 --- a/fuel_ccp/cleanup.py +++ b/fuel_ccp/cleanup.py @@ -1,6 +1,7 @@ import logging import time +from glanceclient import client as glance_client from keystoneauth1 import exceptions as keystoneauth_exceptions from keystoneauth1.identity import v3 from keystoneauth1 import session as keystone_session @@ -92,6 +93,14 @@ def _cleanup_network_resources(session): for network in network_list['networks']])) +def _cleanup_images(session): + LOG.debug("Cleaning up glance images") + glance = glance_client.Client("2", session=session) + for image in glance.images.list(): + LOG.debug("Removing glance image %s", image.id) + glance.images.delete(image.id) + + def _cleanup_openstack_environment(configs, auth_url=None): if 'project_name' not in configs.get('openstack', {}): # Ensure that keystone configs are provided. Assume that it is not an @@ -118,17 +127,26 @@ def _cleanup_openstack_environment(configs, auth_url=None): 'Run with --skip-os-cleanup flag if OpenStack ' 'is not deployed', configs['auth_url']) raise + try: _cleanup_servers(session) except keystoneauth_exceptions.EndpointNotFound: LOG.info('Nova is not present, skipping instances cleanup') pass + + try: + _cleanup_images(session) + except keystoneauth_exceptions.EndpointNotFound: + LOG.info('Glance is not present, skipping images cleanup') + pass + try: _cleanup_network_resources(session) except keystoneauth_exceptions.EndpointNotFound: LOG.info('Neutron is not present, skipping network resources ' 'cleanup') pass + LOG.info('OpenStack cleanup has been finished successfully.') diff --git a/requirements.txt b/requirements.txt index a94e169f..42f1c48c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,15 +4,16 @@ pbr>=1.6 # Apache-2.0 -cliff>=2.2.0 # Apache-2.0 -futures>=3.0;python_version=='2.7' or python_version=='2.6' # BSD -docker-py<1.8.0,>=1.6.0 # Apache-2.0 GitPython>=1.0.1 # BSD License (3 clause) Jinja2>=2.8 # BSD License (3 clause) -jsonschema!=2.5.0,<3.0.0,>=2.0.0 # MIT PyYAML>=3.10.0 # MIT -six>=1.9.0 # MIT +cliff>=2.2.0 # Apache-2.0 +docker-py<1.8.0,>=1.6.0 # Apache-2.0 +futures>=3.0;python_version=='2.7' or python_version=='2.6' # BSD +jsonschema!=2.5.0,<3.0.0,>=2.0.0 # MIT keystoneauth1>=2.10.0 # Apache-2.0 pykube # Apache-2.0 +python-glanceclient>=2.5.0 # Apache-2.0 python-neutronclient>=5.1.0 # Apache-2.0 python-novaclient!=2.33.0,>=2.29.0 # Apache-2.0 +six>=1.9.0 # MIT