lce_service.device_class_api.models module
- class lce_service.device_class_api.models.DeviceClass(*, reference: Annotated[str | None, MinLen(min_length=1), BeforeValidator(func=validate_optional_string, json_schema_input_type=PydanticUndefined)] = None, default_reference_set: bool = False, id: int | None = None, guid: Annotated[str, BeforeValidator(func=validate_device_class_guid, json_schema_input_type=PydanticUndefined)] | None = None, class_name: Annotated[str, MinLen(min_length=1), MaxLen(max_length=64)], description: Annotated[str, MinLen(min_length=1), MaxLen(max_length=64)], category: Annotated[int, Ge(ge=0)], device_type: DeviceClassType = DeviceClassType.PHYSICAL, is_snmp: bool = False, class_identifier_1: Annotated[str, MaxLen(max_length=255)] = '', class_identifier_2: Annotated[str, MaxLen(max_length=255)] = '', discovery_qualifier: Annotated[str, MaxLen(max_length=255)] = '', agent_identifier_1: Annotated[str, MaxLen(max_length=255)] = '', agent_identifier_2: Annotated[str, MaxLen(max_length=255)] = '', root_device: bool = False, weight: Annotated[int, Ge(ge=1), Le(le=10)] = 1, tier_id: Annotated[int, Ge(ge=0)] = 0, image: Annotated[str, MinLen(min_length=1), MaxLen(max_length=32)] = '_generic_unknown.png', pp_guid: Annotated[str, BeforeValidator(func=validate_device_class_guid, json_schema_input_type=PydanticUndefined)] | None = None, class_type: int | None = None, last_edited: Annotated[str | None, BeforeValidator(func=validate_last_edited, json_schema_input_type=PydanticUndefined)] = None, category_name: str | None = None)
Bases:
EnumLabelMixinSchema for a device class. Maps to table: definitions_dev_classes
- agent_identifier_1: str
- agent_identifier_2: str
- category: int
- category_name: str | None
- class_identifier_1: str
- class_identifier_2: str
- class_name: str
- class_type: int | None
- description: str
- device_type: DeviceClassType
- discovery_qualifier: str
- execute_strict_validation(dbc: silo_cursor, dynamic_app: Any = None, references: DeviceClassValidationReferences | None = None) None
Validate the rules a device class must satisfy to be created or updated.
Its discovery identifiers must be consistent with its type (get_identifier_errors)
Its category must exist, and is kept as resolved_category for writing
Its tier, when it has one, must exist
Its PowerPack, when it is given one, must exist. A stored PowerPack that was since removed is left alone (see is_powerpack_changed)
Like the platform, device classes can share a class and description.
- Parameters:
dbc – A silo_cursor instance used to look up the categories, tiers and PowerPacks the rules depend on.
dynamic_app – Unused, as device classes do not belong to a Dynamic Application.
references – The categories, tiers and PowerPacks found for the device classes of the request, see get_validation_references. They are looked up for this device class alone when not provided.
- Raises:
InvalidResourceError – Raised when a rule is not satisfied, with every problem of the identifiers.
DatabaseExecutionError – Raised when a database query fails.
- get_category_to_resolve() int | None
Get the category of this device class that strict validation must resolve.
- Returns:
The id of its category, or None when the category given was already resolved.
- get_identifier_errors() List[str]
Get the problems of the discovery identifiers of this device class.
The rules are those of the platform’s device class editor:
A component device class is not discovered over SNMP
A physical SNMP device class has an OID as its first class identifier, unless it has an agent identifier, and a discovery qualifier OID when it has a qualifier value
Other device classes that are not components have no first class identifier
- Returns:
A message for each problem, empty when the identifiers are valid.
- get_powerpack_to_check() str | None
Get the PowerPack of this device class that strict validation must check exists.
- Returns:
The GUID of its PowerPack when it is given one (see is_powerpack_changed), or None.
- guid: Annotated[str, BeforeValidator(func=validate_device_class_guid, json_schema_input_type=PydanticUndefined)] | None
- id: int | None
- image: str
- is_powerpack_changed() bool
Check whether this device class is new, or is moved to another PowerPack.
The PowerPack of an existing device class can since have been removed. That must not prevent updating the device class, so only a PowerPack it is given is checked.
- Returns:
Whether its PowerPack differs from the stored one, ignoring case like the database does. True for a new device class.
- is_snmp: bool
- last_edited: Annotated[str | None, BeforeValidator(func=validate_last_edited, json_schema_input_type=PydanticUndefined)]
- model_config = {'extra': 'forbid', 'str_strip_whitespace': True, 'use_enum_values': False, 'validate_assignment': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_post_init(context: Any, /) None
This function is meant to behave like a BaseModel method to initialize private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
- Parameters:
self – The BaseModel instance.
context – The context.
- property name: str
Get the name of this device class, as the platform shows it.
- Returns:
The class and description of this device class.
- pp_guid: Annotated[str, BeforeValidator(func=validate_device_class_guid, json_schema_input_type=PydanticUndefined)] | None
- property resolved_category: DeviceCategory
Get the category of this device class, as resolved by its strict validation.
- Returns:
The category.
- Raises:
RuntimeError – Raised before execute_strict_validation resolves the category.
- root_device: bool
- set_resolved_category(category: DeviceCategory) None
Record the category a payload named, so the strict validation does not resolve it again.
- Parameters:
category – The resolved category, whose id is the category of this device class.
- tier_id: int
- weight: int
- class lce_service.device_class_api.models.DeviceClassValidationReferences(categories: Dict[int, DeviceCategory], tier_ids: frozenset[int], powerpack_guids: frozenset[str])
Bases:
NamedTupleThe categories, tiers and PowerPacks that device classes reference and that exist.
- Parameters:
categories – The categories found, by id.
tier_ids – The ids of the tiers found.
powerpack_guids – The uppercase GUIDs of the PowerPacks found.
- categories: Dict[int, DeviceCategory]
Alias for field number 0
- powerpack_guids: frozenset[str]
Alias for field number 2
- tier_ids: frozenset[int]
Alias for field number 1
- lce_service.device_class_api.models.get_validation_references(dbc: silo_cursor, device_classes: List[DeviceClass]) DeviceClassValidationReferences
Look up the categories, tiers and PowerPacks that strict validation checks, at once.
Each kind of reference is looked up with one query for all the device classes, so a request creating or updating many device classes does not query each of them.
- Parameters:
dbc – A silo_cursor instance used to look up the references.
device_classes – The device classes to validate.
- Returns:
The references found. A reference missing from it does not exist.
- Raises:
DatabaseExecutionError – Raised when a database query fails.
- lce_service.device_class_api.models.is_device_class_guid(value: Any) bool
Check whether a value is a device class GUID.
- Parameters:
value – The value to check.
- Returns:
Whether the value is 32 hexadecimal characters, in either case.
- lce_service.device_class_api.models.resolve_device_category(dbc: silo_cursor, category: int | str) DeviceCategory
Resolve a device category from its id, GUID or name.
- Parameters:
dbc – A silo_cursor instance used to look up the category.
category – The id of the category (an int or a string of digits), its GUID (in either case), or its exact name.
- Returns:
The category.
- Raises:
InvalidResourceError – Raised when no category matches, or when several categories share the name.
DatabaseExecutionError – Raised when the database query fails.