# 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, save: bool = True):
"""
Confirm Commit
Confirm a session committed with a commit timer, so it is kept, and save the running config to startup-config.
"""
node(auth).run_commands(
[
f"configure session {session_name} commit",
*(["write memory"] if save else []),
],
)
return {"session": session_name, "confirmed": True, "saved": save}
# 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