Parameters¶
This module defines the Param class, it’s type specific derivatives (IntParam, StrParam) and the Parameters class which serves as a container for Param instances. This can be used by a BaseRecipe class to specify optional/mandatory parameters for the entire test, or by HostReq and DeviceReq classes to define specific parameters needed for the matching algorithm.
-
class
lnst.Common.Parameters.
ChoiceParam
(type=None, choices={}, **kwargs)¶ Choice Param This parameter is used for sitiuation where a param can have one of a specified set of valid values. For example:
>>> flow_type = ChoiceParam(type=StrParam, choices=set('tcp_rr', 'udp_rr', 'tcp_crr'))
The type check will fail if the specified value does not pass both the specified subtype type_check or is not one of the specified choices.
-
class
lnst.Common.Parameters.
NetworkParam
(type: Union[ipaddress.IPv4Network, ipaddress.IPv6Network], **kwargs)¶ Network Param
Parameters of this type are used to specify a IPv4 or IPv6 networks. (network address + prefix length).
- For example::
- vlan0_ipv4 = IPv4NetworkParam(default=”192.168.10.0/24”) vlan0_ipv6 = IPv6NetworkParam(default=”fc00:0:0:1::/64”)
-
class
lnst.Common.Parameters.
Param
(mandatory=False, **kwargs)¶ Base Parameter class
Can beused to define your own specific parameter type. Param derived classes serve as type checkers to enable earlier failure of the recipe.
Parameters: - mandatory (bool) – if True, marks the parameter as mandatory
- default – the default value for the parameter, is also type-checked, immediately at Param object creation
-
type_check
(value)¶ The type check method
Implementation depends on the specific Param derived class.
Returns: the type checked or converted value Raises: ParamError
if the type check or conversion is invalid