Lib package

Submodules

lib.appflow_ansible module

Appflow Ansible utilities. This contains all the functions needed to perform Ansible actions. From provision to encryption/decryption and tag listing.

lib.appflow_ansible.decrypt(tenant, env)[source]

Decrypt the tenant/environment data

Parameters:
  • tenant (string) – The name of the tenant.
  • env (string) – The name of the tenant.
Return type:

None

Returns:

the function prints to screen the ansible output of the execution.

lib.appflow_ansible.encrypt(tenant, env)[source]

Encrypt the tenant/environment data

Parameters:
  • tenant (string) – The name of the tenant.
  • env (string) – The name of the tenant.
Return type:

None

Returns:

the function prints to screen the ansible output of the execution.

lib.appflow_ansible.list_tags(tenant, env)[source]

List all available tags for tenant/environment

Parameters:
  • tenant (string) – The name of the tenant.
  • env (string) – The name of the tenant.
Return type:

None

Returns:

the function prints to screen the available tags.

lib.appflow_ansible.provision(tenant: str, env: str, limit: str, tags: str, skip_tags: str, firstrun: bool, local: bool, debug: bool)[source]

This will perform the ansible playbook. We pass tenant and environment and all other options as –option xys in order to respect ansible’s syntax.

Parameters:
  • tenant (string) – The name of the tenant.
  • env (string) – The name of the tenant.
  • limit (string) – Comma separated list of hosts to provision.
  • tags (string) – Comma separated list of tags to exec (default All).
  • skip_tags (string) – Comma separated list of tags to skip (default None).
  • firstrun (bool) – if it’s first run (default False)
  • debug (bool) – if it’s a debug run (default False)
Return type:

None

Returns:

the function prints to screen the ansible output of the execution.

lib.appflow_tools module

Appflow Tools. This contains all the functions needed to perform actions connected to initialization, config deployment and git versioning.

lib.appflow_tools.git_check_in(tenant, env, commit)[source]

Git push. This will affecy only the modified files (see git_status function). Commit message can be specified.

Parameters:
  • tenant (string) – The name of the tenant.
  • env (string) – The name of the tenant.
  • commit (string) – The commit message to use when committing.
Return type:

None

Returns:

the function doesn’t have a return statement.

lib.appflow_tools.git_check_out(tenant, env)[source]

Git pull of the specified tenant/environment folder. un-pushed work can be overwritten by this, so ask for confirmation.

Parameters:
  • tenant (string) – The name of the tenant.
  • env (string) – The name of the tenant.
Return type:

None

Returns:

the function doesn’t have a return statement.

lib.appflow_tools.git_reset(tenant, env)[source]

Perform git reset in the specified tenant/environment folder. After this, updates the md5 file to reflect the new status.

Parameters:
  • tenant (string) – The name of the tenant.
  • env (string) – The name of the tenant.
Return type:

None

Returns:

the function doesn’t have a return statement.

lib.appflow_tools.git_status(tenant, env)[source]

Return a status of modified files in the tenant/environment folder. this is tracked separately from git, because encryption/decryption of files will always override the git status method.

Parameters:
  • tenant (string) – The name of the tenant.
  • env (string) – The name of the tenant.
Return type:

list

Returns:

the function returns a list containing the different lines between the 2 md5 files.

lib.appflow_tools.git_update_playbooks(branch)[source]

Git pull the latest version of the playbooks. You can specify which branch you want to use

Parameters:branch (string) – The name of the branch
lib.appflow_tools.initialize(tenant, env)[source]

Create default dirs, clone playbooks and yaml files for Assh to function properly.

Parameters:
  • tenant (string) – The name of the tenant. (ex: mrrobot)
  • env (string) – The name of the tenant.
Return type:

None

Returns:

This function doesn’t have a return statement.

lib.appflow_tools.set_vhosts_hosts(tenant)[source]

Setup /etc/hosts for tenant. Requires root access to write.

Parameters:tenant (string) – The name of the tenant.
Return type:None
Returns:the function doesn’t have a return statement.
lib.appflow_tools.setup_default_config(tenant, env)[source]

Deploy a default config file in ~/.appflow/config.yml

Parameters:
  • tenant (string) – The name of the tenant. (ex: mrrobot)
  • env (string) – The name of the tenant.
Return type:

None

Returns:

the function prints to screen the ansible output of the execution.

lib.appflow_tools.setup_ssh(tenant, env)[source]

Deploy Assh configs for tenant/environment.

Parameters:
  • tenant (string) – The name of the tenant.
  • env (string) – The name of the tenant.
Return type:

None

Returns:

the function doesn’t have a return statement.

lib.appflow_utils module

Appflow Utilities. This contains all the generic functions needed to support the rest of the library.

lib.appflow_utils.add_keys(data_dict, key, value=None)[source]

Add keys to dictionary (set also value if specified)

Parameters:
  • data_dict (dict) – The dictionary where to search the key.
  • key (string) – The key to search.
  • value (string) – The value to set. (default None)
Return type:

None

Returns:

the function doesn’t have a return statement.

lib.appflow_utils.check_string_in_file(file_name, searched_string)[source]

Check if string is in file

Parameters:
  • file_name (string) – The file name where to search the string.
  • searched_string (string) – The string to search.
Return type:

bool

Returns:

the function returns if the string is found or not.

lib.appflow_utils.diff_files(file1, file2)[source]

Returns different lines between file1 and file2. Returned data is a list of strings.

Parameters:
  • file1 (string) – The name of the first file.
  • file2 (string) – The name of the second file.
Return type:

list

Returns:

the function returns a list containing the different lines between the 2 files.

lib.appflow_utils.format_string_argument(argument)[source]

Fire takes multiple arguments (comma separated) as list or tuple. Check argument type and put it to string.

Parameters:argument (tuple or list) – The argument passed.
Return type:string
Returns:Separated comma strings convertion for lists and tuples.
lib.appflow_utils.get_appflow_folder()[source]

Get directory or appflow.

Parameters:_file (string) – The name of the script file executed internally.
Return type:string
Returns:the function returns the root of appflow. Needed to then search for playbooks.
lib.appflow_utils.get_env_color_string(env)[source]

Color code for the environment variable Needed in provision string.

Parameters:env (string) – The name of the tenant.
Return type:string
Returns:the function returns the color needed for the corresponding env.
lib.appflow_utils.get_file_list(_dir)[source]

Returns a list of files in a directory.

Parameters:_dir (string) – The name of the directory to explore.
Return type:list
Returns:the function returns the list of files in the folder.
lib.appflow_utils.get_from_dict(data_dict, key)[source]

Return key-value dictionary

Parameters:
  • data_dict (dict) – The dictionary where to search the key.
  • key (string) – The key to search.
Return type:

dict

Returns:

the function returns a dict containing the key-value pair searched.

lib.appflow_utils.get_md5_folder(tenant)[source]

Get directory for the specified tenant md5 files.

Parameters:tenant (string) – The name of the tenant.
Return type:string
Returns:the function returns the md5_folder searched.
lib.appflow_utils.get_md5_sum(file_name)[source]

Return the md5 checksum of the specified file.

Parameters:file_name (string) – The name of the file to hash.
Return type:string
Returns:the function returns the md5 hash of the file.
lib.appflow_utils.get_provision_color_string(command, tenant, env)[source]

Color code for the provision string

Parameters:
  • command (string) – The command to execute.
  • tenant (string) – The name of the tenant.
  • env (string) – The name of the tenant.
Return type:

string

Returns:

the function returns the color coded string to print before the execution of the ansible command.

lib.appflow_utils.get_tenant_dir(tenant)[source]

Get directory for the specified tenant.

Parameters:tenant (string) – The name of the tenant.
Return type:string
Returns:the function returns the tenant folder.
lib.appflow_utils.get_tenant_env_dir(tenant, env)[source]

Get directory for the specified tenant/environment.

Parameters:
  • tenant (string) – The name of the tenant.
  • env (string) – The name of the environment.
Return type:

string

Returns:

the function returns the tenant/environment folder.

lib.appflow_utils.get_vault_file(tenant, env)[source]

Get vault file for the specified tenant/environment.

Parameters:
  • tenant (string) – The name of the tenant.
  • env (string) – The name of the environment.
Return type:

string

Returns:

the function returns the vault file searched.

lib.appflow_utils.rm_in_dict(data_dict, key)[source]

Remove keys from dictionary

Parameters:
  • data_dict (dict) – The dictionary where to search the key.
  • key (string) – The key to search.
Return type:

dict

Returns:

the function returns the dictionary with the deleted the key searched.

lib.appflow_utils.safe_remove(file_name)[source]

Gracefully delete a file.

Parameters:file_name (string) – The name of the file to delete.
Return type:None
Returns:the function doesn’t have a return statement.
lib.appflow_utils.set_in_dict(data_dict, key, value)[source]

Set key-value in dictionary

Parameters:
  • data_dict (dict) – The dictionary where to search the key.
  • key (string) – The key to search.
  • value (string) – The value to set.
Return type:

None

Returns:

the function doesn’t have a return statement.

lib.appflow_utils.write_md5_sum(file_name, md5_store_file)[source]

Write the modified md5 filename to the md5_store_file

Parameters:
  • file_name (string) – The name of the file to hash.
  • md5_store_file (string) – The name of the file where to write the hash.
Return type:

None

Returns:

the function doesn’t have a return statement.

lib.appflow_utils.yes_no(question, default='yes')[source]

Get a prompt for asking a question with y/N as accepted answer.

Parameters:
  • question (string) – The question to ask.
  • default (string) – The default answer. (default Yes)
Return type:

bool

Returns:

the function returns if the answer was yes or no.

lib.appflow_yaml module

Appflow Yaml utilities. This contains all the functions needed to manipulate yaml files. Handy for configs and for tenant setups.

lib.appflow_yaml.add_value(orig_file, orig_key, value)[source]

Returns key-value for searched key in file. Key will be created with the value specified. Data is written to file. Returns string in json format.

Parameters:
  • _file (string) – path.to.file (dot encoded) where to set the key.
  • key (string) – The key to search. (this function will add it if not found.)
  • value (T) – the value to set.
Return type:

json

Returns:

the function returns a json containing the updated file content.

lib.appflow_yaml.get_value(_file, key=None)[source]

Returns key-value for searched key in file. If key is not specified, returns the whole file. Returns string in json format.

Parameters:
  • _file (string) – path.to.file (dot encoded) where to search the key.
  • key (string) – The key to search.
Return type:

json

Returns:

the function returns a json containing the key-value searched.

lib.appflow_yaml.rm_value(_file, key)[source]

Returns key-value for searched key in file. Searched key will be removed. Data is written to file. Returns string in json format.

Parameters:
  • _file (string) – path.to.file (dot encoded) where to remove the key.
  • key (string) – The key to search.
Return type:

json

Returns:

the function returns a json containing the updated file content.

lib.appflow_yaml.set_value(_file, key, value)[source]

Returns key-value for searched key in file. Searched key will be set with the value specified. Data is written to file. Returns string in json format.

Parameters:
  • _file (string) – path.to.file (dot encoded) where to set the key.
  • key (string) – The key to search.
  • value (T) – the value to set.
Return type:

json

Returns:

the function returns a json containing the updated file content.

Module contents