hiera-py¶
Python interface for the hiera hierarchical database.
See the documentation on puppetlabs.com for more detail.
Contents:
Introduction¶
Installation¶
pip install hiera-py
# Or, if you prefer easy_install:
easy_install hiera-py
# Or, if you prefer to install from source:
python setup.py install
Getting Started¶
>>> import hiera
>>> hiera_client = hiera.HieraClient('/etc/hiera.yml', environment='dev')
>>> hiera_client.get('my_key')
'my_value'
>>> hiera_client.get('nonexistent_key')
Traceback (most recent call last):
...
hiera.exc.HieraError: Failed to retrieve key nonexistent_key. ...
Reference¶
Python client for Hiera hierachical database.
- class hiera.client.HieraClient(config_filename, hiera_binary='hiera', **kwargs)¶
Python client for Hiera hierachical database.
- __init__(config_filename, hiera_binary='hiera', **kwargs)¶
Create a new instance with the given settings.
Key value params passed into this will be added to the environment when running the hiera client. For example, (environment=’developer’, osfamily=’Debian’) as keyword args to __init__ would result in hiera calls like this:
hiera –config <config_filename> <key> environment=developer osfamily=Debian
- Parameters:
config_filename – Path to the hiera configuration file.
hiera_binary – Path to the hiera binary. Defaults to ‘hiera’.
- get(key_name)¶
Request the given key from hiera.
Returns the string version of the key when successful.
Raises
hiera.exc.HieraError
if the key does not exist or there was an error invoking hiera. Raiseshiera.exc.HieraNotFoundError
if the hiera CLI binary could not be found.- Parameters:
key_name – string key
- Return type:
str value for key or None
- class hiera.HieraClient(config_filename, hiera_binary='hiera', **kwargs)¶
Python client for Hiera hierachical database.
- __init__(config_filename, hiera_binary='hiera', **kwargs)¶
Create a new instance with the given settings.
Key value params passed into this will be added to the environment when running the hiera client. For example, (environment=’developer’, osfamily=’Debian’) as keyword args to __init__ would result in hiera calls like this:
hiera –config <config_filename> <key> environment=developer osfamily=Debian
- Parameters:
config_filename – Path to the hiera configuration file.
hiera_binary – Path to the hiera binary. Defaults to ‘hiera’.
- get(key_name)¶
Request the given key from hiera.
Returns the string version of the key when successful.
Raises
hiera.exc.HieraError
if the key does not exist or there was an error invoking hiera. Raiseshiera.exc.HieraNotFoundError
if the hiera CLI binary could not be found.- Parameters:
key_name – string key
- Return type:
str value for key or None
Exceptions¶
Exceptions for specific hiera issues.
- class hiera.exc.HieraError(message, returncode=None, output=None)¶
Generic Hiera error.
- __init__(message, returncode=None, output=None)¶
Override instance init so that return code and console output can be added to error.
- class hiera.exc.HieraNotFoundError¶
Hiera error indicating the hiera CLI could not be found.
Development¶
Testing¶
Tox is used to run the tests. Travis automatically verifies commits. It uses python 2.7 and pep8.
# Run the tests against python 2.7.
tox
# Run the tests against python 2.7 with code coverage.
tox -e cover
# Run the tests against a bunch of python versions.
tox -e py25,py26,py27,py31,py32,py33,pypy
TODO¶
Things I would like to do, eventually…
Add additional accessors for array and hash types.
Add support for scope files (either yaml or json format).
Support more python versions
License¶
BSD