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', 'path-selection', 'link-state']

BfdInterval module-attribute

BfdInterval = Annotated[int, Field(ge=50, le=60000)]

BfdMultiplier module-attribute

BfdMultiplier = Annotated[int, Field(ge=3, le=50)]

EcdsaKeySize module-attribute

EcdsaKeySize = Literal[256, 384, 512]

EncryptionAlgorithm module-attribute

EncryptionAlgorithm = Literal['RSA', 'ECDSA']

ErrDisableInterval module-attribute

ErrDisableInterval = Annotated[int, Field(ge=30, le=86400)]

ErrDisableReasons module-attribute

ErrDisableReasons = Literal['acl', 'arp-inspection', 'bpduguard', 'dot1x-session-replace', 'hitless-reload-down', 'lacp-rate-limit', 'link-flap', 'no-internal-vlan', 'portchannelguard', 'portsec', 'tapagg', 'uplink-failure-detection']

EthernetInterface module-attribute

EthernetInterface = Annotated[str, Field(pattern='^Ethernet[0-9]+(\\/[0-9]+)*$'), BeforeValidator(interface_autocomplete), BeforeValidator(interface_case_sensitivity)]

Hostname module-attribute

Hostname = Annotated[str, Field(pattern=REGEXP_TYPE_HOSTNAME)]

Interface module-attribute

Interface = Annotated[str, Field(pattern=REGEXP_TYPE_EOS_INTERFACE), BeforeValidator(interface_autocomplete), BeforeValidator(interface_case_sensitivity)]

MlagPriority module-attribute

MlagPriority = Annotated[int, Field(ge=1, le=32767)]

MultiProtocolCaps module-attribute

MultiProtocolCaps = Annotated[str, BeforeValidator(bgp_multiprotocol_capabilities_abbreviations)]

Percent module-attribute

Percent = Annotated[float, Field(ge=0.0, le=100.0)]

Port module-attribute

Port = Annotated[int, Field(ge=1, le=65535)]

PositiveInteger module-attribute

PositiveInteger = Annotated[int, Field(ge=0)]

REGEXP_BGP_IPV4_MPLS_LABELS module-attribute

REGEXP_BGP_IPV4_MPLS_LABELS = '\\b(ipv4[\\s\\-]?mpls[\\s\\-]?label(s)?)\\b'

Match IPv4 MPLS Labels.

REGEXP_BGP_L2VPN_AFI module-attribute

REGEXP_BGP_L2VPN_AFI = '\\b(l2[\\s\\-]?vpn[\\s\\-]?evpn)\\b'

Match L2VPN EVPN AFI.

REGEXP_EOS_BLACKLIST_CMDS module-attribute

REGEXP_EOS_BLACKLIST_CMDS = ['^reload.*', '^conf\\w*\\s*(terminal|session)*', '^wr\\w*\\s*\\w+']

List of regular expressions to blacklist from eos commands.

REGEXP_INTERFACE_ID module-attribute

REGEXP_INTERFACE_ID = '\\d+(\\/\\d+)*(\\.\\d+)?'

Match Interface ID lilke 1/1.1.

REGEXP_PATH_MARKERS module-attribute

REGEXP_PATH_MARKERS = '[\\\\\\/\\s]'

Match directory path from string.

REGEXP_TYPE_EOS_INTERFACE module-attribute

REGEXP_TYPE_EOS_INTERFACE = '^(Dps|Ethernet|Fabric|Loopback|Management|Port-Channel|Tunnel|Vlan|Vxlan)[0-9]+(\\/[0-9]+)*(\\.[0-9]+)?$'

Match EOS interface types like Ethernet1/1, Vlan1, Loopback1, etc.

REGEXP_TYPE_HOSTNAME module-attribute

REGEXP_TYPE_HOSTNAME = '^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])$'

Match hostname like my-hostname, my-hostname-1, my-hostname-1-2.

REGEXP_TYPE_VXLAN_SRC_INTERFACE module-attribute

REGEXP_TYPE_VXLAN_SRC_INTERFACE = '^(Loopback)([0-9]|[1-9][0-9]{1,2}|[1-7][0-9]{3}|8[01][0-9]{2}|819[01])$'

Match Vxlan source interface like Loopback10.

REGEX_BGP_IPV4_MPLS_VPN module-attribute

REGEX_BGP_IPV4_MPLS_VPN = '\\b(ipv4[\\s\\-]?mpls[\\s\\-]?vpn)\\b'

Match IPv4 MPLS VPN.

REGEX_BGP_IPV4_UNICAST module-attribute

REGEX_BGP_IPV4_UNICAST = '\\b(ipv4[\\s\\-]?uni[\\s\\-]?cast)\\b'

Match IPv4 Unicast.

RegexString module-attribute

RegexString = Annotated[str, AfterValidator(validate_regex)]

Revision module-attribute

Revision = Annotated[int, Field(ge=1, le=99)]

RsaKeySize module-attribute

RsaKeySize = Literal[2048, 3072, 4096]

Safi module-attribute

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

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)]

VxlanSrcIntf module-attribute

VxlanSrcIntf = Annotated[str, Field(pattern=REGEXP_TYPE_VXLAN_SRC_INTERFACE), BeforeValidator(interface_autocomplete), BeforeValidator(interface_case_sensitivity)]

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
38
39
40
41
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

bgp_multiprotocol_capabilities_abbreviations

bgp_multiprotocol_capabilities_abbreviations(value: str) -> str

Abbreviations for different BGP multiprotocol capabilities.

Examples
- IPv4 Unicast
- L2vpnEVPN
- ipv4 MPLS Labels
- ipv4Mplsvpn
Source code in anta/custom_types.py
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
def bgp_multiprotocol_capabilities_abbreviations(value: str) -> str:
    """Abbreviations for different BGP multiprotocol capabilities.

    Examples
    --------
        - IPv4 Unicast
        - L2vpnEVPN
        - ipv4 MPLS Labels
        - ipv4Mplsvpn

    """
    patterns = {
        REGEXP_BGP_L2VPN_AFI: "l2VpnEvpn",
        REGEXP_BGP_IPV4_MPLS_LABELS: "ipv4MplsLabels",
        REGEX_BGP_IPV4_MPLS_VPN: "ipv4MplsVpn",
        REGEX_BGP_IPV4_UNICAST: "ipv4Unicast",
    }

    for pattern, replacement in patterns.items():
        match = re.search(pattern, value, re.IGNORECASE)
        if match:
            return replacement

    return value

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 - lo will be changed to Loopback

Source code in anta/custom_types.py
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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`
    - `lo` will be changed to `Loopback`
    """
    intf_id_re = re.compile(REGEXP_INTERFACE_ID)
    m = intf_id_re.search(v)
    if m is None:
        msg = f"Could not parse interface ID in interface '{v}'"
        raise ValueError(msg)
    intf_id = m[0]

    alias_map = {"et": "Ethernet", "eth": "Ethernet", "po": "Port-Channel", "lo": "Loopback"}

    return next((f"{full_name}{intf_id}" for alias, full_name in alias_map.items() if v.lower().startswith(alias)), v)

interface_case_sensitivity

interface_case_sensitivity(v: str) -> str

Reformat interface name to match expected case sensitivity.

Examples
 - ethernet -> Ethernet
 - vlan -> Vlan
 - loopback -> Loopback
Source code in anta/custom_types.py
64
65
66
67
68
69
70
71
72
73
74
75
76
def interface_case_sensitivity(v: str) -> str:
    """Reformat interface name to match expected case sensitivity.

    Examples
    --------
         - ethernet -> Ethernet
         - vlan -> Vlan
         - loopback -> Loopback

    """
    if isinstance(v, str) and v != "" and not v[0].isupper():
        return f"{v[0].upper()}{v[1:]}"
    return v

validate_regex

validate_regex(value: str) -> str

Validate that the input value is a valid regex format.

Source code in anta/custom_types.py
105
106
107
108
109
110
111
112
def validate_regex(value: str) -> str:
    """Validate that the input value is a valid regex format."""
    try:
        re.compile(value)
    except re.error as e:
        msg = f"Invalid regex: {e}"
        raise ValueError(msg) from e
    return value