Compound Status

  • Pietro Pasotti
Channel Revision Published Runs on
latest/stable 1 26 Jul 2022
Ubuntu 20.04
juju deploy compound-status
Show information

Platform:

Ubuntu
20.04

charms.compound_status.v0.compound_status

This charm lib provides a CompoundStatus utility.

Example usage:

class StatusPool(CompoundStatus): SKIP_UNKNOWN = True

workload = Status()
relation_1 = Status()
relation_2 = Status(tag='rel2')

class TesterCharm(CharmBase): def init(self, framework, key=None): super().init(framework, key) status_pool = StatusPool(self)

    # pro tip: keep the messages short
    status_pool.relation_1 = ActiveStatus('βœ…')
    status_pool.commit()  # sync with juju
    # equivalent to self.unit.status = status_pool.coalesce()

    status_pool.relation_1.unset()  # send status_1 back to unknown, until you set it again.

    status_pool.relation_2 = WaitingStatus('πŒ—: foo')
    status_pool.workload.warning('some debug message about why the workload is blocked')
    status_pool.workload.info('some info about the workload')
    status_pool.workload.error('whoopsiedaisies')
    status_pool.workload = BlockedStatus('blocked', 'see debug-log for the reason')
    status_pool.commit()

class Status

Description

Represents a status. None

Methods

Status. __repr__( self )

Status. __init__( self , tag , priority )

Status. priority( self )

Description

Return the priority of this status. None

Status. priority_key( status )

Description

Return the priority key. None

Status. sort( statuses )

Description

Return the statuses, sorted worst-to-best. None

Status. log( self , level: int , msg: str )

Description

Associate with this status a log entry with level log. None

Status. critical( self , msg: str )

Description

Associate with this status a log entry with level critical. None

Status. error( self , msg: str )

Description

Associate with this status a log entry with level error. None

Status. warning( self , msg: str )

Description

Associate with this status a log entry with level warning. None

Status. info( self , msg: str )

Description

Associate with this status a log entry with level info. None

Status. debug( self , msg: str )

Description

Associate with this status a log entry with level debug. None

Status. unset( self )

Unsets status and message.

Description

This status will go back to its initial state and be removed from the Master clobber.

Status. __get__( self , instance , owner )

Status. __set__( self , instance , value: StatusBase )

Status. status( self )

Description

Return the string representing this status. None

Status. name( self )

Description

Alias for interface-compatibility with ops.model.StatusBase. None

Status. message( self )

Description

Return the message associated with this status. None

Status. __hash__( self )

Status. __eq__( self , other )

class Clobberer

Description

Clobberer. Repeat it many times fast. None

Methods

Clobberer. clobber( self , statuses , skip_unknown: bool )

Description

Produce a clobbered representation of the statuses. None

class WorstOnly

This clobberer provides a worst-only view of the current statuses in the pool.

Description

e.g. if the status pool has three statuses: relation_1 = ActiveStatus('βœ…') relation_2 = WaitingStatus('πŒ—: foo') workload = BlockedStatus('πŸ’”')

The Summary clobbered status will have as message:: (workload) πŸ’”

Methods

WorstOnly. __init__( self , fmt: str , sep: str )

WorstOnly. clobber( self , statuses , skip_unknown: bool )

Description

Produce a clobbered representation of the statuses. None

class Summary

This clobberer provides a worst-first, summarized view of all statuses.

Description

e.g. if the status pool has three statuses: relation_1 = ActiveStatus('βœ…') relation_2 = WaitingStatus('πŒ—: foo') workload = BlockedStatus('πŸ’”')

The Summary clobbered status will have as message: (workload:blocked) πŸ’”; (relation_1:active) βœ…; (rel2:waiting) πŒ—: foo

Methods

Summary. __init__( self , fmt: str , sep: str )

Summary. clobber( self , statuses , skip_unknown: bool )

Description

Produce a clobbered representation of the statuses. None

class Condensed

This clobberer provides a very compact, summarized view of all statuses.

Description

e.g. if the status pool has three statuses: relation_1 = ActiveStatus('βœ…') relation_2 = WaitingStatus('βœ…') relation_3 = BlockedStatus('βœ…') relation_... = ??? relation_N = ActiveStatus('βœ…') relation_2 = WaitingStatus('πŒ—: foo') workload = BlockedStatus('πŸ’”')

The Condensed clobbered status will have as message: 15 blocked; 43 waiting; 12 active

If all are active the message will be empty. Priority will be ignored.

Methods

Condensed. __init__( self , fmt: str , sep: str )

Condensed. clobber( self , statuses , skip_unknown: bool )

Description

Produce a clobbered representation of the statuses. None

class MasterStatus

The Master status of the pool.

Arguments

- `tag`

the name to associate the master status with.

- `fmt`

The format for each child status. Needs to contain three {} slots, will receive three arguments in this order:

  • the tag of the child status (a string)
  • the name of the child status (e.g. 'blocked', or 'active')
  • the message associated with the child status (another string)
- `sep`

The separator used to join together the child statuses.

Methods

MasterStatus. __init__( self , tag: str , clobberer: Clobberer , priority )

MasterStatus. message( self )

Description

Return the message associated with this status. None

MasterStatus. status( self )

Description

Return the status. None

MasterStatus. coalesce( self )

Description

Cast to an ops.model.StatusBase instance by clobbering statuses and messages. None

MasterStatus. unset( self )

Description

Unset all child statuses, as well as any user_set Master status. None

MasterStatus. __repr__( self )

class StatusPool

Description

Represents the pool of statuses available to an Object. None

Methods

StatusPool. __init__( self , charm: CharmBase , key )

StatusPool. get_status( self , attr: str )

Description

Retrieve a status by name. Equivalent to getattr(self, attr). None

StatusPool. set_status( self , attr: str , status: StatusBase )

Description

Set a status by name. Equivalent to setattr(self, attr, status). None

StatusPool. add_status( self , status: Status , attr )

Add status to this pool; under attr: attr.

Description

If attr is not provided, status.tag will be used instead if set.

NB attr needs to be a valid Python identifier.

StatusPool. remove_status( self , status: Status )

Description

Remove the status and forget about it. None

StatusPool. __setattr__( self , key: str , value: StatusBase )

StatusPool. commit( self )

Description

Store the current state and sync with juju. None

StatusPool. unset( self )

Description

Unsets master status (and all children). None

StatusPool. __repr__( self )