packme package

Submodules

packme.PackerTemplate module

class packme.PackerTemplate.PackerTemplate(name: str, yaml_node: dict, packages: List[str], packages_base_dir: str, templates_base_dir: str)

Bases: object

This class implements one packer template. Basically, a packer template is made of four sections: - description: a string that explains the purpose of the template - variables: a dictionary of variables used in the template through jinja2 mechanism - builders: a list of dictionaries where each dictionary defines the type of image that will be built - provisioners: a list of dictionaries where each dictionary defines actions used to configure the image - processors: a list of dictionaries where each dictionary defines actions to be run after the image is built

_load_packages(packages: List[str])

Load the non-standard package YAML file and append them as provisioners of this PackerTemplate.

Parameters:list – The non-standard packages to append.
_read_environment_file(environment_file)

Read YAML environemnt file and populate os.environ

Parameters:environment_file (str) – Path to the environment file.
_update_builder(builder: Dict[str, str])

Update some fields of a builder.

Parameters:builder (dict) – The builder to update.
_update_provisioner(provisioner: Dict[str, str], base_dir: str)

Update some fields of a provisioner.

Parameters:
  • provisioner (dict) – The provisioner to update.
  • base_dir (str) – The base directory for this provisioner.
builders

Returns the list of packer builders of this PackerTemplate.

description

Returns the description of this PackerTemplate.

dump(output_file: str, **kwargs)

Dump this PackerTemplate to a file.

Parameters:output_file (str) – The path to the output json file for this PackerTemplate.
name

Returns the name of this PackerTemplate.

postprocessors

Returns the postprocessors of this PackerTemplate.

provisioners

Returns the provisioners of this PackerTemplate.

set_parent(parent_template: packme.PackerTemplate.PackerTemplate)

Set the parent template to this PackerTemplate.

This defines a relationship for future packer run in the sense that the child template will start directly from the image of its parent template.

Parameters:parent_template (PackerTemplate) – The PackerTemplate of the parent template to connect the child template with.
variables

Returns the variables of this PackerTemplate.

packme.Packman module

class packme.Packman.Packman(input_file: str, templates_base_dir: Optional[str] = None, packages_base_dir: Optional[str] = None)

Bases: object

This class implements the Packman engine for generating packer template json files and run packer optionally .

_build_config_hierarchy(selected_templates: Optional[List[str]] = None)

Build the templates hierarchy.

A template can have a parent template. In that case for packer neig able to run on those templates, the parent tenplate must have been built before.

Getting a hierarchy of templates, the first one being the ones with no parent is the goal of this method.

Parameters:selected_templates (list, optional) – List of strings corresponding to the packer templates from which the hierarchy should be built.
Returns:Returns the hierarchy of templates from the one with no parent to the ones with parents.
Return type:list
_build_template(template_name: str) → packme.PackerTemplate.PackerTemplate

Build a PackerTemplate object from a template name.

Parameters:template_name (str) – The name of the template to build.
Returns:The template object used by packman to build the manifest.json file.
Return type:PackerTemplate
_build_template_hierarchy(template_name: str, hierarchy: List[str])

Build a single template hierarchy.

A template can have a parent template. In that case for packer neig able to run on those templates, the parent tenplate must have been built before.

Getting a hierarchy of templates, the first one being the ones with no parent is the goal of this method.

Parameters:
  • template_name (str) – The template on which the hierarchy will be built upon.
  • hierarchy (list) –

    A list of strings corresponding tot the template hierarchy.

    This argument is just used for passing the template hierarchy across recursive calls of this method.

build(selected_templates: Optional[List[str]] = None, **kwargs)

Build packer on the generated manifest.json files.

Parameters:
  • selected_templates (list, optional) – List of strings corresponding to the packer templates to build.
  • run (bool, optional) – If True packer will be run from the generated manifest.json files.
get_template(template_name)

Return the YAML contents of a given template. PackerTemplate

Parameters:selected_templates (list, optional) – List of strings corresponding to the packer templates from which the hierarchy should be built.
Returns:Returns the hierarchy of templates from the one with no parent to the ones with parents.
Return type:list
get_templates_selection(selected_templates=None)

Filter out a template selection from those which are not actual ones.

Parameters:template_name (str) – The name of the template to fetch.
Returns:The filtered templates list.
Return type:list
run(selected_templates: Optional[List[str]] = None, log: Optional[bool] = False, key_rate: Optional[int] = 10)

Run packer on the generated manifest.json files.

Parameters:selected_templates (list, optional) – The packer templates to run with packer.
exception packme.Packman.TemplatesSelectionError

Bases: Exception