# py312
# requirements:
# pyeapi==1.0.4
import ssl
from typing import TypedDict
from urllib.parse import urlsplit
import pyeapi
class arista_eos(TypedDict):
host: str
username: str
password: str
port: int
verify_tls: bool
def main(auth: arista_eos, session_name: str):
"""
Abort Config Session
Abort a config session: an uncommitted one is discarded, and one pending under a commit timer is rolled back to the configuration before it.
"""
node(auth).run_commands([f"configure session {session_name} abort"])
return {"session": session_name, "aborted": True}
# host is an address or a URL (https://10.0.0.11:8443). pyeapi skips certificate checks unless it is given a context,
# so one is always passed: verifying, or not when the resource unticks verify_tls (EOS ships a self-signed cert).
def node(auth: arista_eos, timeout: float = 60):
url = urlsplit(auth["host"] if "://" in auth["host"] else f"https://{auth['host']}")
context = ssl.create_default_context()
if auth.get("verify_tls") is False:
context.check_hostname = False
context.verify_mode = ssl.CERT_NONE
return pyeapi.connect(
transport=url.scheme,
host=url.hostname,
port=url.port or auth.get("port") or None,
username=auth["username"],
password=auth["password"],
context=context,
timeout=timeout,
return_node=True,
)
Submitted by hugo989 4 hours ago