Skip to content

Commit

Permalink
Merge branch 'ktbyers:develop' into add_cisco_apic
Browse files Browse the repository at this point in the history
  • Loading branch information
yone2ks authored May 6, 2024
2 parents bacf03f + fae3d31 commit 24d4750
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
name: linters
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Setup python
uses: actions/setup-python@v1
uses: actions/setup-python@v5
id: cp311
with:
python-version: '3.11'
Expand Down Expand Up @@ -62,21 +62,15 @@ jobs:

runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Setup python
uses: actions/setup-python@v1
uses: actions/setup-python@v5
id: py_ver
with:
python-version: ${{ matrix.python-version }}
architecture: x64

- name: Setup python
uses: actions/setup-python@v1
with:
python-version: '3.11'
architecture: x64

- name: Install Poetry
uses: snok/install-poetry@v1
with:
Expand Down
2 changes: 1 addition & 1 deletion EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ A set of common Netmiko use cases.
## Table of contents

#### Available Device Types
- [Available device types](#available-device-types)
- [Available device types](#available-device-types-1)

#### Simple Examples
- [Simple example](#simple-example)
Expand Down
6 changes: 4 additions & 2 deletions PLATFORMS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
- Cisco IOS-XR
- Cisco NX-OS
- Cisco SG300
- HP ProCurve
- Juniper Junos
- Linux

Expand All @@ -20,6 +19,7 @@
- Alcatel AOS6/AOS8
- Apresia Systems AEOS
- ARRIS CER
- Aruba OS Switch
- AudioCodes Gateways & Controllers
- Broadcom ICOS
- Calix B6
Expand All @@ -42,6 +42,7 @@
- Fiberstore FSOS
- Hillstone StoneOS
- HPE Comware7
- HPE ProCurve
- Huawei
- Huawei OLT
- Huawei SmartAX
Expand Down Expand Up @@ -73,7 +74,8 @@
- A10
- Accedian
- Allied Telesis AlliedWare Plus
- Aruba
- Aruba OS (Wireless Controllers/WAPs)
- Aruba AOS-CX
- Brocade Fabric OS
- C-DOT CROS
- Ciena SAOS
Expand Down
5 changes: 3 additions & 2 deletions netmiko/aruba/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from netmiko.aruba.aruba_ssh import ArubaSSH
from netmiko.aruba.aruba_os import ArubaOsSSH
from netmiko.aruba.aruba_cx import ArubaCxSSH

__all__ = ["ArubaSSH"]
__all__ = ["ArubaOsSSH", "ArubaCxSSH"]
42 changes: 42 additions & 0 deletions netmiko/aruba/aruba_cx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""
Aruba AOS CX support.
For use with Aruba AOS CX devices.
"""
from typing import Any
from netmiko.cisco_base_connection import CiscoSSHConnection


class ArubaCxSSH(CiscoSSHConnection):
"""Aruba AOS CX support"""

def __init__(self, **kwargs: Any) -> None:
if kwargs.get("default_enter") is None:
kwargs["default_enter"] = "\r"
return super().__init__(**kwargs)

def session_preparation(self) -> None:
self.ansi_escape_codes = True
self._test_channel_read(pattern=r"[>#]")
self.set_base_prompt()
self.disable_paging(command="no page")

def check_config_mode(
self,
check_string: str = "(config)#",
pattern: str = r"[>#]",
force_regex: bool = False,
) -> bool:
return super().check_config_mode(check_string=check_string, pattern=pattern)

def config_mode(
self,
config_command: str = "configure term",
pattern: str = "",
re_flags: int = 0,
) -> str:
"""Aruba auto completes on space so 'configure' needs fully spelled-out."""
return super().config_mode(
config_command=config_command, pattern=pattern, re_flags=re_flags
)
2 changes: 1 addition & 1 deletion netmiko/aruba/aruba_ssh.py → netmiko/aruba/aruba_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from netmiko.cisco_base_connection import CiscoSSHConnection


class ArubaSSH(CiscoSSHConnection):
class ArubaOsSSH(CiscoSSHConnection):
"""Aruba OS support"""

def __init__(self, **kwargs: Any) -> None:
Expand Down
4 changes: 3 additions & 1 deletion netmiko/base_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,8 @@ def __init__(
if self.secret:
no_log["secret"] = self.secret
# Always sanitize username and password
log.addFilter(SecretsFilter(no_log=no_log))
self._secrets_filter = SecretsFilter(no_log=no_log)
log.addFilter(self._secrets_filter)

# Netmiko will close the session_log if we open the file
if session_log is not None:
Expand Down Expand Up @@ -2480,6 +2481,7 @@ def disconnect(self) -> None:
self.remote_conn = None
if self.session_log:
self.session_log.close()
log.removeFilter(self._secrets_filter)

def commit(self) -> str:
"""Commit method for platforms that support this."""
Expand Down
12 changes: 8 additions & 4 deletions netmiko/sophos/sophos_sfos_ssh.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
"""SophosXG (SFOS) Firewall support"""
import time
from typing import Any
import time
import os

from netmiko.no_enable import NoEnable
from netmiko.no_config import NoConfig
from netmiko.cisco_base_connection import CiscoSSHConnection


SOPHOS_MENU_DEFAULT = os.getenv("NETMIKO_SOPHOS_MENU", "4")


class SophosSfosSSH(NoEnable, NoConfig, CiscoSSHConnection):
def session_preparation(self) -> None:
"""Prepare the session after the connection has been established."""
self._test_channel_read()
self._test_channel_read(pattern=r"Main Menu")
"""
Sophos Firmware Version SFOS 18.0.0 GA-Build339
Expand All @@ -27,8 +31,8 @@ def session_preparation(self) -> None:
Select Menu Number [0-7]:
"""
self.write_channel("4" + self.RETURN)
self._test_channel_read(pattern=r"[console>]")
self.write_channel(SOPHOS_MENU_DEFAULT + self.RETURN)
self._test_channel_read(pattern=r"[#>]")
self.set_base_prompt()
# Clear the read buffer
time.sleep(0.3 * self.global_delay_factor)
Expand Down
6 changes: 6 additions & 0 deletions netmiko/ssh_autodetect.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@
"priority": 99,
"dispatch": "_autodetect_std",
},
"cisco_ftd": {
"cmd": "show version",
"search_patterns": [r"Cisco Firepower"],
"priority": 99,
"dispatch": "_autodetect_std",
},
"cisco_ios": {
"cmd": "show version",
"search_patterns": [
Expand Down
5 changes: 3 additions & 2 deletions netmiko/ssh_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from netmiko.arista import AristaFileTransfer
from netmiko.arris import ArrisCERSSH
from netmiko.apresia import ApresiaAeosSSH, ApresiaAeosTelnet
from netmiko.aruba import ArubaSSH
from netmiko.aruba import ArubaOsSSH, ArubaCxSSH
from netmiko.audiocode import (
Audiocode72SSH,
Audiocode66SSH,
Expand Down Expand Up @@ -160,7 +160,8 @@
"apresia_aeos": ApresiaAeosSSH,
"arista_eos": AristaSSH,
"arris_cer": ArrisCERSSH,
"aruba_os": ArubaSSH,
"aruba_os": ArubaOsSSH,
"aruba_cx": ArubaCxSSH,
"aruba_osswitch": HPProcurveSSH,
"aruba_procurve": HPProcurveSSH,
"audiocode_72": Audiocode72SSH,
Expand Down
12 changes: 11 additions & 1 deletion tests/unit/test_base_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from os.path import dirname, join
from threading import Lock

from netmiko import NetmikoTimeoutException
from netmiko import NetmikoTimeoutException, log
from netmiko.base_connection import BaseConnection

RESOURCE_FOLDER = join(dirname(dirname(__file__)), "etc")
Expand Down Expand Up @@ -480,3 +480,13 @@ def test_strip_ansi_codes():

# code_next_line must be substituted with a return
assert connection.strip_ansi_escape_codes("\x1bE") == "\n"


def test_remove_SecretsFilter_after_disconnection():
connection = BaseConnection(
host="testhost", # Enter the hostname to pass initialization
auto_connect=False, # No need to connect for the test purposes
)
connection.disconnect()

assert not log.filters

0 comments on commit 24d4750

Please sign in to comment.