示例#1
0
def _print_pwd_keys(path):
    pwd_keys = ''
    prefix = ''
    pwd_data = utils.sync_read_file(path)
    for line in pwd_data.split('\n'):
        if line.startswith('#'):
            # skip commented lines
            continue
        if ':' in line:
            pwd_key = line.split(':')[0]
            pwd_keys = ''.join([pwd_keys, prefix, pwd_key])
            prefix = ','

    print(pwd_keys)
示例#2
0
    def load():
        """load the inventory from a pickle file"""
        inventory_path = os.path.join(utils.get_kollacli_etc(), INVENTORY_PATH)
        data = ''
        try:
            if os.path.exists(inventory_path):
                data = utils.sync_read_file(inventory_path)

            if data.strip():
                inventory = jsonpickle.decode(data)

                # upgrade version handling
                if inventory.version != inventory.class_version:
                    inventory.upgrade()
            else:
                inventory = Inventory()
        except Exception:
            raise CommandError('loading inventory failed: %s' %
                               traceback.format_exc())
        return inventory
示例#3
0
    def load():
        """load the inventory from a pickle file"""
        inventory_path = os.path.join(utils.get_kollacli_etc(), INVENTORY_PATH)
        data = ''
        try:
            if os.path.exists(inventory_path):
                data = utils.sync_read_file(inventory_path)

            if data.strip():
                inventory = jsonpickle.decode(data)

                # upgrade version handling
                if inventory.version != inventory.class_version:
                    inventory.upgrade()
            else:
                inventory = Inventory()
        except Exception:
            raise CommandError('loading inventory failed: %s'
                               % traceback.format_exc())
        return inventory
示例#4
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