Exemplo n.º 1
0
    def __init__(self, conf_file=None, defs_file=None):

        self._base_defs = {}
        self._plugins = {}
        self._parsers = {}

        self._config_file = conf_file
        self.data = ConfigData()

        self._base_defs = self._read_config_yaml_file(defs_file or ('%s/base.yml' % os.path.dirname(__file__)))

        if self._config_file is None:
            # set config using ini
            self._config_file = find_ini_config_file(self.WARNINGS)

        # consume configuration
        if self._config_file:
            # initialize parser and read config
            self._parse_config_file()

        # update constants
        self.update_config_data()
        try:
            self.update_module_defaults_groups()
        except Exception as e:
            # Since this is a 2.7 preview feature, we want to have it fail as gracefully as possible when there are issues.
            sys.stderr.write('Could not load module_defaults_groups: %s: %s\n\n' % (type(e).__name__, e))
            self.module_defaults_groups = {}
Exemplo n.º 2
0
    def __init__(self, conf_file=None):

        self._base_defs = {}
        self._plugins = {}
        self._parser = None

        self._config_file = conf_file
        self.data = ConfigData()

        # FIXME: make dynamic? scan for more? make it's own method?
        # Create configuration definitions from source
        bconfig_def = to_bytes('%s/base.yml' % os.path.dirname(__file__))
        if os.path.exists(bconfig_def):
            with open(bconfig_def, 'rb') as config_def:
                self._base_defs = yaml.safe_load(config_def)
        else:
            raise AnsibleError(
                "Missing base configuration definition file (bad install?): %s"
                % to_native(bconfig_def))

        if self._config_file is None:
            # set config using ini
            self._config_file = find_ini_config_file()

        if self._config_file:
            if os.path.exists(self._config_file):
                # initialize parser and read config
                self._parse_config_file()

        # update constants
        self.update_config_data()
Exemplo n.º 3
0
    def __init__(self, conf_file=None, defs_file=None):

        self._base_defs = {}
        self._plugins = {}
        self._parsers = {}

        self._config_file = conf_file
        self.data = ConfigData()

        if defs_file is None:
            # Create configuration definitions from source
            b_defs_file = to_bytes('%s/base.yml' % os.path.dirname(__file__))
        else:
            b_defs_file = to_bytes(defs_file)

        # consume definitions
        if os.path.exists(b_defs_file):
            with open(b_defs_file, 'rb') as config_def:
                self._base_defs = yaml_load(config_def, Loader=SafeLoader)
        else:
            raise AnsibleError("Missing base configuration definition file (bad install?): %s" % to_native(b_defs_file))

        if self._config_file is None:
            # set config using ini
            self._config_file = find_ini_config_file()

        # consume configuration
        if self._config_file:
            if os.path.exists(self._config_file):
                # initialize parser and read config
                self._parse_config_file()

        # update constants
        self.update_config_data()
Exemplo n.º 4
0
    def __init__(self, conf_file=None):

        self.data = ConfigData()

        #FIXME: make dynamic?
        bconfig_def = to_bytes('%s/data/config.yml' %
                               os.path.dirname(__file__))
        if os.path.exists(bconfig_def):
            with open(bconfig_def, 'rb') as config_def:
                self.initial_defs = yaml.safe_load(config_def)
        else:
            raise AnsibleError(
                "Missing base configuration definition file (bad install?): %s"
                % to_native(bconfig_def))

        ftype = None
        if conf_file is None:
            # set config using ini
            conf_file = self.find_ini_config_file()
            ftype = 'ini'
        else:
            ext = os.path.splitext(conf_file)[-1]
            if ext in ('.ini', '.cfg'):
                ftype = 'ini'
            elif ext in ('.yaml', '.yml'):
                ftype = 'yaml'
            else:
                raise AnsibleOptionsError(
                    "Unsupported configuration file extension: \n{0}".format(
                        ext))

        self.parse_config(conf_file, ftype)
Exemplo n.º 5
0
    def __init__(self, conf_file=None, defs_file=None):

        self._base_defs = {}
        self._plugins = {}
        self._parsers = {}

        self._config_file = conf_file
        self.data = ConfigData()

        self._base_defs = self._read_config_yaml_file(defs_file or ('%s/base.yml' % os.path.dirname(__file__)))

        if self._config_file is None:
            # set config using ini
            self._config_file = find_ini_config_file(self.WARNINGS)

        # consume configuration
        if self._config_file:
            # initialize parser and read config
            self._parse_config_file()

        # update constants
        self.update_config_data()
 def setUp(self):
     self.cdata = ConfigData()