moler.config package

Submodules

moler.config.connections module

Connections related configuration

moler.config.connections.clear()

Cleanup configuration related to connections

moler.config.connections.define_connection(name, io_type, **constructor_kwargs)

Assign name to connection specification.

You should provide name that is meaningful in context of your application. Let’s say you have 3 servers hosting HTTP under 10.20.30.41 .. 43 Then you may name/define your connections like:

www_svr1  io_type=tcp, host=10.20.30.41, port=80
www_svr2  io_type=tcp, host=10.20.30.42, port=80
www_svr3  io_type=tcp, host=10.20.30.43, port=80

Thanks to such naming you could establish connection to server like:

svr1_conn = get_connection(name="www_svr_1")
svr1_conn.open()
moler.config.connections.mlr_conn_no_encoding(moler_conn_class, name)
moler.config.connections.mlr_conn_no_encoding_partial_clean_vt100(moler_conn_class, name)

Cleans some VT100 control-codes

moler.config.connections.mlr_conn_utf8(moler_conn_class, name)
moler.config.connections.mlr_conn_utf8_with_clean_vt100(moler_conn_class, name)
moler.config.connections.register_builtin_connections(connection_factory, moler_conn_class)
moler.config.connections.set_default_variant(io_type, variant)

Set variant to use as default when requesting ‘io_type’ connection

moler.config.connections.set_defaults()

Set defaults for connections configuration

moler.config.devices module

Package Open Source functionality of Moler.

moler.config.devices.clear()

Cleanup configuration related to devices

moler.config.devices.define_device(name, device_class, connection_desc, connection_hops, initial_state=None, lazy_cmds_events=False, additional_params=None)

Assign name to device specification.

moler.config.devices.set_default_connection(io_type, variant)

Set connection to use as default when requesting ‘device’ without connection specification

moler.config.loggers module

Configure logging for Moler’s needs

class moler.config.loggers.MolerMainMultilineWithDirectionFormatter(fmt, datefmt=None)

Bases: moler.config.loggers.MultilineWithDirectionFormatter

format(record)

Format the specified record as text.

The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.

class moler.config.loggers.MultilineWithDirectionFormatter(fmt=None, datefmt=None)

Bases: logging.Formatter

We want logs to have non-overlapping areas timestamp area TTTTTTTTTTT transfer direction area > (shows send ‘>’ or receive ‘<’) log message area MMMMMMMMMM It should look like: TTTTTTTTTTTTTTT D MMMMMMMMMMMMMMM 01 00:36:09.581 >|cat my_file.txt 01 00:36:09.585 <|This is

|multiline |content

This formatter allows to use %(transfer_direction)s inside format

format(record)

Format the specified record as text.

The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.

class moler.config.loggers.RawDataFormatter

Bases: object

format(record)

We want to take data from log_record.msg as bytes

class moler.config.loggers.RawFileHandler(*args, **kwargs)

Bases: logging.FileHandler

emit(record)
Emit a record. We don’t want base class implementation since we don’t want to do: stream.write(self.terminator) We are not adding any

to bytes-message from record.

class moler.config.loggers.RawTraceFormatter

Bases: moler.config.loggers.RawDataFormatter

format(record)

We want to see info about binary data log-record

class moler.config.loggers.SpecificLevelFilter(level)

Bases: object

filter(logRecord)
class moler.config.loggers.TracedIn(logger_name)

Bases: object

Decorator to allow for tracing method/function invocation It sends function name and parameters into logger given as decorator parameter sends with loglevel=TRACE Decorator is active only when environment variable MOLER_DEBUG_LEVEL = TRACE ex.: @TracedIn(‘moler’) def method(self, arg1, arg2):

moler.config.loggers.change_logging_suffix(suffix=None, logger_name=None)

Change logging suffix. :param suffix: new suffix for log files. None for no suffix. :param logger_name: name of logger. None for all loggers. :return: None

moler.config.loggers.configure_debug_level(level=None)

Configure debug_level based on environment variable MOLER_DEBUG_LEVEL We use additional env variable besides MOLER_CONFIG to allow for quick/temporary change since debug level is intended also for troubleshooting

moler.config.loggers.configure_device_logger(connection_name, propagate=False)

Configure logger with file storing connection’s log

moler.config.loggers.configure_moler_main_logger()

Configure main logger of Moler

moler.config.loggers.configure_moler_threads_logger()

Configure threads logger of Moler

moler.config.loggers.configure_runner_logger(runner_name)

Configure logger with file storing runner’s log

moler.config.loggers.create_logger(name, log_file=None, log_level=4, log_format='%(asctime)s %(levelname)-10s: |%(message)s', datefmt=None)

Creates Logger with (optional) file writer :param name: Logger name :param log_file: Path to logfile. Final logfile location is logging_path + log_file :param log_level: only log records with equal and greater level will be accepted for storage in log :param log_format: layout of log file, default is “%(asctime)s %(levelname)-10s: |%(message)s” :param datefmt: format the creation time of the log record :return: None

moler.config.loggers.debug_level_or_info_level()

If debugging is active we want to have details inside logs otherwise we want to keep them small

moler.config.loggers.get_error_log_stack()

Get how many functions stack you want to log when error is logged. :return: True to get log of all

moler.config.loggers.get_logging_path()
moler.config.loggers.reconfigure_logging_path(log_path)

Set up new logging path when Moler script is running :param log_path: new log path when logs will be stored :return: None

moler.config.loggers.set_backup_count(backup_count)
Set maximum number of files of logs to rotate for rotating logging. If parameter is not an int number then the
function does not change any value.
Parameters:backup_count – int number of how many files to keep to rotate logs.
Returns:None
moler.config.loggers.set_compress_after_rotation(compress_after_rotation)

Set True to compress file after log rotation. :param compress_after_rotation: True to compress, False otherwsie :return: None

moler.config.loggers.set_compress_command(compress_command)

Set compress command. :param compress_command: String with compress command with two fields {compressed} and {log_input} :return: None

moler.config.loggers.set_compressed_file_extension(compressed_file_extension)

Set compressed file extension. :param compressed_file_extension: String with file extension, for example “.zip” :return: None

moler.config.loggers.set_date_format(format)
moler.config.loggers.set_error_log_stack(error_log_stack=False)

Set how many functions stack you want to log when error is logged. :param error_log_stack: True to get all functions, False to get the last one. :return: None

moler.config.loggers.set_interval(interval)

Set interval for rotating logging. If parameter is not an int number then the function does not change any value. :param interval: int number in bytes or seconds :return: None

moler.config.loggers.set_kind(kind)

Set kind of logging. :param kind: None for plain logger, ‘time’ to time rotating, ‘size’ for size rotating. :return: None

moler.config.loggers.set_logging_path(path)
moler.config.loggers.set_write_mode(mode)
moler.config.loggers.setup_new_file_handler(logger_name, log_level, log_filename, formatter, filter=None)

Sets up new file handler for given logger :param logger_name: name of logger to which filelogger is added :param log_level: logging level :param log_filename: path to log file :param formatter: formatter for file logger :param filter: filter for file logger :return: logging.FileHandler object

moler.config.loggers.want_debug_details()

Check if we want to have debug details inside logs

moler.config.loggers.want_raw_logs()

moler.config.runners module

Runners related configuration

moler.config.runners.clear()

Cleanup configuration related to runners

moler.config.runners.register_builtin_runners(runner_factory)
moler.config.runners.set_default_variant(variant)

Set variant to use as default when requesting runner

Module contents

Moler related configuration

moler.config.clear()

Cleanup Moler’s configuration

moler.config.configs_are_same(config_list, config_to_find)

Utility function to check if two configs are identical (deep comparison)

Parameters:
  • config_list – list of configs to compare
  • config_to_find – second config to compare
Returns:

bool, True if config_to_find is in config_list, False otherwise.

moler.config.load_config(config=None, from_env_var=None, *args, **kwargs)

Load Moler’s configuration from config file.

Load Moler’s configuration from config file. :param config: either dict or config filename directly provided (overwrites ‘from_env_var’ if both given). :type config: dict or str :param from_env_var: name of environment variable storing config filename (file is in YAML format) :return: None

moler.config.load_connection_from_config(config)
moler.config.load_device_from_config(config, add_only=False)
moler.config.load_logger_from_config(config)
moler.config.read_configfile(path)

Context manager that reads content of configuration file into string

Parameters:path – location of configuration file
Returns:configuration file content as string
moler.config.read_yaml_configfile(path)

Read and convert YAML into dictionary

Parameters:path – location of yaml file
Returns:configuration as a python dictionary
moler.config.reconfigure_logging_path(logging_path)

Set up new logging path when Moler script is running :param logging_path: new log path when logs will be stored :return: