flync.core¶
flync.core.annotations¶
external¶
- class NamingStrategy(value)¶
Bases:
IntEnumThe strategy on how the external field file/folder will be named.
- class OutputStrategy(value)¶
Bases:
IntFlagThe strategy on how an external field will be generated.
- class External(path: str | None = None, root: str | None = None, output_structure: ~flync.core.annotations.external.OutputStrategy = <OutputStrategy.AUTO: 1>, naming_strategy: ~flync.core.annotations.external.NamingStrategy = NamingStrategy.AUTO)¶
Bases:
objectIndicates this field is loaded from a separate location.
implied¶
- class ImpliedStrategy(value)¶
Bases:
IntEnumThe strategy on how an implied field will be calculated.
- class Implied(strategy: ImpliedStrategy = ImpliedStrategy.AUTO)¶
Bases:
objectIndicates this field is implied instead of loaded/generated.
flync.core.base_models¶
base_models¶
- class FLYNCBaseModel¶
Bases:
BaseModel- model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_post_init(context: Any, /) None¶
We need to both initialize private attributes and call the user-defined model_post_init method.
unique_names¶
- class UniqueName(*, name: str)¶
Bases:
FLYNCBaseModel,BaseRegistry- classmethod reset()¶
Reset function to clear the registry.
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_post_init(context: Any, /) None¶
We need to both initialize private attributes and call the user-defined model_post_init method.
flync.core.datatypes¶
- class Datatype¶
Bases:
FLYNCBaseModelBase class of every datatype.
Parameters¶
- namestr
Unique name of the datatype.
- descriptionstr, optional
Human-readable description of the datatype.
- typestr
Discriminator identifying the concrete datatype kind.
- endiannessLiteral[“BE”, “LE”], optional
Byte order used for encoding multi-byte values. Defaults to big-endian (“BE”).
- class PrimitiveDatatype¶
Bases:
DatatypeBase class for primitive datatypes such as integers, floating-point values, or booleans.
Parameters¶
- namestr
Unique name of the datatype.
- descriptionstr, optional
Human-readable description of the datatype.
- typestr
Discriminator identifying the concrete primitive datatype kind.
- endiannessLiteral[“BE”, “LE”], optional
Byte order used for encoding multi-byte values. Defaults to big-endian (“BE”).
- class ComplexDatatype¶
Bases:
DatatypeBase class for complex datatypes such as structures, arrays, or unions.
Parameters¶
- namestr
Unique name of the datatype.
- descriptionstr, optional
Human-readable description of the datatype.
- typestr
Discriminator identifying the concrete complex datatype kind.
- endiannessLiteral[“BE”, “LE”], optional
Byte order used for encoding multi-byte values. Defaults to big-endian (“BE”).
- class BaseInt¶
Bases:
PrimitiveDatatypeBase class for all integer primitive datatypes.
This class provides shared semantics for signed and unsigned integer representations and defines common descriptive metadata.
- class BaseFloat¶
Bases:
PrimitiveDatatypeBase class for all floating-point primitive datatypes.
This class provides shared semantics for floating-point representations and defines common descriptive metadata.
- class Typedef¶
Bases:
ComplexDatatypeAlias datatype that references another datatype definition.
A typedef introduces an alternative name for an existing datatype without changing its underlying structure or serialization behavior.
Parameters¶
- typeLiteral[“typedef”]
Discriminator used to identify this datatype.
- namestr
Name of the typedef reference.
- datatyperefAllTypes
Referenced datatype definition that this typedef aliases.
- class ArrayType¶
Bases:
ComplexDatatypeGeneric multidimensional array type.
Parameters¶
- typeLiteral[“array”]
Discriminator identifying this datatype as an array.
- dimensionsList[
ArrayDimension] Ordered list of array dimensions (outer → inner). Must contain at least one dimension.
- element_type
AllTypes Datatype of the innermost array element. This may itself be a primitive, struct, union, or another array type.
- class ArrayDimension¶
Bases:
FLYNCBaseModelDescribes a single array dimension.
Parameters¶
- kindLiteral[“fixed”, “dynamic”]
Specifies whether the dimension has a fixed size or a dynamically encoded length.
- lengthint, optional
Number of elements for a fixed-length dimension. Must be greater than 0. Only valid when
kind="fixed".- length_of_length_fieldLiteral[0, 8, 16, 32], optional
Size in bits of the length field that precedes the array data for a dynamic dimension. Only valid when
kind="dynamic".- upper_limitint, optional
Upper bound on the number of elements. Must be greater than 0.
- lower_limitint, optional
Lower bound on the number of elements. Must be greater than or equal to 0.
- bit_alignmentLiteral[8, 16, 32, 64, 128, 256], optional
Optional padding alignment in bits applied after this dimension.
- class BitfieldEntryValue¶
Bases:
BaseModelRepresents a named value within a bitfield entry.
Parameters¶
- valueint
Numeric value represented by this bitfield entry value.
- namestr
Symbolic name associated with the value.
- descriptionstr, optional
Human-readable description of the value.
- class BitfieldEntry¶
Bases:
BaseModelDescribes a single field within a bitfield.
Parameters¶
- namestr
Name of the individual bitfield.
- bitpositionint
Bit position of the individual bitfield within the enclosing bitfield datatype.
- descriptionstr, optional
Human-readable description of the field.
- valueslist of
BitfieldEntryValue, optional Optional enumeration of named values defined for this bitfield entry.
- class Bitfield¶
Bases:
DatatypeAllows modeling of SOME/IP bitfields.
Parameters¶
- namestr
Unique name of the datatype.
- descriptionstr, optional
Human-readable description of the datatype.
- typeLiteral[“bitfield”]
Discriminator identifying this datatype as a bitfield.
- endiannessLiteral[“BE”, “LE”], optional
Byte order used for encoding multi-byte values. Defaults to big-endian (“BE”).
- lengthLiteral[8, 16, 32, 64], optional
Size of the bitfield in bits.
- fieldslist of
BitfieldEntry List of bitfield entries that define the individual bit ranges.
- class BitRange¶
Bases:
DatatypeRepresents a range of bits in a signal or data array.
Parameters¶
- namestr
Unique name of the datatype.
- descriptionstr, optional
Human-readable description of the datatype.
- typestr
Datatype discriminator inherited from
Datatype.- endiannessLiteral[“BE”, “LE”], optional
Byte order used for encoding multi-byte values. Defaults to big-endian (“BE”).
- startint
Starting bit position (inclusive).
- endint
Ending bit position (inclusive).
- class EnumEntry¶
Bases:
BaseModelRepresents a single entry in an enumeration.
Parameters¶
- valueint
Numeric value associated with the enumeration entry.
- namestr
Symbolic name of the enumeration entry.
- descriptionstr, optional
Human-readable description of the enumeration entry.
- class Enum¶
Bases:
DatatypeAllows modeling SOME/IP enumerations with value, name, and description.
Parameters¶
- namestr
Unique name of the datatype.
- descriptionstr, optional
Human-readable description of the datatype.
- typeLiteral[“enum”]
Datatype discriminator identifying this datatype as an enumeration.
- endiannessLiteral[“BE”, “LE”], optional
Byte order used for encoding multi-byte values. Defaults to big-endian (“BE”).
- base_typeInts, optional
Underlying integer datatype used to encode enumeration values. Defaults to
UInt8.- entrieslist of
EnumEntry, optional List of enumeration entries defining the mapping between numeric values and symbolic names.
- class IPv4AddressEntry¶
Bases:
FLYNCBaseModelRepresents an IPv4 address entry for a network interface.
Parameters¶
- address
IPv4Address The IPv4 address.
- ipv4netmask
IPv4Address The subnet mask in IPv4 format.
- address
- class IPv6AddressEntry¶
Bases:
FLYNCBaseModelRepresents an IPv6 address entry for a network interface.
Parameters¶
- address
IPv6Address The IPv6 address.
- ipv6prefixint
The prefix length (0-128).
- address
- class MACAddressEntry¶
Bases:
FLYNCBaseModelRepresents an MAC address entry for a network interface.
- Parameters:
- address (str):
Source MAC address to filter by. Format: “xx:xx:xx:xx:xx:xx”
- macmask (str):
The mask in MAC format. Format: “xx:xx:xx:xx:xx:xx”
- class UnicastMACAddressEntry¶
Bases:
MACAddressEntryRepresents a Unicast MAC address entry for a network interface.
- class MulticastMACAddressEntry¶
Bases:
MACAddressEntryRepresents a Multicast MAC address entry for a network interface.
- class Boolean¶
Bases:
PrimitiveDatatypeBoolean primitive datatype.
Parameters¶
- namestr
Datatype name. Defaults to
"BOOLEAN".- typeLiteral[“boolean”]
Discriminator identifying the primitive boolean datatype.
- class UInt8¶
Bases:
BaseIntUnsigned 8-bit integer datatype.
Parameters¶
- namestr
Datatype name. Defaults to
"UINT_8".- typeLiteral[“uint8”]
Discriminator identifying this datatype.
- signedLiteral[False]
Indicates that the integer is unsigned.
- bit_sizeint
Storage size in bits. Defaults to 8.
- max_applicative_valueint
Maximum application-level value allowed for this datatype.
- class UInt16¶
Bases:
BaseIntUnsigned 16-bit integer datatype.
Parameters¶
- namestr
Datatype name. Defaults to
"UINT_16".- typeLiteral[“uint16”]
Discriminator identifying this datatype.
- signedLiteral[False]
Indicates that the integer is unsigned.
- bit_sizeint
Storage size in bits. Defaults to 16.
- max_applicative_valueint
Maximum application-level value allowed for this datatype.
- class UInt32¶
Bases:
BaseIntUnsigned 32-bit integer datatype.
Parameters¶
- namestr
Datatype name. Defaults to
"UINT_32".- typeLiteral[“uint32”]
Discriminator identifying this datatype.
- signedLiteral[False]
Indicates that the integer is unsigned.
- bit_sizeint
Storage size in bits. Defaults to 32.
- max_applicative_valueint
Maximum application-level value allowed for this datatype.
- class UInt64¶
Bases:
BaseIntUnsigned 64-bit integer datatype.
Parameters¶
- namestr
Datatype name. Defaults to
"UINT_64".- typeLiteral[“uint64”]
Discriminator identifying this datatype.
- signedLiteral[False]
Indicates that the integer is unsigned.
- bit_sizeint
Storage size in bits. Defaults to 64.
- max_applicative_valueint
Maximum application-level value allowed for this datatype.
- class SInt8¶
Bases:
BaseIntSigned 8-bit integer datatype.
Parameters¶
- namestr
Datatype name. Defaults to
"SINT_8".- typeLiteral[“sint8”]
Discriminator identifying this datatype.
- signedLiteral[True]
Indicates that the integer is signed.
- bit_sizeint
Storage size in bits. Defaults to 8.
- max_applicative_valueint
Maximum application-level value allowed for this datatype.
- class SInt16¶
Bases:
BaseIntSigned 16-bit integer datatype.
Parameters¶
- namestr
Datatype name. Defaults to
"SINT_16".- typeLiteral[“sint16”]
Discriminator identifying this datatype.
- signedLiteral[True]
Indicates that the integer is signed.
- bit_sizeint
Storage size in bits. Defaults to 16.
- max_applicative_valueint
Maximum application-level value allowed for this datatype.
- class SInt32¶
Bases:
BaseIntSigned 32-bit integer datatype.
Parameters¶
- namestr
Datatype name. Defaults to
"SINT_32".- typeLiteral[“sint32”]
Discriminator identifying this datatype.
- signedLiteral[True]
Indicates that the integer is signed.
- bit_sizeint
Storage size in bits. Defaults to 32.
- max_applicative_valueint
Maximum application-level value allowed for this datatype.
- class SInt64¶
Bases:
BaseIntSigned 64-bit integer datatype.
Parameters¶
- namestr
Datatype name. Defaults to
"SINT_64".- typeLiteral[“sint64”]
Discriminator identifying this datatype.
- signedLiteral[True]
Indicates that the integer is signed.
- bit_sizeint
Storage size in bits. Defaults to 64.
- max_applicative_valueint
Maximum application-level value allowed for this datatype.
- class Float32¶
Bases:
PrimitiveDatatype32-bit floating-point datatype.
Parameters¶
- namestr
Datatype name. Defaults to
"FLOAT_32".- typeLiteral[“float32”]
Discriminator identifying this datatype.
- max_applicative_valuefloat
Maximum application-level absolute value allowed.
- class Float64¶
Bases:
BaseFloat64-bit floating-point datatype.
Parameters¶
- namestr
Datatype name. Defaults to
"FLOAT_64".- typeLiteral[“float64”]
Discriminator identifying this datatype.
- bit_sizeint
Storage size in bits. Defaults to 64.
- max_applicative_valuefloat
Maximum application-level absolute value allowed.
- class BaseString¶
Bases:
DatatypeBase class for all string datatypes.
Parameters¶
- typestr
Discriminator identifying the concrete string type.
- encodingLiteral[“UTF-8”, “UTF-16BE”, “UTF-16LE”]
Character encoding used for the string payload.
- class FixedLengthString¶
Bases:
BaseStringFixed-length string datatype.
This string occupies a fixed number of bytes on the wire. If the actual content is shorter than the configured length, it is padded with zero bytes.
Parameters¶
- typeLiteral[“fixed_length_string”]
Discriminator used to identify this datatype.
- lengthint
Total length of the string in bytes, including zero-termination and any padding.
- length_of_length_fieldLiteral[0, 8, 16, 32]
Size of the optional length field in bits. A value of 0 indicates that no length field is present.
- class DynamicLengthString¶
Bases:
BaseStringDynamic-length string datatype.
The encoded representation starts with a length field, followed by the string content and a zero-termination character.
Parameters¶
- typeLiteral[“dynamic_length_string”]
Discriminator used to identify this datatype.
- length_of_length_fieldLiteral[8, 16, 32]
Size of the length field in bits that precedes the string data.
- bit_alignmentLiteral[8, 16, 32, 64, 128, 256]
Optional padding alignment applied after the string so that the next parameter starts at the specified bit boundary.
- class Struct¶
Bases:
ComplexDatatypeStructured datatype composed of multiple ordered members.
A struct groups several datatypes into a single composite element that is serialized in the order the members are defined.
Parameters¶
- typeLiteral[“struct”]
Discriminator used to identify this datatype.
- membersList[AllTypes]
Ordered list of datatypes that form the members of the struct.
- bit_alignmentLiteral[8, 16, 32, 64, 128, 256]
Optional padding alignment applied after the struct to ensure the next parameter starts at the specified bit boundary.
- length_of_length_fieldLiteral[0, 8, 16, 32]
Size of the optional length field in bits that prefixes the struct. A value of 0 indicates that no length field is present.
- class UnionMember¶
Bases:
DatatypeRepresents a single member entry of an union datatype.
Each union member defines a possible datatype that may be present, together with its selector index and a descriptive name.
Parameters¶
- typeAllTypes
Member datatype (discriminated by its
typefield).- indexint
Index of the union member. This value is used in the serialized union to indicate which member is currently active. Must be greater than or equal to 0.
- namestr
Name of the union member.
- class Union¶
Bases:
DatatypeRepresents an union datatype.
A union allows exactly one of several possible member datatypes to be encoded at runtime. The active member is identified using a type selector field.
Parameters¶
- typeLiteral[“union”]
Discriminator used to identify this datatype.
- memberslist of
UnionMember List of the allowed datatypes a union can contain.
- bit_alignmentLiteral[8, 16, 32, 64, 128, 256], optional
Defines the optional alignment padding that can be added after the union to fix the alignment of the next parameter to 8, 16, 32, 64, 128 or 256 bits.
- length_of_length_fieldLiteral[0, 8, 16, 32], optional
Defines the length of the length-field in bits for the union.
- length_of_type_fieldLiteral[0, 8, 16, 32], optional
Defines the length of the type-selector field in bits for the union.
- class ValueRange¶
Bases:
FLYNCBaseModelDefines an inclusive range of integer values.
This datatype is typically used to express valid numeric intervals for parameters, identifiers, or signal values.
Parameters¶
- from_valueint
Lower bound of the range (inclusive).
- to_valueint
Upper bound of the range (inclusive).
- class ValueTable¶
Bases:
ComplexDatatypeRepresents a table of values with an associated description.
Parameters¶
- num_valueint
The numeric value associated with this table entry.
- descriptionstr
Human-readable description of the table entry.
- datatypes.AllTypes¶
alias of
Annotated[Annotated[Annotated[SInt8|SInt16|SInt32|SInt64, FieldInfo(annotation=NoneType, required=True, discriminator=’type’)] |Annotated[UInt8|UInt16|UInt32|UInt64, FieldInfo(annotation=NoneType, required=True, discriminator=’type’)], FieldInfo(annotation=NoneType, required=True, discriminator=’type’)] |Annotated[Float32|Float64, FieldInfo(annotation=NoneType, required=True, discriminator=’type’)] |Enum|Boolean|Struct|Union|ArrayType|DynamicLengthString|FixedLengthString|Bitfield, FieldInfo(annotation=NoneType, required=True, discriminator=’type’)]
flync.core.utils¶
base_utils¶
Base Utils that can be useful throughout the whole FLYNC Library and toolchain.
- read_yaml(path: str | PathLike | Path)¶
Read a YAML file.
- Args:
path (str | os.PathLike | Path): Path to the YAML file
- Raises:
err_fatal: If path is not for YAML file.
- Returns:
Any: Retrieved data from YAML.
- write_to_file(data, outfile: str = 'exports/generated.yaml')¶
Simply write some data to a file.
- Args:
data (Any): Data to write to the file.
outfile (str, optional): Path to the file. Defaults to “exports/generated.yaml”.
- get_yaml_paths(base_path: str | PathLike) list¶
Collect absolute paths to yaml files from a base_path.
- Args:
base_path (str | os.PathLike): Base Path to FLYNC Config.
- Returns:
list: List of absolute file paths to yaml files.
- is_mac_address(input: str) Tuple[bool, str]¶
Helper to check if an input is a valid MAC address based on pydantic validator.
- Args:
input (str): input string that should be checked.
- Returns:
bool: Returns the result of check as a boolean as well as a message that could be used in logging or exception handling. If the result boolean is true, the provided input is a MAC address. If the boolean is false, it is not.
- is_mac_unicast(input: str) Tuple[bool, str]¶
Helper to check if a MAC address is unicast. Unicast if first byte’s least significant bit is 0.
- Args:
input (str): input string that should be checked.
- Returns:
Union[bool, str]: Returns the result of check as a boolean as well as a message that could be used in logging or exception handling. If the result boolean is true, the provided input is an unicast MAC address. If the boolean is false, it is not.
- is_mac_multicast(input: str) Tuple[bool, str]¶
Method to check if a MAC address is multicast. Multicast if first byte’s least significant bit is 1.
- Args:
input (str): input string that should be checked.
- Returns:
Union[bool, str]: Returns the result of check as a boolean as well as a message that could be used in logging or exception handling. If the result boolean is true, the provided input is a MAC multicast address. If the boolean is false, it is not.
- is_ip_address(input: IPv4Address | IPv6Address | str) Tuple[bool, str]¶
Helper to check if an input is a valid IP address.
- Args:
input (
IPv4Address|IPv6Address| str): input string that should be checked.- Returns:
bool: Returns the result of check as a boolean as well as a message that could be used in logging or exception handling. If the result boolean is true, the provided input is an IP address. If the boolean is false, it is not.
- is_ip_multicast(input: IPv4Address | IPv6Address | str) Tuple[bool, str]¶
Method to check if a string is an IP multicast address.
- Args:
input (
IPv4Address|IPv6Address): input string that should be checked.- Returns:
Union[bool, str]: Returns the result of check as a boolean as well as a message that could be used in logging or exception handling. If the result boolean is true, the provided input is an IP multicast address. If the boolean is false, it is not.
- get_duplicates_in_list(input: list) list¶
Find duplicates in a list.
- Args:
input (list): a list where duplicates are suspected.
- Returns:
list: returns a list of the duplicates that were found.
- check_obj_in_list(obj, list)¶
Helper function: To check if the object is in the list or not
common_validators¶
Common Validators are validation methods that are used throughout the whole FLYNC model. The Validators either raise minor, major or fatal errors as pydantic usage proposes.
- validate_mac_unicast(input: str) str¶
Custom Validator for Unicast MAC addresses.
- Args:
input (str): MAC address to validate.
- Raises:
err_minor: Input is not a Unicast address based on the expected format.
- Returns:
Any: Input is handed over.
- validate_mac_multicast(input: str) Any¶
Custom Validator for Multicast MAC addresses.
- Args:
input (str): MAC address to validate.
- Raises:
err_minor: Input is not a Multicast address based on the expected format.
- Returns:
Any: Input is handed over.
- validate_ip_multicast(input: IPv4Address | IPv6Address | str) Any¶
Custom Validator for Multicast IP addresses.
- Args:
input (
IPv4Address|IPv6Address): IP address to validate.- Raises:
err_minor: Input is not a Multicast address based on the expected format.
- Returns:
Any: Input is handed over.
- validate_any_multicast_address(input: IPv4Address | IPv6Address | str) Any¶
Custom Validator for Multicast MAC or IP addresses.
- Args:
input (
IPv4Address|IPv6Address| str): IP address or MAC Address to validate.- Raises:
err_minor: The address is not a multicast address.
- Returns:
Any: Input is handed over.
- validate_multicast_list_only_ip(input_list: list)¶
Custom Validator for a list of Multicast IP addresses.
- Args:
input_list (list): List of only Multicast IPs.
- Raises:
err_minor: Any of the addresses in the list is not an IP multicast address.
- validate_multicast_list(input_list: list)¶
Custom Validator for a list of Multicast MAC or IP addresses.
- Args:
input_list (list): List of Multicast IPs and MACs.
- Raises:
err_minor: Any of the addresses in the list is not a multicast address.
- validate_list_items_unique(input_list: list, list_label: str | None = None) list¶
Custom Validator for a list of items where every item should be unique.
- Args:
input_list (list): List of items.
list_label(str): Add an optional label to the error message.
- Raises:
err_major: List contains duplicates.
- Returns:
list: Input is handed over.
- validate_cbs_idleslopes_fit_portspeed(traffic_classes: list, port_speed: int)¶
Custom Validator for a list of Traffic Classes to check conformity to MII/MDI speed.
- Args:
traffic_classes (list): List of element type TrafficClass.
port_speed (int): MII or MDI speed of the port.
- Raises:
- err_major: The sum of idleslopes of all shapers on one port
must be equal or lower than the port speed.
- Returns:
list: Return list of traffic classes as received.
- validate_optional_mii_config_compatibility(comp1, comp2, id)¶
Custom validator for optional MII configuration compatibility between two components.
- Args:
comp1 (object): First component that may contain a
mii_configattribute.comp2 (object): Second component that may contain a
mii_configattribute.id (Any): Identifier of the connection (used only in error messages).
- Raises:
err_major: One component has an MII config while the other does not.
err_major: Both components have an MII config but the mode values are identical. The modes must differ.
err_major: Both components have an MII config but the speed values are different.
err_major: Both components have an MII config but the type values are different.
- validate_compulsory_mii_config_compatibility(comp1, comp2, id)¶
Validator that enforces a mandatory MII configuration on both components and then checks optional compatibility.
- Args:
comp1 (object): First component. Must have
mii_config.comp2 (object): Second component. Must have
mii_config.id (Any): Identifier of the connection (used only in error messages).
- Raises:
err_major: Either component is missing a required MII configuration.
err_major: Propagated from
validate_optional_mii_config_compatibility()when the optional checks fail.
- validate_htb(comp, speed)¶
Validator that checks an HTB (Hierarchical Token Bucket) configuration against the physical link speed.
- Args:
comp (object): Component that owns an
htbattribute withchild_classes.speed (int): Link speed of the interface (same unit as the HTB rates).
- Raises:
err_major: The sum of the
ratevalues of all child classes exceeds the providedspeed.
- validate_macsec(comp1, comp2, id)¶
Validator for MACsec configuration compatibility between two components.
- Args:
comp1 (object): First component: May contain a
macsec_config.comp2 (object): Second component: May contain a
macsec_config.id (Any): Identifier of the connection (used only in error messages).
- Raises:
err_major: One component has a MACsec config while the other does not.
err_major: MKA (Key Agreement) enabled state differs between the two components.
err_major:
macsec_modediffers between the two components.
- validate_gptp(comp1, comp2, id)¶
Validator that checks gPTP (generic Precision Time Protocol) configuration compatibility between two components.
- Args:
comp1 (object): First component. May contain a
ptp_config.comp2 (object): Second component. May contain a
ptp_config.id (Any): Identifier of the connection (used only in error messages).
- Raises:
err_major: PTP configuration present on one side only.
err_major: Mismatch of the
cmlds_linkport_enabledflag between the two components.err_major: Propagated from
validate_gptp_domains()when domain level checks fail.
- validate_gptp_domains(comp1, comp2, ptp1, ptp2, id)¶
Helper that validates matching PTP domains and sync-config types between two components.
- Args:
comp1 (object): First component (source of
ptp1).comp2 (object): Second component (source of
ptp2).ptp1 (object):
ptp_configofcomp1.ptp2 (object):
ptp_configofcomp2.id (Any): Identifier of the connection (used only in error messages).
- Raises:
err_major: A domain present in
ptp1is missing inptp2.err_major: The
sync_config.typeof a matching domain is identical on both sides (they must differ for a valid configuration).
- validate_elements_in(subset: Iterable[Any], superset: Iterable[Any], msg: str | None = None)¶
Custom Validator that checks if every element in subset appears at least once in superset. E.g. Validate if port_name is in switch_port_names.
- Args:
subset (Iterable[Any]): Subset where elements are expected to be in superset.
superset (Iterable[Any]): Reference set.
- Returns:
Iterable[Any]: Return subset as received.
- check_prio_unique(traffic_classes)¶
Check if the traffic class prios are unique across various traffic classes in a controller interface or switch.
- check_pcps_different(traffic_classes)¶
Check if the PCPs are different across traffic classes.
- check_ipvs_unique(traffic_classes)¶
Check if ipvs across traffic classes are unique
- validate_traffic_classes(traffic_classes)¶
Validate the traffic classes in a controller interface and switch to find out if a pcp, ipv or traffic class prio is reused or nor
- none_to_empty_list(v)¶
Make the field defined as optional [] if accidentally declared by the user as None
exceptions¶
- err_minor(msg: str, **ctx) PydanticCustomError¶
Factory that returns PydanticCustomError with type minor.
Parameters¶
- msgstr
Error message that may contain placeholders
- ctxdict
Context arguments that define key-value pairs to fill the placeholders in msg
Returns¶
PydanticCustomError
exceptions_handling¶
- errors_to_init_errors(errors: List[ErrorDetails]) List[InitErrorDetails]¶
Function to convert Pydantic validation errors into init Errors to be reraised.
Parameters¶
- errorsList[ErrorDetails]
The list of errors to be converted.
Returns¶
- List[InitErrorDetails]
The converted errors to be reraised.
- delete_at_loc(data: Any, loc: Tuple)¶
Helper function to remove the key/item from original object by loc(path to an element within the object).
Parameters¶
- dataAny
Data to remove the item from. Will be mutated.
- locTuple
Path to the location of item to remove.
- get_unique_errors(errors: List[ErrorDetails]) List[ErrorDetails]¶
A function to get the list of unique errors.
Parameters¶
- errors: List[ErrorDetails]
The list of pydantic’s error details
Returns¶
List[ErrorDetails]
- validate_with_policy(model: Type[FLYNCBaseModel], data: Any) Tuple[FLYNCBaseModel | None, List[ErrorDetails]]¶
Helper function to perform model validation from the given data, collect errors with different severity and perform action based on severity.
Parameters¶
- modelType[FLYNCBaseModel]
Flync model class.
- dataAny
Data to validate and instantiate the model with.
Returns¶
- Tuple[Optional[FLYNCBaseModel], List]
Tuple with optional model instance and list of errors.
Raises¶
ValidationError