Helper Classes


Charter

Contains helper class Charter that deals with the file structure of the program. Getter and setter methods for context, paths to certain resources.

class src.mpaas.charter.Charter(context_path, projects_path, configs_path)

Bases: object

Helper class to deal with Charts and current Context

create_value(values_yaml_path, value_name, new_value)

Creates a value in a values.yaml file

delete_preprocess(project_name, project_location)

Deletes the preprocesses file. Useful when some values change or new plugins are loaded. Ensures every plugin gets to work with the latests values.

delete_value(values_yaml_path, value_name)

Returns a dictionary of a yaml file with target value removed.

Parameters
  • values_yaml_path (String) – Path to values.yaml file you wish to replace a value of.

  • value_name – Name of the value you wish to change,

each level of depth separated by a ‘.’ (Same syntax as ‘mpaas list values’ output) :type value_name: String :rtype: Dictionary

describe_config(config_name)

Method that returns the contents of target config

Parameters

config_name (String) – Name of target config

Return type

Dictionary

from_template(project, chart_name)

Returns the name of the template a chart was created from.

Parameters
  • project (String) – Name of target project

  • chart_name (String) – Name of target chart

Return type

String

get_chart_path(project, chart)

Returns path to target chart in target project.

Parameters
  • project (String) – Name of target project

  • chart (String) – Name of target chart

Return type

String

get_context_all()

Method that returns a dict of all the current context objects

Return type

Dict

get_context_chart()

Method that returns current chart in context

Return type

String

get_context_config()

Method that returns current config file in context

Return type

String

get_context_project()

Method that returns current project in context

Return type

String

get_target_value(document_path, value_path)

Method that returns the value of target key in a yaml document

Parameters
  • document_path (String) – Path to target document

  • value_path – Name of the value you wish to get type,

each level of depth separated by a ‘.’ (Same syntax as ‘mpaas list values’ output) :type value_path: String :rtype: dict, list or string

get_value(document_path, value_path)

Method that returns a value in a target yaml document. If the value does not exist, returns None

Parameters
  • document_path (String) – Path to target document

  • value_path – Name of the value you wish to get,

each level of depth separated by a ‘.’ (Same syntax as ‘mpaas list values’ output) :type value_path: String :rtype: String, List, Dict or None

get_value_type(document_path, value_path)

Method that returns the type of a value in a target yaml document

Parameters
  • document_path (String) – Path to target document

  • value_path – Name of the value you wish to get type,

each level of depth separated by a ‘.’ (Same syntax as ‘mpaas list values’ output) :type value_path: String :rtype: type

get_values_path(project, chart)

Returns the path to the values.yaml file in target chart in target project. Returns path to target chart in target project.

Parameters
  • project (String) – Name of target project

  • chart (String) – Name of target chart

Return type

String

get_version(chart_path)

Method that returns the version of target template or Chart

Parameters

chart_path (String) – Path to target chart directory

getcontext_path()

Method that returns the path to current Project

Return type

String

has_preprocessed(project_name, project_location)

Returns False if no preprocessed template has been found, True otherwise.

init_context()

Method that initializes the context file

Return type

None

is_simple_value(document_path, value_path)

Method that return True if target value is not a dict or a list

Parameters
  • document_path (String) – Path to target document

  • value_path – Name of the value you wish to check,

each level of depth separated by a ‘.’ (Same syntax as ‘mpaas list values’ output) :type value_path: String :rtype: Boolean

lint_chart(chart_path)

Returns true if target path is a valid helm chart, false otherwise.

Parameters

chart_path (String) – Path to target chart

Return type

Boolean

preprocess(project_name, project_location, namespace)

Renders a complete template of target project.

replace_value(values_yaml_path, document)

Method that overwrites target yaml file with the contents of a python Dict.

Parameters
  • values_yaml_path (String) – Path to values.yaml file you wish to replace.

  • document (Dictionary) – Variable that contains the new values

Return type

Boolean

set_context_chart(chart)

Method that sets the current chart context

Parameters

chart (String) – Name of chart to be set

set_context_config(config)

Method thats sets the current config context.

Parameters

config (String) – Name of config to be set

set_context_project(context)

Method that sets current project context.

Parameters

context (String) – Name of context to be set

update_value(values_yaml_path, value_name, new_value, value_type=None)

Generates a new yaml document with an updated value.

Parameters
  • values_yaml_path (String) – Path to values.yaml file you wish to replace a value in.

  • value_name – Name of the value you wish to change,

each level of depth separated by a ‘.’ (Same syntax as ‘mpaas list values’ output) :type value_name: String :param new_value: New value to be taken by [value_name] :type new_value: String, List or Dict

value_exists(document_path, value_path)

Method that checks if a value exists in target yaml document.

Parameters
  • document_path (String) – Path to target document

  • value_path – Name of the value you wish to check,

each level of depth separated by a ‘.’ (Same syntax as ‘mpaas list values’ output) :type value_path: String :rtype: Boolean

write_preprocess(project_name, project_location, namespace)

Writes the preprocessed template to the default location in the template


Config Handler

Module that handles kubeconfigs

class src.mpaas.config_handler.ConfigHandler(path, context_path, projects_path)

Bases: object

Class that handles the creation and storage of kubeconfigs.

check_config()

Function that checks the config’s status. Returns true if a default config file has been found, False otherwise. Makes a backup of the default config if it exists, to restore later. :rtype: Boolean

create_config(config_name, base_config_path)

Method that creates a config from an existing config file. :param config_name: Name of config file to create :type config_name: String :param base_config_path: Path to the original kubeconfig file :type base_config_path: String

delete_config(config_name)

Method that deletes a mpaas config file. :param config_name: Name of target config to delete :type config_name: String

set_config(config_name)

Function that writes to the default kubeconfig location from a mpaas config file.

set_default_config()

Method that sets the current config from a backup of the original host’s kubeconfig file


Value Parser

Contains the class that parses helm values.yaml files into a convenient structure to use and display in main program.

class src.mpaas.value_parser.ValueParser

Bases: object

Class that parses values.yaml files to produce a dictionary of depth 1 of the form: {‘key/subkey/…/subsubkey’:value}

add_entry(key, value, is_list=False)

Function that adds the tips of the branches from the tree structure to the ValueParser’s data. :param key: Key of dict :type key: String :param value: Value of dict :type value: String or List

get_value(k, v)

Recursive function that creates the tree structure of the dictionary :param k: Key of dict :type k: String :param v: Value of dict :type v: String, List or Dict :rtype: None

parse(file)

Main method that creates the dictionary :param file: Path to file to parse :type file: String :rtype: List

parse_with_JSON(file)

Same as parse method but enables JSON syntax coloring down the line