leapp.utils.audit package

Module contents

class leapp.utils.audit.Audit(event=None, stamp=None, message=None, data=None, actor=None, phase=None, hostname=None, context=None)

Bases: leapp.utils.audit.DataSource

Parameters:
  • event (str) – Type of this event e.g. new-message or log-message but can be anything
  • stamp (str) – Timestamp string of the event creation in iso format
  • message (leapp.utils.audit.Message or None) – A message object, if this audit entry represents a message otherwise None
  • data (str or None) – If message is None this has to be the data for the audit entry
  • actor (str) – Name of the actor that triggered the entry
  • phase (str) – In which phase of the workflow execution the data entry was created
  • context (str) – The execution context
  • hostname (str) – Hostname of the system that produced the entry
audit_id
data_source_id

Returns the id of the entry, which is only set when already stored. :return: Integer id or None

do_store(connection)
host_id

Returns the id of the entry, which is only set when already stored. :return: Integer id or None

store(db=None)

Stores the data within a transaction :param db: Database object (optional) :return: None

class leapp.utils.audit.DataSource(actor=None, phase=None, context=None, hostname=None)

Bases: leapp.utils.audit.Host

Parameters:
  • actor (str) – Name of the actor that triggered the entry
  • phase (str) – In which phase of the workflow execution the data entry was created
  • context (str) – The execution context
  • hostname (str) – Hostname of the system that produced the entry
data_source_id

Returns the id of the entry, which is only set when already stored. :return: Integer id or None

do_store(connection)
host_id

Returns the id of the entry, which is only set when already stored. :return: Integer id or None

store(db=None)

Stores the data within a transaction :param db: Database object (optional) :return: None

class leapp.utils.audit.Execution(context=None, kind=None, configuration=None, stamp=None)

Bases: leapp.utils.audit.Storable

Stores information about the current execution

Parameters:
  • context (str) – Execution context identifier
  • kind (str) – Execution kind - Can be any string and used for filtering
  • configuration (str, dict, list or tuple) –
  • stamp (str) – Timestamp string of the execution start in iso format
do_store(connection)
execution_id

Returns the id of the entry, which is only set when already stored. :return: Integer id or None

store(db=None)

Stores the data within a transaction :param db: Database object (optional) :return: None

class leapp.utils.audit.Host(context=None, hostname=None)

Bases: leapp.utils.audit.Storable

Host information

do_store(connection)
host_id

Returns the id of the entry, which is only set when already stored. :return: Integer id or None

store(db=None)

Stores the data within a transaction :param db: Database object (optional) :return: None

class leapp.utils.audit.Message(stamp=None, msg_type=None, topic=None, data=None, actor=None, phase=None, hostname=None, context=None)

Bases: leapp.utils.audit.DataSource

Parameters:
  • stamp (str) – Timestamp string of the message creation in iso format
  • msg_type (str) – Name of the model that represents the message payload
  • topic (str) – Topic for this message
  • data (leapp.utils.audit.MessageData) – Payload data
  • actor (str) – Name of the actor that triggered the entry
  • phase (str) – In which phase of the workflow execution the message was created
  • context (str) – The execution context
  • hostname (str) – Hostname of the system that produced the message
data_source_id

Returns the id of the entry, which is only set when already stored. :return: Integer id or None

do_store(connection)
host_id

Returns the id of the entry, which is only set when already stored. :return: Integer id or None

message_id

Returns the id of the entry, which is only set when already stored. :return: Integer id or None

store(db=None)

Stores the data within a transaction :param db: Database object (optional) :return: None

class leapp.utils.audit.MessageData(data=None, hash_id=None)

Bases: leapp.utils.audit.Storable

Message data

Parameters:
  • data (str) – Message payload
  • hash_id (str) – SHA256 hash in hexadecimal representation of data
do_store(connection)
store(db=None)

Stores the data within a transaction :param db: Database object (optional) :return: None

class leapp.utils.audit.Storable

Bases: object

Base class for database storables

do_store(connection)

Performs the actual storing of the data

Parameters:connection – Database connection to use (Can be a transaction cursor)
Returns:None
store(db=None)

Stores the data within a transaction :param db: Database object (optional) :return: None

leapp.utils.audit.checkpoint(actor, phase, context, hostname)

Creates a checkpoint audit entry

Parameters:
  • actor (str) – Name of the actor that triggered the entry
  • phase (str) – In which phase of the workflow execution the data entry was created
  • context (str) – The execution context
  • hostname (str) – Hostname of the system that produced the entry
Returns:

None

leapp.utils.audit.create_audit_entry(event, data, message=None)

Create an audit entry

Parameters:
  • event – Event type identifier
  • data – Data related to Type of the event, e.g. a command and its arguments
  • message – An optional message.
Returns:

leapp.utils.audit.create_connection(path)

Creates a database connection to the path and ensures it’s initialized and up to date.

Parameters:path – Path to the database
Returns:Connection object
leapp.utils.audit.dict_factory(cursor, row)
leapp.utils.audit.get_audit_entry(event, context)

Retrieve audit entries stored in the database for the given context

Parameters:
  • context (str) – The execution context
  • event (str) – Event type identifier
Returns:

list of dicts with id, time stamp, actor and phase fields

leapp.utils.audit.get_checkpoints(context)

Retrieve all checkpoints stored in the database for the given context

Parameters:context (str) – The execution context
Returns:list of dicts with id, timestamp, actor and phase fields
leapp.utils.audit.get_connection(db)

Get the database connection or passes it through if it is already set

Parameters:db – Database connection to be passed through in case it exists already
Returns:database object initialized and migrated to the latest schema version
leapp.utils.audit.get_errors(context)

Queries all error messages from the database for the given context

Parameters:context (str) – The execution context
Returns:List of error messages
leapp.utils.audit.get_messages(names, context, connection=None)

Queries all messages from the database for the given context and the list of model names :param names: List of names that should be messages returned for :type names: list or tuple of str :param context: Execution id the message should be queried from. :param connection: Database connection to use instead of the default one. :return: Iterable with messages :rtype: iterable