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: N/A: # noqa: DAR202 Raises: ValueError: 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 ValueError(msg) pattern = r"^[a-z0-9.\-_@/:]{1,32}\(config\-s[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
def test_update_privilege_levels(sync_cisco_iosxe_conn): sync_cisco_iosxe_conn.privilege_levels["scrapli"] = PrivilegeLevel( pattern=r"^weirdpatterndude$", name="scrapli", previous_priv="", deescalate="", escalate="", escalate_auth=False, escalate_prompt="", ) sync_cisco_iosxe_conn.update_privilege_levels() assert ( sync_cisco_iosxe_conn.comms_prompt_pattern == r"(^[a-z0-9.\-_@()/:]{1,63}>$)|(^[a-z0-9.\-_@/:]{1,63}#$)|(^[a-z0-9.\-_@/:]{1,63}\([a-z0-9.\-@/:\+]{0,32}\)#$)|(^weirdpatterndude$)" ) assert sync_cisco_iosxe_conn._priv_map == { "exec": ["exec"], "privilege_exec": ["exec", "privilege_exec"], "configuration": ["exec", "privilege_exec", "configuration"], "scrapli": ["scrapli"], }
"""scrapli_community.ruckus.fastiron.ruckus_fastiron""" from scrapli.driver.base_network_driver import PrivilegeLevel from scrapli_community.ruckus.fastiron._async import default_async_on_close, default_async_on_open from scrapli_community.ruckus.fastiron.sync 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}\)#$", name="configuration", previous_priv="privilege_exec", deescalate="end", escalate="configure terminal",
"""scrapli.driver.core.cisco_nxos.base_driver""" from typing import Dict from scrapli.driver.base_network_driver import PrivilegeLevel 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", escalate="configure terminal",
"""scrapli.driver.core.cisco_iosxe.base_driver""" from scrapli.driver.base_network_driver import PrivilegeLevel PRIVS = { "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="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.arista_eos.base_driver""" import re from typing import Dict from scrapli.driver.base_network_driver import PrivilegeLevel 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,
"""scrapli_community.huawei.vrp.huawei_vrp""" from scrapli.driver.base_network_driver import PrivilegeLevel from scrapli_community.huawei.vrp._async import default_async_on_close, default_async_on_open from scrapli_community.huawei.vrp.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,64}\]$", name="configuration", previous_priv="privilege_exec", deescalate="quit", escalate="system-view", escalate_auth=False, escalate_prompt="", )), } SCRAPLI_PLATFORM = { "driver_type": "network", # generic|network "defaults": { "privilege_levels": DEFAULT_PRIVILEGE_LEVELS,
"""scrapli.driver.core.juniper_junos.base_driver""" from scrapli.driver.base_network_driver import PrivilegeLevel PRIVS = { "root": (PrivilegeLevel( pattern=r"^root@%\s?$", name="root", previous_priv="", deescalate="", escalate="", escalate_auth=False, escalate_prompt="", )), "exec": (PrivilegeLevel( pattern=r"^({\w+:\d}\n){0,1}[a-z0-9.\-_@()/:]{1,63}>\s?$", name="exec", previous_priv="root", deescalate="start shell", escalate="cli", 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="", )),
"""scrapli.driver.core.cisco_nxos.base_driver""" from typing import Dict from scrapli.driver.base_network_driver import PrivilegeLevel 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"^[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)[a-z0-9.\-@/:]{0,32}\)#\s?$",
"""scrapli_community.edgecore.ecs.edgecore_ecs""" from scrapli.driver.base_network_driver import PrivilegeLevel from scrapli_community.edgecore.ecs._async import default_async_on_close, default_async_on_open from scrapli_community.edgecore.ecs.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}\)#$", name="configuration", previous_priv="privilege_exec", deescalate="end", escalate="conf", escalate_auth=False, escalate_prompt="", )), } SCRAPLI_PLATFORM = { "driver_type": "network", "defaults": { "privilege_levels":
"""scrapli_community.huawei.vrp.huawei_vrp""" from scrapli.driver.base_network_driver import PrivilegeLevel from scrapli_community.huawei.vrp._async import default_async_on_close, default_async_on_open from scrapli_community.huawei.vrp.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( # 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 # ... # # Since the version string is basically in the same format as the prompt in # configuration mode, scrapli only reads until it sees this very string, and then # stops reading since it assumes that a valid prompt has been found.
"""scrapli_community.fortinet.wlc.fortinet_wlc""" from scrapli.driver.base_network_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="", )), } SCRAPLI_PLATFORM = { "driver_type": "network", "defaults": {
"""scrapli.driver.core.cisco_iosxr.base_driver""" from scrapli.driver.base_network_driver import PrivilegeLevel PRIVS = { "privilege_exec": (PrivilegeLevel( pattern=r"^[a-z0-9.\-_@/:]{1,63}#\s?$", name="privilege_exec", previous_priv="", deescalate="", escalate="", escalate_auth=False, escalate_prompt="", )), "configuration": (PrivilegeLevel( pattern=r"^[a-z0-9.\-_@/:]{1,63}\(config[a-z0-9.\-@/:]{0,32}\)#\s?$", name="configuration", previous_priv="privilege_exec", deescalate="end", escalate="configure terminal", escalate_auth=False, escalate_prompt="", )), "configuration_exclusive": (PrivilegeLevel( pattern=r"^[a-z0-9.\-_@/:]{1,63}\(config[a-z0-9.\-@/:]{0,32}\)#\s?$", name="configuration_exclusive", previous_priv="privilege_exec", deescalate="end", escalate="configure exclusive", escalate_auth=False, escalate_prompt="", )),