Rundeck Resources

Gitlab-CI Pipeline CodeCov.io Documentation Status Pypi Package Version Python Versions Supported BSD License

Python tool to query resources from different sources and export them into a data structure that Rundeck can consume.

Installation

pip install rundeck-resources

Usage

$ rundeck-resources -h
usage: rundeck-resources [-h] [-v] [-l LOGGER] [--no-cache] [-V] config

Generates rundeck resources file from different API sources.

positional arguments:
  config                Configuration file.

optional arguments:
  -h, --help            show this help message and exit
  -v, --verbose         Verbosity level to use.
  -l LOGGER, --logger LOGGER
                        The logger YAML configuration file.
  --no-cache            Do not use cache.
  -V, --version         Prints version.

The rundeck-resources requires an INI configuration file. You can see the example configuration in the example.ini.

Docker

There is a docker image tagged with the version of the released package.

ENV OPTIONAL DESCRIPTION
ARGS True The command line arguments.
CONFIG False The path to the configuration file.
Usage:
$ docker run -it -v ~/config/:/config \
  -v ~/export/:/export \
  -e ARGS="-vvv" -e CONFIG="/config/config.ini" \
  elazkani/rundeck-resources
Assumptions:
  • ~/config/ holds the config.ini configuration file.
  • The configuration is set to export to the /export/ path.
  • /export will hold the resources exported file inside the container.
  • ~/export/ exists on the host.

Importers

rundeck-resources currently offer the following importers:
  • Chef: ChefImporter

Exporters

rundeck-resources currently offers the following exporters:
  • YAML: YAMLExporter

Contributors:

CLI

rundeck_resources.cli.argument_parse()[source]

Method to extract the arguments from the command line.

Return type:ArgumentParser
Returns:The argument parser.
rundeck_resources.cli.export_resources(interfaces, resources)[source]

Method to export the resources using the output interfaces.

Parameters:
  • interfaces (list) – The list of initialized output interfaces.
  • resources (dict) – The resources provided by the input interfaces.
Return type:

None

rundeck_resources.cli.import_resources(interfaces)[source]

Method to get all resources from the input interfaces.

Parameters:interfaces (list) – The list of initialized input interfaces.
Return type:dict
Returns:The resources returned by the input interfaces.
rundeck_resources.cli.initialize_export_interfaces(config, plugins)[source]

Method to initialize the interfaces with the configuration.

Parameters:
  • config (dict) – The configuration file content.
  • plugins (dict) – The list of loaded plugins.
Return type:

list

Returns:

The list of loaded plugins initialized.

rundeck_resources.cli.initialize_import_interfaces(config, plugins, cache)[source]

Method to initialize the interfaces with the configuration.

Parameters:
  • config (dict) – The configuration file content.
  • plugins (dict) – The list of loaded plugins.
  • cache (Cache) – The cache system instance.
Return type:

list

Returns:

The list of loaded plugins initialized.

rundeck_resources.cli.load_exporters(config)[source]

Method to load the Exporters plugins configured in the configuration file.

Parameters:config – The configuration file content.
Returns:The Exporters plugins, loaded.
rundeck_resources.cli.load_importers(config)[source]

Method to load the Importers plugins configured in the configuration file.

Parameters:config – The configuration file content.
Returns:The Importers plugins, loaded.
rundeck_resources.cli.main()[source]

Main method.

Return type:None
rundeck_resources.cli.verbosity(verbose)[source]

Method to set the verbosity.

Parameters:verbose (int) – The verbosity set by user.
Returns:The verbosity level.

Errors

exception rundeck_resources.errors.CacheNotFound(message=None)[source]

Custom CacheNotFound exception. We raise this exception when no plugin cache have been found.

exception rundeck_resources.errors.ConfigError(message=None)[source]

Custom ConfigError exception. We raise this exception when a configuration error is encountered.

exception rundeck_resources.errors.NoResourcesFound(message=None)[source]

Custom NoResourcesFound exception. We raise this exception when no resources have been returned from the importers.

Logger

rundeck_resources.logger.setup_logging(default_path=None, default_level=40, env_key='LOG_CFG')[source]

Method that sets the logging system up.

Parameters:
  • default_path (Optional[str]) – The path to the logger configuration.
  • default_level (int) – The default logging level (DEFAULT: ERROR)
  • env_key (str) – The environment variable specifying the path to the configuration file.
Return type:

None

Cache

class rundeck_resources.cache.Cache(config, no_cache)[source]

A cache module the plugins can take advantage of in case the APIs do not return data or the server is down.

cache(plugin, resources)[source]

Method to cache plugin data.

Parameters:
  • plugin (str) – The plugin name to cache data for.
  • resources (dict) – The resources data to cache.
Return type:

None

invalidate(plugin)[source]

Method to invalidate a plugin cache file.

Parameters:plugin (str) – The plugin name to invalidate the cache file for.
Return type:None
load_cache(config)[source]

Method to search for all configured plugins cache files

Parameters:config (dict) – the configuration provided by config.read_config.
Return type:dict
Returns:The cache configuration that includes paths to all plugin cache files.
static translate_to_filename(plugin_name)[source]

Static method to translate the plugin name to a standard prefix that could be used in a standard matter in the Cache class.

Parameters:plugin_name (str) – The plugin to translate the name for.
Return type:str
Returns:The translated plugin name.
uncache(plugin)[source]

Method to read cached data for a specific plugin.

Parameters:plugin (str) – The plugin to read cached data for.
Raises:CacheNotFound
Return type:dict

Common

rundeck_resources.common.check_file(path)[source]

Method to normalize the path of a file and check if the file exists and is a file.

Parameters:path (str) – The file path to check.
Return type:str
Returns:The absolute path of a file.
Raises:FileNotFoundError
rundeck_resources.common.get_section(plugin, title)[source]

Construct the configuration section

Parameters:
  • plugin (str) – The plugin name.
  • title (str) – The title seperated by : in the configuration file.
Return type:

str

Returns:

The configuration section to pull from the configuration file.

rundeck_resources.common.normalize_path(path)[source]

Method to expand and return an absolute path from a normal path.

Parameters:path (str) – The path to normalize.
Return type:str
Returns:The absolute path.

Config

rundeck_resources.config.read_config(path)[source]

Method to read the init configuration file.

Parameters:path (str) – The path to the init configuration file.
Return type:dict
Returns:The content of the configuration file.

Interfaces

class rundeck_resources.interfaces.ResourcesExporter[source]

ResourcesExporter interface definition

export_resources(resources)[source]

This method is expected to save the data into a rundeck resources formatted file.

Parameters:resources (dict) – The resources to save into the resources file.
Return type:None
class rundeck_resources.interfaces.ResourcesImporter[source]

ResourcesImporter interface definition

import_resources()[source]

This method is expected to export the data into a rundeck data structure that can be easily saved

Return type:dict
Returns:Resources data.

Plugins

rundeck_resources.plugins.get_plugins(resource_types)[source]

Method to get the plugins defined in the entry_point.

Parameters:resource_types (str) – The resource type to get (Input, Output).
Return type:dict
Returns:The entry points by name.
rundeck_resources.plugins.load_plugins(config, resource_types)[source]

Method to load plugins defined in the entry_point by resource_type.

Parameters:
  • config (dict) – The configuration file content.
  • resource_types (str) – The resource type to load (Input, Output).
Return type:

dict

Returns:

The plugins loaded.

Chef Importer

class rundeck_resources.chef_importer.ChefImporter(title, config, cache)[source]

A Chef node information importer

static call_chef(config)[source]

Method to query the chef server.

Parameters:config (dict) – The chef configuration.
Return type:dict
Returns:The chef nodes information.
static expand_paths(config)[source]

Method to expand file paths for the user certificate and the chef ssl certificate.

Parameters:config (dict) – The chef configuration.
Return type:dict
Returns:The chef configuration with expanded paths.
static expand_ssl_cert_path(ssl_cert_path)[source]

Method to return expanded and checked ssl_cert_path.

Parameters:user_cert_path – The chef server SSL certificate path.
Return type:str
Returns:The check expanded chef server SSL certificate path.
static expand_user_cert_path(user_cert_path)[source]

Method to return expanded and checked user_cert_path.

Parameters:user_cert_path (str) – The user certificate path.
Return type:str
Returns:The check expanded user certificate path.
get_chef_nodes()[source]

Method to get the chef nodes information.

Return type:dict
Returns:The chef nodes information.
import_resources()[source]

Method to format chef resources into rundeck resources.

Return type:dict
Returns:Rundeck formatted nodes resources.

YAML Exporter

class rundeck_resources.yaml_exporter.YAMLExporter(title, config={})[source]

The YAML rundeck exporter class

static export_path(config)[source]

Method to get the rundeck export file in absolute path format.

Parameters:config (dict) – The Rundeck section of the configuration.
Return type:str
Returns:The file path of rundeck resources to export to.
export_resources(dictionary)[source]

Method to save nodes’ information into a rundeck nodes resources YAML file.

Parameters:dictionary (dict) – Rundeck formatted nodes information.
Return type:None

Indices and tables