Common

class narrenschiff.modules.common.NarrenschiffModule(command)[source]

Abstract class/Interface for the module classes. A module must inherit from this class.

Variables

DRY_RUN_FLAGint

The subprocess module does not have a way of indicating whether a command was run with dry run or not, since that is the responsibility of narrenschiff.modules.common.NarrenschiffModule.execute() method. If module or subcommand of module is not supporting dry run, than DRY_RUN_FLAG is a reserved return code (rc) that indicates that program should not exit, and output should be printed in special color (blue).

abstract property cmd

Get command that module needs to execute later.

Returns

Full command with all parameters

Return type

str

property dry_run

Return a dry run flag.

Returns

--dry-run string

Return type

str

In general most commands use --dry-run so there is no need to override this. However, there are exceptions for some commands where this flag is differently named. This property offers extensibility to the modules that may use different flag.

abstract dry_run_supported(cmd)[source]

Check if command supports –dry-run.

Parameters

cmd (str) – Command that module should execute

Returns

Boolean indicating whether command supports dry run

Return type

bool

echo(output, rc)[source]

Print output to console, and exit if return code is different from 0.

Parameters
  • output (str) – stdout or stderr of a process

  • rc (int) – Return code of the process

Returns

Void

Return type

None

execute(dry_run_enabled=False)[source]

Parse command and its arguments, and execute the module.

Parameters

dry_run_enabled (bool) – Boolean indicating whether user turned on dry run for the task

Returns

Void

Return type

None

subprocess(cmd)[source]

Execute command with shell, and return output and return code.

Parameters

cmd (str) – Command to execute

Returns

Output and return code

Return type

tuple

Example:

output, rc = self.subprocess('kubectl get pods')
exception narrenschiff.modules.common.NarrenschiffModuleException[source]

Use when something goes wrong in modules.