def take_action(self, parsed_args): try: if parsed_args.hosts and parsed_args.groups: raise CommandError('Hosts and Groups arguments cannot both ' + 'be present at the same time.') self._run_rules() playbook = AnsiblePlaybook() kolla_home = get_kolla_home() playbook.playbook_path = os.path.join(kolla_home, 'ansible/site.yml') if parsed_args.hosts: host_list = parsed_args.hosts.strip() host_list = convert_to_unicode(host_list) playbook.hosts = host_list.split(',') if parsed_args.groups: group_list = parsed_args.groups.strip() group_list = convert_to_unicode(group_list) playbook.groups = group_list.split(',') if parsed_args.services: tag_list = parsed_args.services.strip() tag_list = convert_to_unicode(tag_list) playbook.services = tag_list.split(',') if parsed_args.serial: playbook.serial = True playbook.verbose_level = self.app.options.verbose_level playbook.run() except CommandError as e: raise e except Exception: raise Exception(traceback.format_exc())
def take_action(self, parsed_args): try: hostname = '' hostname = parsed_args.hostname.strip() hostname = convert_to_unicode(hostname) if hostname != 'all': inventory = Inventory.load() host = inventory.get_host(hostname) if not host: _host_not_found(self.log, hostname) destroy_type = 'kill' if parsed_args.stop: destroy_type = 'stop' self.log.info('please be patient as this may take a while.') ansible_properties = properties.AnsibleProperties() base_distro = \ ansible_properties.get_property('kolla_base_distro') install_type = \ ansible_properties.get_property('kolla_install_type') container_prefix = base_distro + '-' + install_type kollacli_home = get_kollacli_home() playbook = AnsiblePlaybook() playbook.playbook_path = os.path.join(kollacli_home, 'ansible/host_destroy.yml') playbook.extra_vars = 'hosts=' + hostname + \ ' prefix=' + container_prefix + \ ' destroy_type=' + destroy_type playbook.print_output = False playbook.verbose_level = self.app.options.verbose_level playbook.run() except CommandError as e: raise e except Exception as e: raise Exception(traceback.format_exc())