linchpin.api module

This page contains the list of project’s modules

class linchpin.api.LinchpinAPI(ctx)
__init__(ctx)

LinchpinAPI constructor

Parameters:ctx – context object from api/context.py
lp_up(pinfile, targets='all', run_id=None)

This function takes a list of targets, and provisions them according to their topology. If an layout argument is provided, an inventory will be generated for the provisioned nodes.

Parameters:
  • pinfile – Provided PinFile, with available targets,
  • targets – A tuple of targets to provision.
lp_destroy(pinfile, targets='all', run_id=None)

This function takes a list of targets, and performs a destructive teardown, including undefining nodes, according to the target.

See also

lp_down - currently unimplemented

Parameters:
  • pinfile – Provided PinFile, with available targets,
  • targets – A tuple of targets to destroy.
lp_down(pinfile, targets='all')

This function takes a list of targets, and performs a shutdown on nodes in the target’s topology. Only providers which support shutdown from their API (Ansible) will support this option.

CURRENTLY UNIMPLEMENTED

See also

lp_destroy

Parameters:
  • pinfile – Provided PinFile, with available targets,
  • targets – A tuple of targets to provision.
run_playbook(pinfile, targets=[], action='up', run_id=None)

This function takes a list of targets, and executes the given action (up, destroy, etc.) for each provided target.

Parameters:
  • pinfile – Provided PinFile, with available targets,
  • targets – A tuple of targets to run. (default: ‘all’)
find_topology(topology)

Find the topology to be acted upon. This could be pulled from a registry.

Parameters:topology – name of topology from PinFile to be loaded
get_cfg(section=None, key=None, default=None)

Get cfgs value(s) by section and/or key, or the whole cfgs object

Parameters:
  • section – section from ini-style config file
  • key – key to get from config file, within section
  • default – default value to return if nothing is found.

Does not apply if section is not provided.

set_cfg(section, key, value)

Set a value in cfgs. Does not persist into a file, only during the current execution.

Parameters:
  • section – section within ini-style config file
  • key – key to use
  • value – value to set into section within config file
get_evar(key=None, default=None)

Get the current evars (extra_vars)

Parameters:
  • key – key to use
  • default – default value to return if nothing is found

(default: None)

set_evar(key, value)

Set a value into evars (extra_vars). Does not persist into a file, only during the current execution.

Parameters:
  • key – key to use
  • value – value to set into evars
lp_rise(pinfile, targets='all', run_id=None)

DEPRECATED

An alias for lp_up. Used only for backward compatibility.

lp_drop(pinfile, targets, run_id=None)

DEPRECATED

An alias for lp_destroy. Used only for backward compatibility.

class linchpin.api.context.LinchpinContext

LinchpinContext object, which will be used to manage the cli, and load the configuration file.

get_cfg(section=None, key=None, default=None)

Get cfgs value(s) by section and/or key, or the whole cfgs object

Parameters:
  • section – section from ini-style config file
  • key – key to get from config file, within section
  • default – default value to return if nothing is found.

Does not apply if section is not provided.

get_evar(key=None, default=None)

Get the current evars (extra_vars)

Parameters:
  • key – key to use
  • default – default value to return if nothing is found

(default: None)

load_config(lpconfig=None)

Create self.cfgs from the linchpin configuration file.

Note

Overrides load_config in linchpin.api.LinchpinContext

These are the only hardcoded values, which are used to find the config file. The search path consists of the following:

* /linchpin/library/path/linchpin.conf
* /etc/linchpin.conf
* ~/.config/linchpin/linchpin.conf
* path/to/workspace/linchpin.conf

Linchpin will continuously override and extend the configuration as newer configurations are added and modified. Alternatively, a full path to the linchpin configuration file can be passed.

Parameters:lpconfig – absolute path to a linchpin config (default: None)
load_global_evars()

Instantiate the evars variable, then load the variables from the ‘evars’ section in linchpin.conf. This will then be passed to invoke_linchpin, which passes them to the Ansible playbook as needed.

log(msg, **kwargs)

Logs a message to a logfile

Parameters:
  • msg – message to output to log
  • level – keyword argument defining the log level
log_debug(msg)

Logs a DEBUG message

log_info(msg)

Logs an INFO message

log_state(msg)

Logs nothing, just calls pass

Attention

state messages need to be implemented in a subclass

pinfile

getter function for pinfile name

set_cfg(section, key, value)

Set a value in cfgs. Does not persist into a file, only during the current execution.

Parameters:
  • section – section within ini-style config file
  • key – key to use
  • value – value to set into section within config file
set_evar(key, value)

Set a value into evars (extra_vars). Does not persist into a file, only during the current execution.

Parameters:
  • key – key to use
  • value – value to set into evars
setup_logging()

Setup logging to the console only

Attention

Please implement this function in a subclass

workspace

getter function for workspace

linchpin.api.utils.yaml2json(pf)

parses yaml file into json object