0

Abort Config Session

by
Published today

Abort a config session: an uncommitted one is discarded, and one pending under a commit timer is rolled back to the configuration before it.

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, session_name: str):
21
    """
22
    Abort Config Session
23
    Abort a config session: an uncommitted one is discarded, and one pending under a commit timer is rolled back to the configuration before it.
24
    """
25
    node(auth).run_commands([f"configure session {session_name} abort"])
26
    return {"session": session_name, "aborted": True}
27

28

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