Skip to main content

utils.unit_id

UnitID Objects

@dataclass_json

@dataclass(frozen=True)
class UnitID()

A general unit identifier.

A unit basically is something that has a unique identifier consisting of three parts: The general type (e.g., 'infra' for components belonging to the overall infrastructure), the unit name itself (e.g., 'server'), and an instance specifier (used to distinguish multiple instances of the same unit).

Attributes:

  • type - The unit type.
  • unit - The unit name.
  • instance - The instance specifier.

equals

def equals(other: typing.Self) -> bool

Compares this identifier to another one.

Arguments:

  • other - The unit identifier to compare this one to.

Notes:

The instance specifiers are only compared if both are not None.

Returns:

Whether both identifiers are equal.

from_string

@staticmethod
def from_string(id_str: str) -> 'UnitID'

Creates a new UnitID from a string.

The string must be of the form <type>/<unit>/<instance> or <type>/<unit>.

Arguments:

  • id_str - The unit identifier string.

Returns:

The newly created UnitID.

Raises:

  • ValueError - If the passed string is invalid.