added support for the stop command.

added a new ansible directory to hold kollacli specific playbooks
This commit is contained in:
Borne Mace 2015-09-17 13:00:17 -07:00
parent 0ac5ed13b1
commit 01091beddf
4 changed files with 91 additions and 0 deletions

9
ansible/stop.yml Normal file
View File

@ -0,0 +1,9 @@
---
- hosts: '{{ hosts }}'
tasks:
- name: stop kolla containers
shell: '{{ item }}'
ignore_errors: yes
with_items:
- docker stop $(docker ps -a | grep ol-openstack | awk '{print $1}')
- docker rm $(docker ps -a | grep ol-openstack | awk '{print $1}')

View File

@ -82,9 +82,11 @@ __EOF__
mkdir -m 0755 -p %{buildroot}/%{_sysconfdir}/kolla/kollacli
mkdir -m 0775 -p %{buildroot}/%{_sysconfdir}/kolla/kollacli/ansible
mkdir -m 0750 -p %{buildroot}/%{_datadir}/kolla/kollacli/tools
mkdir -m 0750 -p %{buildroot}/%{_datadir}/kolla/kollacli/ansible
# Install the required OpenStack Kolla files
cp -r tools/* %{buildroot}/%{_datadir}/kolla/kollacli/tools
cp -r ansible/* %{buildroot}/%{_datadir}/kolla/kollacli/ansible
# Create an empty inventory file
touch %{buildroot}/%{_sysconfdir}/kolla/kollacli/ansible/inventory.json
@ -103,6 +105,7 @@ rm -rf %{buildroot}
%attr(550, %{kolla_user}, %{kolla_group}) %dir %{_datadir}/kolla/kollacli/tools
%attr(555, %{kolla_user}, %{kolla_group}) %{_datadir}/kolla/kollacli/tools/json*
%attr(500, %{kolla_user}, %{kolla_group}) %{_datadir}/kolla/kollacli/tools/passwd*
%attr(550, %{kolla_user}, %{kolla_group}) %{_datadir}/kolla/kollacli/ansible/*.yml
%attr(-, %{kolla_user}, %{kolla_group}) %config(noreplace) %{_sysconfdir}/kolla/kollacli
@ -137,6 +140,10 @@ esac
%changelog
* Thu Sep 17 2015 - Borne Mace <borne.mace@oracle.com>
- Added the ansible directory under /usr/share/kolla/kollacli
- Added code to copy the kollacli specific playbooks into that directory
* Wed Sep 16 2015 - Wiekus Beukes <wiekus.beukes@oracle.com>
- Added the bash completion setup
- Added code to augment the kolla sudo file for the password mgmt piece

View File

@ -21,6 +21,7 @@ import traceback
from kollacli.ansible.inventory import Inventory
from kollacli.exceptions import CommandError
from kollacli.i18n import _
from kollacli.utils import convert_to_unicode
from kollacli.utils import get_kolla_etc
from kollacli.utils import get_kolla_home
from kollacli.utils import get_kollacli_etc
@ -170,3 +171,76 @@ class Setdeploy(Command):
raise e
except Exception:
raise Exception(traceback.format_exc())
class Stop(Command):
"""Stop
Stops and removes all containers on either the specified host
or if no host is specified, on all hosts.
"""
log = logging.getLogger(__name__)
def get_parser(self, prog_name):
parser = super(Stop, self).get_parser(prog_name)
parser.add_argument('hostname', nargs='?', metavar='[hostname]',
help='hostname')
return parser
def take_action(self, parsed_args):
try:
hostname = 'all'
if parsed_args.hostname:
hostname = parsed_args.hostname.strip()
hostname = convert_to_unicode(hostname)
inventory = Inventory.load()
if hostname != None and hostname != 'all':
host = inventory.get_host(hostname)
if not host:
raise CommandError(
'ERROR: Host (%s) not found. ' % hostname +
'Please add it with "host add"')
flag = ''
# verbose levels: 1=not verbose, 2=more verbose
if self.app.options.verbose_level > 1:
flag = '-vvv'
kollacli_home = get_kollacli_home()
command_string = 'sudo -u kolla ansible-playbook %s ' % flag
inventory_string = '-i ' + os.path.join(kollacli_home,
'tools',
'json_generator.py ')
playbook_string = ' ' + os.path.join(kollacli_home,
'ansible/stop.yml')
envvar_string = ' --extra-vars "hosts="' + hostname + '"'
cmd = command_string + inventory_string
cmd = cmd + playbook_string + envvar_string
print_output = False
if self.app.options.verbose_level > 1:
# log the ansible command
self.log.debug('cmd:' + cmd)
print_output = True
if self.app.options.verbose_level > 2:
# log the inventory
dbg_gen = os.path.join(kollacli_home, 'tools',
'json_generator.py ')
(inv, _) = \
subprocess.Popen(dbg_gen.split(' '),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE).communicate()
self.log.debug(inv)
err_flag, _ = run_cmd(cmd, print_output)
if err_flag:
raise Exception('stop failed')
self.log.info('stop succeeded')
except CommandError as e:
raise e
except Exception:
raise Exception(traceback.format_exc())

View File

@ -55,6 +55,7 @@ kolla.cli =
property_list = kollacli.property:PropertyList
service_list = kollacli.service:ServiceList
setdeploy = kollacli.common:Setdeploy
stop = kollacli.common:Stop
[extract_messages]
keywords = _ gettext ngettext l_ lazy_gettext