Skip to content

Input Types

anta.custom_types

Module that provides predefined types for AntaTest.Input instances

AAAAuthMethod module-attribute

AAAAuthMethod = Annotated[str, AfterValidator(aaa_group_prefix)]

Afi module-attribute

Afi = Literal['ipv4', 'ipv6', 'vpn-ipv4', 'vpn-ipv6', 'evpn', 'rt-membership']

Interface module-attribute

Interface = Annotated[str, Field(pattern='^(Dps|Ethernet|Fabric|Loopback|Management|Port-Channel|Tunnel|Vlan|Vxlan)[0-9]+(\\/[0-9]+)*(\\.[0-9]+)?$'), BeforeValidator(interface_autocomplete), BeforeValidator(interface_case_sensitivity)]

Safi module-attribute

Safi = Literal['unicast', 'multicast', 'labeled-unicast']

TestStatus module-attribute

TestStatus = Literal['unset', 'success', 'failure', 'error', 'skipped']

Vlan module-attribute

Vlan = Annotated[int, Field(ge=0, le=4094)]

Vni module-attribute

Vni = Annotated[int, Field(ge=1, le=16777215)]

aaa_group_prefix

aaa_group_prefix(v: str) -> str

Prefix the AAA method with ‘group’ if it is known

Source code in anta/custom_types.py
15
16
17
18
def aaa_group_prefix(v: str) -> str:
    """Prefix the AAA method with 'group' if it is known"""
    built_in_methods = ["local", "none", "logging"]
    return f"group {v}" if v not in built_in_methods and not v.startswith("group ") else v

interface_autocomplete

interface_autocomplete(v: str) -> str

Allow the user to only provide the beginning of an interface name.

Supported alias
  • et, eth will be changed to Ethernet
  • po will be changed to Port-Channel
Source code in anta/custom_types.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
def interface_autocomplete(v: str) -> str:
    """Allow the user to only provide the beginning of an interface name.

    Supported alias:
         - `et`, `eth` will be changed to `Ethernet`
         - `po` will be changed to `Port-Channel`"""
    intf_id_re = re.compile(r"[0-9]+(\/[0-9]+)*(\.[0-9]+)?")
    m = intf_id_re.search(v)
    if m is None:
        raise ValueError(f"Could not parse interface ID in interface '{v}'")
    intf_id = m[0]
    if any(v.lower().startswith(p) for p in ["et", "eth"]):
        return f"Ethernet{intf_id}"
    if v.lower().startswith("po"):
        return f"Port-Channel{intf_id}"
    return v

interface_case_sensitivity

interface_case_sensitivity(v: str) -> str

Reformat interface name to match expected case sensitivity.

Examples:

  • ethernet -> Ethernet
  • vlan -> Vlan
Source code in anta/custom_types.py
39
40
41
42
43
44
45
46
47
48
def interface_case_sensitivity(v: str) -> str:
    """Reformat interface name to match expected case sensitivity.

    Examples:
         - ethernet -> Ethernet
         - vlan -> Vlan
    """
    if isinstance(v, str) and len(v) > 0 and not v[0].isupper():
        return f"{v[0].upper()}{v[1:]}"
    return v