administrative

Administrative module.

exception spicerack.administrative.ReasonError[source]

Bases: SpicerackError

Custom exception class for errors of the Reason class.

class spicerack.administrative.Reason(reason: str, username: str, hostname: str, *, task_id: str | None = None)[source]

Bases: object

Class to manage the reason for administrative actions.

Initialize the instance.

Parameters:
  • reason (str) -- the reason to use to justify an administrative action. The username and the hostname where the action was originated will be added to the reason automatically. The reason is meant to be passed to remote execution in double quotes, allowing to use Bash variables, if needed. Therefore the reason cannot contain double quotes.

  • username (str) -- the username to mention in the reason as the author of the action.

  • hostname (str) -- the hostname to mention in the reason as the host originating the action.

  • task_id (str, optional) -- the task ID to mention in the reason.

Raises:

spicerack.administrative.ReasonError -- if any parameter contains double quotes.

__str__() str[source]

String representation of the instance, including all attributes.

Example

  • Example return value when the task ID is not set:

    Given reason - username@hostname
    
  • Example return value when the task ID is set:

    Given reason - username@hostname - T12345
    
Returns:

the generated string representation of all the instance attributes.

Return type:

str

quoted() str[source]

Double quoted string representation of the instance, including all attributes.

Example

  • Example return value when the task ID is not set:

    "Given reason - username@hostname"
    
  • Example return value when the task ID is set:

    "Given reason - username@hostname - T12345"
    
Returns:

the generated string representation of all the instance attributes, double quoted.

Return type:

str

property hostname: str

Getter for the hostname property.

Returns:

the hostname on which the code is running.

Return type:

str

property owner: str

Getter for the owner property.

Example

Example return value:

username@hostname
Returns:

the owner of the currently running code.

Return type:

str

property reason: str

Getter for the reason property.

Returns:

the reason given to justify the administrative action.

Return type:

str

property task_id: str | None

Getter for the task ID property.

Returns:

the task ID to mention in the reason, or None if none was given.

Return type:

Optional[Str]