Пример #1
0
    def extra_data(self, role_uuid):
        """Retrieve the extra data files associated with a given role.

        :param role_uuid: identifies the role
        :type  role_uuid: str

        :return: a dict where keys are filenames and values are their contents
        :rtype:  dict

        This method will retrieve all stored role_extra records (these are
        created at the same time that the Roles are, by using --role-extra
        parameter to tuskar-load-roles).

        The internal representation for a given role-extra file encodes the
        file extension into the name. For instance 'hieradata/compute.yaml'
        is stored as 'extra_compute_yaml'.

        The given role's template is searched for 'get_file' directives and
        then matched against the stored role-extra records (based on their
        name... e.g. 'extra_controller_yaml' we look for 'controller.yaml'
        after a get_file directive).

        This method thus returns all the matched role-extra files for the
        given role. The keys will include the relative path if one is
        used in the role template:
        {
            "hieradata/common.yaml": "CONTENTS",
            "hieradata/controller.yaml": "CONTENTS",
            "hieradata/object.yaml": "CONTENTS"
        }

        """
        manager = RoleManager()
        db_role = manager.retrieve_db_role_by_uuid(role_uuid)
        db_role_extra = manager.retrieve_db_role_extra()
        role_extra_paths = utils.resolve_template_extra_data(
            db_role, db_role_extra)
        return manager.template_extra_data_for_output(role_extra_paths)