gc3libs.config — gc3pie development (SVN $Revision$) documentation

### Navigation

- index
- modules |
- next |
- previous |
- gc3pie development (SVN $Revision$) documentation »
- Programmer Documentation »
- GC3Libs programming API »

# gc3libs.config

Deal with GC3Pie configuration files.

class `gc3libs.config.` `Configuration`(*locations, **extra_args)

  In-memory representation of the GC3Pie configuration.

  This class provides facilities for:

  - parsing configuration files (methods `load()` and `merge_file()`);
  - validating the loaded values;
  - instanciating the internal GC3Pie objects resulting from the configuration (methods `make_auth()` and `make_resource()`).

  The constructor takes a list of files to load (locations) and a list of key=value pairs to provide defaults for the configuration. Both lists are optional and can be omitted, resulting in a configuration containing only GC3Pie default values.

  Example 1: initialization from config file:

      >>> import os
      >>> example_cfgfile = os.path.join(os.path.dirname(__file__), 'etc/gc3pie.conf.example')
      >>> cfg = Configuration(example_cfgfile)
      >>> cfg.debug
      '0'

  Example 2: initialization from key=value list:

      >>> cfg = Configuration(auto_enable_auth=False, foo=1, bar='baz')
      >>> cfg.auto_enable_auth
      False
      >>> cfg.foo
      1
      >>> cfg.bar
      'baz'

  When both a configuration file and a key=value list is present, values in the configuration files override those in the key=value list:

      >>> cfg = Configuration(example_cfgfile, debug=1)
      >>> cfg.debug
      '0'

  Example 3: default initialization:

      >>> cfg = Configuration()
      >>> cfg.auto_enable_auth
      True

  `auth_factory`

    The instance of `gc3libs.authentication.Auth` used to manage auth access for the resources.

    This is a read-only attribute, created upon first access with the values set in self.auths and self.auto_enabled.

  `load`(*locations)

    Merge settings from configuration files into this Configuration instance.

    Environment variables and ~ references are expanded in the location file names.

    If any of the specified files does not exist or cannot be read (for whatever reason), a message is logged but the error is ignored. However, a NoConfigurationFile exception is raised if none of the specified locations could be read.

    Raises gc3libs.exceptions.NoConfigurationFile:
    | if none of the specified files could be read.

  `make_auth`(name)

    Return factory for auth credentials configured in section `[auth/name]`.

  `make_resources`(ignore_errors=True)

    Make backend objects corresponding to the configured resources.

    Return a dictionary, mapping the resource name (string) into the corresponding backend object.

    By default, errors in constructing backends (e.g., due to a bad configuration) are silently ignored: the offending configuration is just dropped. This can be changed by setting the optional argument ignore_errors to False: in this case, an exception is raised whenever we fail to construct a backend.

  `merge_file`(filename)

    Read configuration files and merge the settings into this Configuration object.

    Contrary to `load()` (which see), the file name is taken literally and an error is raised if the file cannot be read for whatever reason.

    Any parameter which is set in the configuration files `[DEFAULT]` section, and whose name does not start with underscore (`_`) defines an attribute in the current Configuration.

    Warning

    No type conversion is performed on values set this way - so they all end up being strings!

    Raises gc3libs.exceptions.ConfigurationError:
    | if the configuration file does not exist, cannot be read, is corrupt or has wrong format.

### Navigation

- index
- modules |
- next |
- previous |
- gc3pie development (SVN $Revision$) documentation »
- Programmer Documentation »
- GC3Libs programming API »