Example #1
0
    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())
Example #2
0
    def take_action(self, parsed_args):
        try:
            kolla_home = get_kolla_home()
            kolla_logs = get_kolla_log_dir()
            kolla_ansible = os.path.join(kolla_home, 'ansible')
            kolla_docs = os.path.join(kolla_home, 'docs')
            kolla_etc = get_kolla_etc()
            kolla_config = os.path.join(kolla_etc, 'config')
            kolla_globals = os.path.join(kolla_etc, 'globals.yml')
            kollacli_etc = get_kollacli_etc().rstrip('/')
            ketc = 'kolla/etc/'
            kshare = 'kolla/share/'
            fd, dump_path = tempfile.mkstemp(prefix='kollacli_dump_',
                                             suffix='.tgz')
            os.close(fd)  # avoid fd leak
            with tarfile.open(dump_path, 'w:gz') as tar:
                # Can't blanket add kolla_home because the .ssh dir is
                # accessible by the kolla user only (not kolla group)
                tar.add(kolla_ansible,
                        arcname=kshare + os.path.basename(kolla_ansible))
                tar.add(kolla_docs,
                        arcname=kshare + os.path.basename(kolla_docs))

                # Can't blanket add kolla_etc because the passwords.yml
                # file is accessible by the kolla user only (not kolla group)
                tar.add(kolla_config,
                        arcname=ketc + os.path.basename(kolla_config))
                tar.add(kolla_globals,
                        arcname=ketc + os.path.basename(kolla_globals))
                tar.add(kollacli_etc,
                        arcname=ketc + os.path.basename(kollacli_etc))

                # add kolla log files
                if os.path.isdir(kolla_logs):
                    tar.add(kolla_logs)

                # add output of various commands
                self._add_cmd_info(tar)

            self.log.info('dump successful to %s' % dump_path)
        except Exception:
            raise Exception(traceback.format_exc())
Example #3
0
    def __init__(self):
        """initialize ansible property information

        property information is pulled from the following files:
        KOLLA_ETC/globals.yml
        KOLLA_ETC/passwords.yml
        KOLLA_HOME/group_vars/all.yml
        KOLLA_HOME/ansible/roles/<service>/default/main.yml
        """
        kolla_etc = get_kolla_etc()
        kolla_home = get_kolla_home()

        self.allvars_path = ''
        self.globals_path = ''
        self.properties = []
        self.unique_properties = {}
        # this is so for any given property
        # we can look up the file it is in easily, to be used for the
        # property set command
        self.file_contents = {}

        try:
            start_dir = os.path.join(kolla_home, ANSIBLE_ROLES_PATH)
            services = next(os.walk(start_dir))[1]
            for service_name in services:
                file_name = os.path.join(start_dir, service_name,
                                         ANSIBLE_DEFAULTS_PATH)
                if os.path.isfile(file_name):
                    with open(file_name) as service_file:
                        service_contents = yaml.load(service_file)
                        self.file_contents[file_name] = service_contents
                        service_contents = self.filter_jinja2(service_contents)
                        prop_file_name = service_name + ':main.yml'
                        for key, value in service_contents.items():
                            ansible_property = AnsibleProperty(
                                key, value, prop_file_name)
                            self.properties.append(ansible_property)
                            self.unique_properties[key] = ansible_property
        except Exception as e:
            raise e

        try:
            self.allvars_path = os.path.join(kolla_home, ALLVARS_PATH)
            with open(self.allvars_path) as allvars_file:
                allvars_contents = yaml.load(allvars_file)
                self.file_contents[self.allvars_path] = allvars_contents
                allvars_contents = self.filter_jinja2(allvars_contents)
                for key, value in allvars_contents.items():
                    ansible_property = AnsibleProperty(key, value,
                                                       'group_vars/all.yml')
                    self.properties.append(ansible_property)
                    self.unique_properties[key] = ansible_property
        except Exception as e:
            raise e

        try:
            self.globals_path = os.path.join(kolla_etc, GLOBALS_FILENAME)
            globals_data = sync_read_file(self.globals_path)
            globals_contents = yaml.load(globals_data)
            self.file_contents[self.globals_path] = globals_contents
            globals_contents = self.filter_jinja2(globals_contents)
            for key, value in globals_contents.items():
                ansible_property = AnsibleProperty(key, value,
                                                   GLOBALS_FILENAME)
                self.properties.append(ansible_property)
                self.unique_properties[key] = ansible_property
        except Exception as e:
            raise e
    def __init__(self):
        """initialize ansible property information

        property information is pulled from the following files:
        KOLLA_ETC/globals.yml
        KOLLA_ETC/passwords.yml
        KOLLA_HOME/group_vars/all.yml
        KOLLA_HOME/ansible/roles/<service>/default/main.yml
        """
        kolla_etc = get_kolla_etc()
        kolla_home = get_kolla_home()

        self.allvars_path = ''
        self.globals_path = ''
        self.properties = []
        self.unique_properties = {}
        # this is so for any given property
        # we can look up the file it is in easily, to be used for the
        # property set command
        self.file_contents = {}

        try:
            start_dir = os.path.join(kolla_home, ANSIBLE_ROLES_PATH)
            services = next(os.walk(start_dir))[1]
            for service_name in services:
                file_name = os.path.join(start_dir, service_name,
                                         ANSIBLE_DEFAULTS_PATH)
                if os.path.isfile(file_name):
                    with open(file_name) as service_file:
                        service_contents = yaml.load(service_file)
                        self.file_contents[file_name] = service_contents
                        service_contents = self.filter_jinja2(service_contents)
                        prop_file_name = service_name + ':main.yml'
                        for key, value in service_contents.items():
                            ansible_property = AnsibleProperty(key, value,
                                                               prop_file_name)
                            self.properties.append(ansible_property)
                            self.unique_properties[key] = ansible_property
        except Exception as e:
            raise e

        try:
            self.allvars_path = os.path.join(kolla_home, ALLVARS_PATH)
            with open(self.allvars_path) as allvars_file:
                allvars_contents = yaml.load(allvars_file)
                self.file_contents[self.allvars_path] = allvars_contents
                allvars_contents = self.filter_jinja2(allvars_contents)
                for key, value in allvars_contents.items():
                    ansible_property = AnsibleProperty(key, value,
                                                       'group_vars/all.yml')
                    self.properties.append(ansible_property)
                    self.unique_properties[key] = ansible_property
        except Exception as e:
            raise e

        try:
            self.globals_path = os.path.join(kolla_etc, GLOBALS_FILENAME)
            globals_data = sync_read_file(self.globals_path)
            globals_contents = yaml.load(globals_data)
            self.file_contents[self.globals_path] = globals_contents
            globals_contents = self.filter_jinja2(globals_contents)
            for key, value in globals_contents.items():
                ansible_property = AnsibleProperty(key, value,
                                                   GLOBALS_FILENAME)
                self.properties.append(ansible_property)
                self.unique_properties[key] = ansible_property
        except Exception as e:
            raise e