Added support for removal of docker images during destroy

Change-Id: I77c5892546c992b083377acd195b2b1b852471f3
Jira-Issue: OSTACKDEV-142
This commit is contained in:
Borne Mace 2016-10-21 16:22:18 -07:00
parent 55da56990d
commit 9772b1ab28
3 changed files with 18 additions and 7 deletions

View File

@ -77,8 +77,8 @@ class AsyncApi(object):
return Job(ansible_job)
def async_host_destroy(self, hostnames, destroy_type, verbose_level=1,
include_data=False):
# type: (List[str], str, int, bool) -> Job
include_data=False, remove_images=False):
# type: (List[str], str, int, bool, bool) -> Job
"""Destroy Hosts.
Stops and removes all kolla related docker containers on the
@ -92,6 +92,8 @@ class AsyncApi(object):
:type verbose_level: integer
:param include_data: if true, destroy data containers too.
:type include_data: boolean
:param remove_images: if true, destroy will remove the docker images
:type remove_images: boolean
:return: Job object
:rtype: Job
"""
@ -99,6 +101,7 @@ class AsyncApi(object):
check_arg(destroy_type, u._('Destroy type'), str)
check_arg(verbose_level, u._('Verbose level'), int)
check_arg(include_data, u._('Include data'), bool)
check_arg(remove_images, u._('Remove images'), bool)
if destroy_type not in ['stop', 'kill']:
raise InvalidArgument(
u._('Invalid destroy type ({type}). Must be either '
@ -109,7 +112,7 @@ class AsyncApi(object):
inventory.validate_hostnames(hostnames)
ansible_job = actions.destroy_hosts(hostnames, destroy_type,
verbose_level, include_data)
verbose_level, include_data, remove_images)
return Job(ansible_job)
def async_host_precheck(self, hostnames, verbose_level=1):

View File

@ -68,6 +68,8 @@ class HostDestroy(Command):
help=u._('Stop rather than kill'))
parser.add_argument('--includedata', action='store_true',
help=u._('Destroy data containers'))
parser.add_argument('--removeimages', action='store_true',
help=u._('Remove docker images'))
return parser
def take_action(self, parsed_args):
@ -84,6 +86,9 @@ class HostDestroy(Command):
include_data = False
if parsed_args.includedata:
include_data = True
remove_images = False
if parsed_args.removeimages:
remove_images = True
if not include_data:
question = ('This will delete all containers and data'
@ -97,7 +102,8 @@ class HostDestroy(Command):
verbose_level = self.app.options.verbose_level
job = CLIENT.async_host_destroy(hostnames, destroy_type,
verbose_level, include_data)
verbose_level, include_data,
remove_images)
status = job.wait()
if verbose_level > 2:
LOG.info('\n\n' + 80 * '=')

View File

@ -31,12 +31,12 @@ LOG = logging.getLogger(__name__)
def destroy_hosts(hostnames, destroy_type,
verbose_level=1, include_data=False):
verbose_level=1, include_data=False,
remove_images=False):
'''destroy containers on a set of hosts.
The containers on the specified hosts will be stopped
or killed. That will be determined by the destroy_type,
which can either be 'stop' or 'kill'.
or killed.
'''
playbook = AnsiblePlaybook()
playbook_name = 'destroy.yml'
@ -49,6 +49,8 @@ def destroy_hosts(hostnames, destroy_type,
# 'hosts' is defined as 'all' in the playbook yml code, but inventory
# filtering will subset that down to the hosts in playbook.hosts.
playbook.hosts = hostnames
if remove_images:
playbook.extra_vars = 'destroy_include_images=yes'
if verbose_level <= 1:
playbook.print_output = False
playbook.verbose_level = verbose_level