maaspower.maasconfig#

massconfig.py#

This module uses APISchema to serialize and deserialize the config file, plus provides a schema for easy editing of the config.

The MaasConfig class plus SwitchDevice derived classes in the devices folder provide an in memory representation of the contents of the maaspower YAML configuration file that specifies the set of power manager devices for which to serve web hooks.

Members

MaasConfig

Provides global information regarding webhook address, passwords etc.

RegexSwitchDevice

An abstract SwitchDevice which has the ability to interpret reponses and convert them to the requisit MaasReponse values using regex.

SwitchDevice

A base class for the switching devices that the webhook server will control.

class maaspower.maasconfig.SwitchDevice(*, name: ~typing.Annotated[str, ~apischema.schemas.Schema(title=None, description=A name for the switching device, default=None, examples=None, format=None, deprecated=None, media_type=None, encoding=None, constraints=Constraints(min=None, max=None, exc_min=None, exc_max=None, mult_of=None, min_len=None, max_len=None, pattern=None, min_items=None, max_items=None, unique=None, min_props=None, max_props=None), extra=None, override=False, child=None)])[source]#

A base class for the switching devices that the webhook server will control.

Concrete subclasses MUST provide a type field akin to this:

type: Literal[“ConreteDevice”] = “ConcreteDevice”

Concrete subclasses are found in the devices subfolder

copy(new_name: str, match) SwitchDevice[source]#

Create a copy of this device with a new name. All the fields of the object are reformatted with substitutions in regex matches using {name} for the whole match and {m1} {m2} etc for matching subgroups.

This is used for creating a specific instance of a device from a regex defined device.

class maaspower.maasconfig.RegexSwitchDevice(*, name: ~typing.Annotated[str, ~apischema.schemas.Schema(title=None, description=A name for the switching device, default=None, examples=None, format=None, deprecated=None, media_type=None, encoding=None, constraints=Constraints(min=None, max=None, exc_min=None, exc_max=None, mult_of=None, min_len=None, max_len=None, pattern=None, min_items=None, max_items=None, unique=None, min_props=None, max_props=None), extra=None, override=False, child=None)], query_on_regex: ~typing.Annotated[str, ~apischema.schemas.Schema(title=None, description=match the on status return from query, default=None, examples=None, format=None, deprecated=None, media_type=None, encoding=None, constraints=Constraints(min=None, max=None, exc_min=None, exc_max=None, mult_of=None, min_len=None, max_len=None, pattern=None, min_items=None, max_items=None, unique=None, min_props=None, max_props=None), extra=None, override=False, child=None)] = 'on', query_off_regex: ~typing.Annotated[str, ~apischema.schemas.Schema(title=None, description=match the off status return from query, default=None, examples=None, format=None, deprecated=None, media_type=None, encoding=None, constraints=Constraints(min=None, max=None, exc_min=None, exc_max=None, mult_of=None, min_len=None, max_len=None, pattern=None, min_items=None, max_items=None, unique=None, min_props=None, max_props=None), extra=None, override=False, child=None)] = 'off')[source]#

An abstract SwitchDevice which has the ability to interpret reponses and convert them to the requisit MaasReponse values using regex.

abstract run_query() str[source]#

Ths method should be overridden by concrete classes. This method is called by query_state and it’s response is run through query_regex_on and query_regex_off.

returns: A value to be parsed by query_regex_on and query_regex_off.

query_state() str[source]#

Uses the regex patterns defined in query_on_regex and query_off_regex to ascertain the correct response.

class maaspower.maasconfig.MaasConfig(name: ~typing.Annotated[str, ~apischema.schemas.Schema(title=None, description=The name for this webhook server instance, default=None, examples=None, format=None, deprecated=None, media_type=None, encoding=None, constraints=Constraints(min=None, max=None, exc_min=None, exc_max=None, mult_of=None, min_len=None, max_len=None, pattern=None, min_items=None, max_items=None, unique=None, min_props=None, max_props=None), extra=None, override=False, child=None)], ip_address: ~typing.Annotated[str, ~apischema.schemas.Schema(title=None, description=IP address to listen on, default=None, examples=None, format=None, deprecated=None, media_type=None, encoding=None, constraints=Constraints(min=None, max=None, exc_min=None, exc_max=None, mult_of=None, min_len=None, max_len=None, pattern=None, min_items=None, max_items=None, unique=None, min_props=None, max_props=None), extra=None, override=False, child=None)], port: ~typing.Annotated[int, ~apischema.schemas.Schema(title=None, description=port to listen on, default=None, examples=None, format=None, deprecated=None, media_type=None, encoding=None, constraints=Constraints(min=None, max=None, exc_min=None, exc_max=None, mult_of=None, min_len=None, max_len=None, pattern=None, min_items=None, max_items=None, unique=None, min_props=None, max_props=None), extra=None, override=False, child=None)], username: ~typing.Annotated[str, ~apischema.schemas.Schema(title=None, description=username for connecting to webhook, default=None, examples=None, format=None, deprecated=None, media_type=None, encoding=None, constraints=Constraints(min=None, max=None, exc_min=None, exc_max=None, mult_of=None, min_len=None, max_len=None, pattern=None, min_items=None, max_items=None, unique=None, min_props=None, max_props=None), extra=None, override=False, child=None)], password: ~typing.Annotated[str, ~apischema.schemas.Schema(title=None, description=password for connecting to webhook, default=None, examples=None, format=None, deprecated=None, media_type=None, encoding=None, constraints=Constraints(min=None, max=None, exc_min=None, exc_max=None, mult_of=None, min_len=None, max_len=None, pattern=None, min_items=None, max_items=None, unique=None, min_props=None, max_props=None), extra=None, override=False, child=None)], devices: ~collections.abc.Annotated[~collections.abc.Sequence[~maaspower.maasconfig.SwitchDevice], ~apischema.schemas.Schema(title=None, description=A list of the devices that this webhook server will control, default=None, examples=None, format=None, deprecated=None, media_type=None, encoding=None, constraints=Constraints(min=None, max=None, exc_min=None, exc_max=None, mult_of=None, min_len=None, max_len=None, pattern=None, min_items=None, max_items=None, unique=None, min_props=None, max_props=None), extra=None, override=False, child=None)])[source]#

Provides global information regarding webhook address, passwords etc.

Plus a list of switch devices. The devices are generic in this module, config definitions and function for specific device types are in the devices folder.

find_device(name: str)[source]#

use the indexed list to find the device or walk through the and check for regex matches. A regex match creates a new device which goes in the _devices cache so will not need matching a second time

TODO gilesknap/maaspower#10