def _create_configuration_session(self, session_name: str) -> None: """ Handle configuration session creation tasks for consistency between sync/async versions Args: session_name: name of session to register Returns: None Raises: ScrapliValueError: if a session of given name already exists """ if session_name in self.privilege_levels.keys(): msg = ( f"session name `{session_name}` already registered as a privilege level, chose a " "unique session name") raise ScrapliValueError(msg) sess_prompt = re.escape(session_name[:6]) pattern = ( rf"^[a-z0-9.\-@()/: ]{{1,63}}\(config\-s\-{sess_prompt}[a-z0-9_.\-@/:]{{0,32}}\)#\s?$" ) name = session_name config_session = PrivilegeLevel( pattern=pattern, name=name, previous_priv="privilege_exec", deescalate="end", escalate=f"configure session {session_name}", escalate_auth=False, escalate_prompt="", ) self.privilege_levels[name] = config_session
"""scrapli.driver.core.juniper_junos.base_driver""" from scrapli.driver.network.base_driver import PrivilegeLevel PRIVS = { "exec": (PrivilegeLevel( pattern=r"^({\w+:\d}\n){0,1}[a-z0-9.\-_@()/:]{1,63}>\s?$", name="exec", previous_priv="", deescalate="", escalate="", escalate_auth=False, escalate_prompt="", )), "configuration": (PrivilegeLevel( pattern=r"^({\w+:\d}\[edit\]\n){0,1}[a-z0-9.\-_@()/:]{1,63}#\s?$", name="configuration", previous_priv="exec", deescalate="exit configuration-mode", escalate="configure", escalate_auth=False, escalate_prompt="", )), "configuration_exclusive": (PrivilegeLevel( pattern=r"^({\w+:\d}\[edit\]\n){0,1}[a-z0-9.\-_@()/:]{1,63}#\s?$", name="configuration_exclusive", previous_priv="exec", deescalate="exit configuration-mode", escalate="configure exclusive", escalate_auth=False, escalate_prompt="", )),
AsyncHuaweiVRPDriver, default_async_on_close, default_async_on_open, ) from scrapli_community.huawei.vrp.sync import ( HuaweiVRPDriver, default_sync_on_close, default_sync_on_open, ) DEFAULT_PRIVILEGE_LEVELS = { "privilege_exec": (PrivilegeLevel( pattern=r"^<[a-z0-9.\-_@()/:]{1,48}>\s*$", name="privilege_exec", previous_priv="", deescalate="", escalate="", escalate_auth=False, escalate_prompt="", )), "configuration": ( PrivilegeLevel( # On some versions of VRP running on the AR160 & AR650 router series (and possibly # others), the router outputs the current OS version in the following format when # calling the command 'display current-configuration': # # <HOSTNAME>display current-configuration # [V200R009C00SPC500] # # # sysname HOSTNAME # ...
from scrapli.driver.network.base_driver import PrivilegeLevel from scrapli_community.ruckus.fastiron.async_driver import ( default_async_on_close, default_async_on_open, ) from scrapli_community.ruckus.fastiron.sync_driver import ( default_sync_on_close, default_sync_on_open, ) DEFAULT_PRIVILEGE_LEVELS = { "exec": (PrivilegeLevel( pattern=r"^[a-z0-9.\-_@()/:]{1,63}>$", name="exec", previous_priv="", deescalate="", escalate="", escalate_auth=False, escalate_prompt="", )), "privilege_exec": (PrivilegeLevel( pattern=r"^[a-z0-9.\-_@/:]{1,63}#$", name="privilege_exec", previous_priv="exec", deescalate="quit", escalate="enable", escalate_auth=True, escalate_prompt=r"^[pP]assword:\s?$", )), "configuration": (PrivilegeLevel( pattern=r"^[a-z0-9.\-_@/:]{1,63}\(conf[a-z0-9.\-@/:\+]{0,32}\)#$",
"""scrapli.driver.core.cisco_iosxr.base_driver""" from scrapli.driver.network.base_driver import PrivilegeLevel PRIVS = { "privilege_exec": (PrivilegeLevel( pattern=r"^[\w.\-@/:]{1,63}#\s?$", name="privilege_exec", previous_priv="", deescalate="", escalate="", escalate_auth=False, escalate_prompt="", )), "configuration": (PrivilegeLevel( pattern=r"^[\w.\-@/:]{1,63}\(config[\w.\-@/:]{0,32}\)#\s?$", name="configuration", previous_priv="privilege_exec", deescalate="end", escalate="configure terminal", escalate_auth=False, escalate_prompt="", )), "configuration_exclusive": (PrivilegeLevel( pattern=r"^[\w.\-@/:]{1,63}\(config[\w.\-@/:]{0,32}\)#\s?$", name="configuration_exclusive", previous_priv="privilege_exec", deescalate="end", escalate="configure exclusive", escalate_auth=False, escalate_prompt="", )),
"""scrapli_community.nokia.srlinux.nokia_srlinux""" from scrapli.driver.network.base_driver import PrivilegeLevel from scrapli_community.nokia.srlinux.async_driver import ( default_async_on_close, default_async_on_open, ) from scrapli_community.nokia.srlinux.sync_driver import default_sync_on_close, default_sync_on_open DEFAULT_PRIVILEGE_LEVELS = { "exec": (PrivilegeLevel( pattern=r"^--{\srunning\s}--\[.+?\]--\s*\n[abcd]:\S+#\s*$", name="exec", previous_priv="", deescalate="", escalate="", escalate_auth=False, escalate_prompt="", )), "configuration": (PrivilegeLevel( pattern=r"^--{\scandidate[\-\w\s]+}--\[.+?\]--\s*\n[abcd]:\S+#\s*$", name="configuration", previous_priv="exec", deescalate="discard now", escalate="enter candidate exclusive", escalate_auth=False, escalate_prompt="", )), } SCRAPLI_PLATFORM = { "driver_type": "network",
"""scrapli.driver.core.arista_eos.base_driver""" import re from typing import Dict from scrapli.driver.network.base_driver import PrivilegeLevel from scrapli.exceptions import ScrapliValueError PRIVS = { "exec": ( PrivilegeLevel( # pattern has... gotten a bit out of hand. it seems some eos devices can have things in # parenthesis in a "normal" (non config) prompt... something like `my(eos)#`. To make # sure we account for that but do *not* include config modes we need this negative # lookahead to *not* match "config"... the remaining pattern is the "normal" scrapli # eos pattern basically pattern=r"^((?!config)[a-z0-9.\-@()/: ]){1,63}>\s?$", name="exec", previous_priv="", deescalate="", escalate="", escalate_auth=False, escalate_prompt="", )), "privilege_exec": (PrivilegeLevel( pattern=r"^((?!config)[a-z0-9.\-@()/: ]){1,63}#\s?$", name="privilege_exec", previous_priv="exec", deescalate="disable", escalate="enable", escalate_auth=True, escalate_prompt=r"^[pP]assword:\s?$", )),
"""scrapli_community.fortinet.wlc.fortinet_wlc""" from scrapli.driver.network.base_driver import PrivilegeLevel from scrapli_community.fortinet.wlc._async import default_async_on_close, default_async_on_open from scrapli_community.fortinet.wlc.sync import default_sync_on_close, default_sync_on_open DEFAULT_PRIVILEGE_LEVELS = { "privilege_exec": ( PrivilegeLevel( pattern=r"^[a-z0-9-]{1,48}\(\d{1,2}\)#\s*$", name="privilege_exec", previous_priv="", deescalate="", escalate="", escalate_auth=False, escalate_prompt="", ) ), "configuration": ( PrivilegeLevel( pattern=r"^[a-z0-9-]{1,48}\(\d{1,2}\)\(conf[a-z0-9.\-@/:\+]{0,32}\)#\s*$", name="configuration", previous_priv="privilege_exec", deescalate="end", escalate="configure terminal", escalate_auth=False, escalate_prompt="", ) ), }
classic_default_async_on_open, default_async_on_close, default_async_on_open, ) from scrapli_community.nokia.sros.sync_driver import ( classic_default_sync_on_open, default_sync_on_close, default_sync_on_open, ) DEFAULT_PRIVILEGE_LEVELS = { "exec": (PrivilegeLevel( pattern= r"^(?!\(ex\)|\(ro\)|\(gl\)|\(pr\))\[.*\]\n[abcd]:[\w\._]+@[\w\s_-]+#\s?$", name="exec", previous_priv="", deescalate="", escalate="", escalate_auth=False, escalate_prompt="", )), "configuration": (PrivilegeLevel( pattern=r"^(?:!|\*)?\(ex\)\[\/?\]\n\*?[abcd]:[\w\._]+@[\w\s_-]+#\s?$", name="configuration", previous_priv="exec", deescalate="quit-config", escalate="edit-config exclusive", escalate_auth=False, escalate_prompt="", )), "configuration_with_path": (PrivilegeLevel( pattern=
"""scrapli.driver.core.cisco_iosxe.base_driver""" from scrapli.driver.network.base_driver import PrivilegeLevel PRIVS = { "exec": ( PrivilegeLevel( pattern=r"^(?!tcl)[\w.\-@/:]+>$", name="exec", previous_priv="", deescalate="", escalate="", escalate_auth=False, escalate_prompt="", ) ), "privilege_exec": ( PrivilegeLevel( pattern=r"^(?!tcl)[\w.\-@/:]+#$", name="privilege_exec", previous_priv="exec", deescalate="disable", escalate="enable", escalate_auth=True, escalate_prompt=r"^(?:enable\s){0,1}password:\s?$", ) ), "configuration": ( PrivilegeLevel( pattern=r"^[\w.\-@/:]+\((?!tcl)[\w.\-@/:+]{0,32}\)#$", name="configuration", previous_priv="privilege_exec",
"""scrapli.driver.core.cisco_nxos.base_driver""" from typing import Dict from scrapli.driver.network.base_driver import PrivilegeLevel from scrapli.exceptions import ScrapliValueError PRIVS = { "exec": (PrivilegeLevel( pattern=r"^[a-z0-9.\-_@()/:]{1,63}>\s?$", name="exec", previous_priv="", deescalate="", escalate="", escalate_auth=False, escalate_prompt="", )), "privilege_exec": (PrivilegeLevel( pattern=r"^((?!\-tcl)[a-z0-9.\-_@/:]){1,63}#\s?$", name="privilege_exec", previous_priv="exec", deescalate="disable", escalate="enable", escalate_auth=True, escalate_prompt=r"^[pP]assword:\s?$", )), "configuration": (PrivilegeLevel( pattern= r"^[a-z0-9.\-_@/:]{1,63}\(config(?!\-s)(?!\-tcl)[a-z0-9.\-@/:]{0,32}\)#\s?$", name="configuration", previous_priv="privilege_exec", deescalate="end",
"""scrapli_community.siemens.roxii.siemens_roxii""" from scrapli.driver.network.base_driver import PrivilegeLevel from scrapli_community.siemens.roxii._async import default_async_on_close, default_async_on_open from scrapli_community.siemens.roxii.sync import default_sync_on_close, default_sync_on_open DEFAULT_PRIVILEGE_LEVELS = { "privilege_exec": ( PrivilegeLevel( pattern=r"^[a-z0-9\-_]{1,48}#\s*$", name="privilege_exec", previous_priv="", deescalate="", escalate="", escalate_auth=False, escalate_prompt="", ) ), "configuration": ( PrivilegeLevel( pattern=r"^[a-z0-9\-_]{1,63}\(conf[a-z0-9.\-@/:\+]{0,32}\)#\s*$", name="configuration", previous_priv="privilege_exec", deescalate="top; exit", escalate="config", escalate_auth=False, escalate_prompt="", ) ), }
AsyncHPComwareDriver, default_async_on_close, default_async_on_open, ) from scrapli_community.hp.comware.sync_driver import ( HPComwareDriver, default_sync_on_close, default_sync_on_open, ) DEFAULT_PRIVILEGE_LEVELS = { "privilege_exec": (PrivilegeLevel( pattern=r"^<[a-z0-9.\-_@()/:]{1,48}>\s*$", name="privilege_exec", previous_priv="", deescalate="", escalate="", escalate_auth=False, escalate_prompt="", )), "configuration": (PrivilegeLevel( pattern=r"^(?=\[[a-z0-9.\-_@/:]{1,64}\]$).*$", name="configuration", previous_priv="privilege_exec", deescalate="quit", escalate="system-view", escalate_auth=False, escalate_prompt="", )), }
"""scrapli.driver.core.arista_eos.base_driver""" import re from typing import Dict from scrapli.driver.network.base_driver import PrivilegeLevel from scrapli.exceptions import ScrapliValueError PRIVS = { "exec": (PrivilegeLevel( pattern=r"^[\w.\-@()/: ]{1,63}>\s?$", name="exec", previous_priv="", deescalate="", escalate="", escalate_auth=False, escalate_prompt="", )), "privilege_exec": (PrivilegeLevel( pattern=r"^[\w.\-@()/: ]{1,63}#\s?$", name="privilege_exec", previous_priv="exec", deescalate="disable", escalate="enable", escalate_auth=True, escalate_prompt=r"^[pP]assword:\s?$", not_contains=["(config"], )), "configuration": (PrivilegeLevel( pattern=r"^[\w.\-@()/: ]{1,63}\(config[\w.\-@/:]{0,32}\)#\s?$", name="configuration", previous_priv="privilege_exec",
"""scrapli_community.paloalto.panos.paloalto_panos""" from scrapli.driver.network.base_driver import PrivilegeLevel from scrapli_community.paloalto.panos.async_driver import ( default_async_on_close, default_async_on_open, ) from scrapli_community.paloalto.panos.sync_driver import default_sync_on_close, default_sync_on_open DEFAULT_PRIVILEGE_LEVELS = { "exec": (PrivilegeLevel( pattern=r"^[\w\._-]+@[\w\._-]+>\s?$", name="exec", previous_priv="", deescalate="", escalate="", escalate_auth=False, escalate_prompt="", )), "configuration": (PrivilegeLevel( pattern=r"^[\w\._-]+@[\w\._-]+#\s?$", name="configuration", previous_priv="exec", deescalate="exit", escalate="configure", escalate_auth=False, escalate_prompt="", )), } SCRAPLI_PLATFORM = {
"""scrapli_community.edgecore.ecs.edgecore_ecs""" from scrapli.driver.network.base_driver import PrivilegeLevel from scrapli_community.edgecore.ecs.async_driver import ( default_async_on_close, default_async_on_open, ) from scrapli_community.edgecore.ecs.sync_driver import default_sync_on_close, default_sync_on_open DEFAULT_PRIVILEGE_LEVELS = { "privilege_exec": (PrivilegeLevel( pattern=r"^[a-z0-9.\-_@()/:]{1,48}#\s*$", name="privilege_exec", previous_priv="", deescalate="", escalate="", escalate_auth=False, escalate_prompt="", )), "configuration": (PrivilegeLevel( pattern=r"^[a-z0-9.\-_@/:]{1,63}\(conf[a-z0-9.\-@/:\+]{0,32}\)#$", name="configuration", previous_priv="privilege_exec", deescalate="end", escalate="conf", escalate_auth=False, escalate_prompt="", )), } SCRAPLI_PLATFORM = { "driver_type": "network",
"""scrapli.driver.core.cisco_iosxe.base_driver""" from scrapli.driver.network.base_driver import PrivilegeLevel PRIVS = { "exec": (PrivilegeLevel( pattern=r"^((?!tcl)[a-z0-9.\-_@()/:]){1,63}>$", name="exec", previous_priv="", deescalate="", escalate="", escalate_auth=False, escalate_prompt="", )), "privilege_exec": (PrivilegeLevel( pattern=r"^((?!tcl)[a-z0-9.\-_@/:]){1,63}#$", name="privilege_exec", previous_priv="exec", deescalate="disable", escalate="enable", escalate_auth=True, escalate_prompt=r"^(?:enable\s){0,1}password:\s?$", )), "configuration": (PrivilegeLevel( pattern=r"^[a-z0-9.\-_@/:]{1,63}\((?!tcl)[a-z0-9.\-@/:\+]{0,32}\)#$", name="configuration", previous_priv="privilege_exec", deescalate="end", escalate="configure terminal", escalate_auth=False, escalate_prompt="", )),
"""scrapli.driver.core.juniper_junos.base_driver""" from scrapli.driver.network.base_driver import PrivilegeLevel PRIVS = { "exec": (PrivilegeLevel( pattern=r"^({\w+:\d}\n){0,1}[\w\-@()/:\.]{1,63}>\s?$", name="exec", previous_priv="", deescalate="", escalate="", escalate_auth=False, escalate_prompt="", )), "configuration": (PrivilegeLevel( pattern=r"^({\w+:\d}\[edit\]\n){0,1}[\w\-@()/:\.]{1,63}#\s?$", name="configuration", previous_priv="exec", deescalate="exit configuration-mode", escalate="configure", escalate_auth=False, escalate_prompt="", )), "configuration_exclusive": (PrivilegeLevel( pattern=r"^({\w+:\d}\[edit\]\n){0,1}[\w\-@()/:\.]{1,63}#\s?$", name="configuration_exclusive", previous_priv="exec", deescalate="exit configuration-mode", escalate="configure exclusive", escalate_auth=False, escalate_prompt="", )),