0

Get MLAG

by
Published today

MLAG state of the switch: state, negotiation, peer-link, config-sanity, reload-delay (seconds) and the status of every MLAG port (show mlag detail, show mlag config-sanity, show mlag interfaces).

Script arista_eos Verified

The script

Submitted by hugo989 Python3
Verified 3 hours ago
1
# py312
2
# requirements:
3
# pyeapi==1.0.4
4

5
import ssl
6
from typing import TypedDict
7
from urllib.parse import urlsplit
8

9
import pyeapi
10

11

12
class arista_eos(TypedDict):
13
    host: str
14
    username: str
15
    password: str
16
    port: int
17
    verify_tls: bool
18

19

20
def main(auth: arista_eos):
21
    """
22
    Get MLAG
23
    MLAG state of the switch: state, negotiation, peer-link, config-sanity, reload-delay (seconds) and the status of every MLAG port (show mlag detail, show mlag config-sanity, show mlag interfaces).
24
    """
25
    detail, config_sanity, interfaces = node(auth).run_commands(
26
        ["show mlag detail", "show mlag config-sanity", "show mlag interfaces"]
27
    )
28
    return {
29
        **detail,
30
        "config_sanity": config_sanity,
31
        "interfaces": interfaces.get("interfaces"),
32
    }
33

34

35
# host is an address or a URL (https://10.0.0.11:8443). pyeapi skips certificate checks unless it is given a context,
36
# so one is always passed: verifying, or not when the resource unticks verify_tls (EOS ships a self-signed cert).
37
def node(auth: arista_eos, timeout: float = 60):
38
    url = urlsplit(auth["host"] if "://" in auth["host"] else f"https://{auth['host']}")
39
    context = ssl.create_default_context()
40
    if auth.get("verify_tls") is False:
41
        context.check_hostname = False
42
        context.verify_mode = ssl.CERT_NONE
43
    return pyeapi.connect(
44
        transport=url.scheme,
45
        host=url.hostname,
46
        port=url.port or auth.get("port") or None,
47
        username=auth["username"],
48
        password=auth["password"],
49
        context=context,
50
        timeout=timeout,
51
        return_node=True,
52
    )
53