Commit e6844fba authored by Andrey Vertiprahov's avatar Andrey Vertiprahov
Browse files

Merge branch 'cherry-pick-f7abdee4' into 'release-22.1'

release-22.1:Backport!6349

See merge request !6370
parents d9a7c32f 0837d51e
{"description": "", "$collection": "sa.profiles", "name": "Mellanox.Onyx", "uuid": "74567265-0704-405f-bf40-62fb4f010f91"}
\ No newline at end of file
---
uuid: 465caebf-452e-44e7-96ac-c26188329500
---
# Mellanox.Onyx
<!-- prettier-ignore -->
!!! todo
Describe *Mellanox.Onyx* profile
## Supported Scripts
{{ supported_scripts("Mellanox.Onyx") }}
---
uuid: 633076ad-006e-4c75-8cdc-3a3eb4a94b8b
---
# Mellanox
`Mellanox.*` family of profiles support various [Mellanox](https://www.mellanox.com)
network equipment.
## Supported Profiles
- [Mellanox.Onyx](Mellanox.Onyx.md)
## Supported Platforms
{{ supported_platforms('Mellanox') }}
......@@ -310,6 +310,9 @@ nav:
- Meinberg:
- Overview: user/reference/profiles/Meinberg/index.md
- Meinberg.LANTIME: user/reference/profiles/Meinberg/Meinberg.LANTIME.md
- Mellanox:
- Overview: user/reference/profiles/Mellanox/index.md
- Mellanox.Onyx: user/reference/profiles/Mellanox/Mellanox.Onyx.md
- MikroTik:
- Overview: user/reference/profiles/MikroTik/index.md
- MikroTik.RouterOS: user/reference/profiles/MikroTik/MikroTik.RouterOS.md
......
---
uuid: 00152ed1-88cd-4e2d-8dde-f1efe4976e83
---
# Mellanox.Onyx
<!-- prettier-ignore -->
!!! todo
Describe *Mellanox.Onyx* profile
## Supported Scripts
{{ supported_scripts("Mellanox.Onyx") }}
---
uuid: 46de1046-a14c-4a3a-a0ef-119fa2a5fe36
---
# Mellanox
`Mellanox.*` family of profiles support various [Mellanox](https://www.mellanox.com)
network equipment.
## Supported Profiles
- [Mellanox.Onyx](Mellanox.Onyx.md)
## Supported Platforms
{{ supported_platforms('Mellanox') }}
......@@ -321,6 +321,9 @@ nav:
- Meinberg:
- Overview: user/reference/profiles/Meinberg/index.md
- Meinberg.LANTIME: user/reference/profiles/Meinberg/Meinberg.LANTIME.md
- Mellanox:
- Overview: user/reference/profiles/Mellanox/index.md
- Mellanox.Onyx: user/reference/profiles/Mellanox/Mellanox.Onyx.md
- MikroTik:
- Overview: user/reference/profiles/MikroTik/index.md
- MikroTik.RouterOS: user/reference/profiles/MikroTik/MikroTik.RouterOS.md
......
# ---------------------------------------------------------------------
# Mellanox.Onyx.get_capabilities
# ---------------------------------------------------------------------
# Copyright (C) 2007-2022 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
# NOC modules
from noc.sa.profiles.Generic.get_capabilities import Script as BaseScript
from noc.sa.profiles.Generic.get_capabilities import false_on_cli_error
class Script(BaseScript):
name = "Mellanox.Onyx.get_capabilities"
@false_on_cli_error
def has_lldp_cli(self):
"""
Check box has LLDP enabled
"""
c = self.cli("show lldp local", cached=True)
return "LLDP: enabled" in c
# ---------------------------------------------------------------------
# Mellanox.Onyx.get_chassis_id
# ---------------------------------------------------------------------
# Copyright (C) 2007-2022 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
# Python modules
import re
# NOC modules
from noc.sa.profiles.Generic.get_chassis_id import Script as BaseScript
from noc.sa.interfaces.igetchassisid import IGetChassisID
class Script(BaseScript):
name = "Mellanox.Onyx.get_chassis_id"
interface = IGetChassisID
cache = True
rx_mac = re.compile(r"^\s+Chassis id: (\S+)\s*\n", re.MULTILINE)
def execute_cli(self):
c = self.cli("show lldp local", cached=True)
mac = self.rx_mac.search(c).group(1)
return [{"first_chassis_mac": mac, "last_chassis_mac": mac}]
# ---------------------------------------------------------------------
# Mellanox.Onyx.get_config
# ---------------------------------------------------------------------
# Copyright (C) 2007-2022 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
# NOC modules
from noc.core.script.base import BaseScript
from noc.sa.interfaces.igetconfig import IGetConfig
class Script(BaseScript):
name = "Mellanox.Onyx.get_config"
interface = IGetConfig
def execute_cli(self, policy="r"):
assert policy in ("r", "s")
if policy == "s":
config = self.cli("show configuration")
else:
config = self.cli("show configuration running")
return self.cleaned_config(config)
# ----------------------------------------------------------------------
# Mellanox.Onyx.get_interfaces
# ----------------------------------------------------------------------
# Copyright (C) 2007-2022 The NOC Project
# See LICENSE for details
# ----------------------------------------------------------------------
# Python modules
import re
# NOC modules
from noc.sa.profiles.Generic.get_interfaces import Script as BaseScript
from noc.sa.interfaces.igetinterfaces import IGetInterfaces
class Script(BaseScript):
name = "Mellanox.Onyx.get_interfaces"
interface = IGetInterfaces
rx_iface = re.compile(
r"^(?P<ifname>Eth\S+):\s*\n"
r"^\s+Admin state\s+: (?P<admin_state>\S+)\s*\n"
r"^\s+Operational state\s+: (?P<oper_state>\S+)\s*\n"
r"^\s+Last change in operational status: .+\n"
r"^\s+Boot delay time\s+: \d+ sec\s*\n"
r"^\s+Description\s+: (?P<description>.+)\n"
r"^\s+Mac address\s+: (?P<mac>\S+)\s*\n"
r"^\s+MTU\s+: (?P<mtu>\d+)",
re.MULTILINE,
)
rx_ip = re.compile(
r"^(?P<ifname>Vlan \d+):\s*\n"
r"^\s+Admin state\s+: (?P<admin_state>\S+)\s*\n"
r"^\s+Operational state: (?P<oper_state>\S+)\s*\n"
r"^\s+Autostate\s+: \S+\s*\n"
r"^\s+Mac Address\s+: (?P<mac>\S+)\s*\n"
r"^\s+DHCP client\s+: \S+\s*\n"
r"^\s+PBR route-map\s+: .+\n"
r"^\s*\n"
r"^\s+IPv4 address:\s*\n"
r"^\s+(?P<ip>\d\S+) \[primary\]\s*\n"
r"^\s*\n"
r"^\s+Broadcast address:\s*\n"
r"^\s+.+\n"
r"^\s*\n"
r"^\s+MTU\s+: (?P<mtu>\d+) bytes",
re.MULTILINE,
)
def execute_cli(self):
interfaces = []
c = self.cli("show interfaces", cached=True)
for match in self.rx_iface.finditer(c):
iface = {
"name": match.group("ifname"),
"type": "physical",
"admin_status": match.group("admin_state") == "Enabled",
"oper_status": match.group("oper_state") == "Up",
"mac": match.group("mac"),
"subinterfaces": [
{
"name": match.group("ifname"),
"admin_status": match.group("admin_state") == "Enabled",
"oper_status": match.group("oper_state") == "Up",
"mac": match.group("mac"),
"mtu": match.group("mtu"),
"enabled_afi": ["BRIDGE"],
}
],
}
if match.group("description").strip() != "N/A":
iface["description"] = match.group("description").strip()
interfaces += [iface]
c = self.cli("show ip interface")
for match in self.rx_ip.finditer(c):
iface = {
"name": match.group("ifname"),
"type": "SVI",
"admin_status": match.group("admin_state") == "Enabled",
"oper_status": match.group("oper_state") == "Up",
"mac": match.group("mac"),
"subinterfaces": [
{
"name": match.group("ifname"),
"admin_status": match.group("admin_state") == "Enabled",
"oper_status": match.group("oper_state") == "Up",
"mac": match.group("mac"),
"mtu": match.group("mtu"),
"enabled_afi": ["IPv4"],
"ipv4_addesses": [match.group("ip")],
"vlan_ids": match.group("ifname")[5:],
}
],
}
interfaces += [iface]
return [{"interfaces": interfaces}]
# ---------------------------------------------------------------------
# Mellanox.Onyx.get_lldp_neighbors
# ---------------------------------------------------------------------
# Copyright (C) 2007-2022 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
# Python modules
import re
# NOC modules
from noc.sa.profiles.Generic.get_lldp_neighbors import Script as BaseScript
from noc.sa.interfaces.igetlldpneighbors import IGetLLDPNeighbors
from noc.core.lldp import (
LLDP_PORT_SUBTYPE_MAC,
LLDP_PORT_SUBTYPE_NAME,
LLDP_CHASSIS_SUBTYPE_MAC,
LLDP_CAP_OTHER,
LLDP_CAP_REPEATER,
LLDP_CAP_BRIDGE,
LLDP_CAP_WLAN_ACCESS_POINT,
LLDP_CAP_ROUTER,
LLDP_CAP_TELEPHONE,
LLDP_CAP_DOCSIS_CABLE_DEVICE,
LLDP_CAP_STATION_ONLY,
lldp_caps_to_bits,
)
class Script(BaseScript):
name = "Mellanox.Onyx.get_lldp_neighbors"
interface = IGetLLDPNeighbors
rx_lldp = re.compile(
r"^(?P<local>Eth\S+):\s*\n"
r"^\s+Remote Index\s+: \d+\s*\n"
r"^\s+Remote chassis id\s+: (?P<remote_id>.+)\s*\n"
r"^\s+chassis id subtype\s+: (?P<remote_type>.+) \(\d+\)\s*\n"
r"^\s+Remote port-id\s+: (?P<remote_port>.+)\n"
r"^\s+port id subtype\s+: (?P<remote_port_type>.+) \(\d+\)\s*\n"
r"^\s+Remote port description\s+: (?P<remote_port_descr>.+)\s*\n"
r"^\s+Remote system name\s+: (?P<remote_system_name>.+)\s*\n"
r"^\s+Remote system description\s+: (?P<remote_system_descr>(.+\n)+)\s*\n"
r"^\s+Remote system capabilities supported: .+\n"
r"^\s+Remote system capabilities enabled : (?P<caps>\S+)\s*\n",
re.MULTILINE,
)
def execute_cli(self):
r = []
c = self.cli("show lldp interfaces ethernet remote")
for match in self.rx_lldp.finditer(c):
i = {
"local_interface": match.group("local"),
"neighbors": [
{
"remote_chassis_subtype": {
"Mac Address": LLDP_CHASSIS_SUBTYPE_MAC,
}[match.group("remote_type").strip()],
"remote_chassis_id": match.group("remote_id"),
"remote_port_subtype": {
"Mac Address": LLDP_PORT_SUBTYPE_MAC,
"Interface Name": LLDP_PORT_SUBTYPE_NAME,
}[match.group("remote_port_type").strip()],
"remote_port": match.group("remote_port"),
"remote_port_description": match.group("remote_port_descr"),
"remote_system_name": match.group("remote_system_name"),
"remote_system_description": match.group("remote_system_descr"),
"remote_capabilities": lldp_caps_to_bits(
match.group("caps").strip().split(","),
{
"o": LLDP_CAP_OTHER,
"p": LLDP_CAP_REPEATER,
"b": LLDP_CAP_BRIDGE,
"w": LLDP_CAP_WLAN_ACCESS_POINT,
"r": LLDP_CAP_ROUTER,
"t": LLDP_CAP_TELEPHONE,
"c": LLDP_CAP_DOCSIS_CABLE_DEVICE,
"s": LLDP_CAP_STATION_ONLY,
},
),
}
],
}
r += [i]
return r
# ----------------------------------------------------------------------
# Mellanox.Onyx.get_mac_address_table
# ----------------------------------------------------------------------
# Copyright (C) 2007-2022 The NOC Project
# See LICENSE for details
# ----------------------------------------------------------------------
# Python modules
import re
# NOC modules
from noc.core.script.base import BaseScript
from noc.sa.interfaces.igetmacaddresstable import IGetMACAddressTable
class Script(BaseScript):
name = "Mellanox.Onyx.get_mac_address_table"
interface = IGetMACAddressTable
rx_line = re.compile(
r"^(?P<vlan_id>\d+)\s+(?P<mac>\S+)\s+(?P<type>\S+)\s+(?P<interfaces>\S+)\s*\n",
re.MULTILINE,
)
def execute_cli(self, interface=None, vlan=None, mac=None):
r = []
cmd = "show mac-address-table"
if mac is not None:
cmd += " address %s" % mac
if interface is not None:
cmd += " interface %s" % interface
if vlan is not None:
cmd += " vlan %s" % vlan
v = self.cli(cmd)
for match in self.rx_line.finditer(v):
iface = match.group("interfaces")
# if iface == '0':
# continue
r.append(
{
"vlan_id": match.group("vlan_id"),
"mac": match.group("mac"),
"interfaces": [iface],
"type": {"Dynamic": "D", "Static": "S"}[match.group("type")],
}
)
return r
# ---------------------------------------------------------------------
# Mellanox.Onyx.get_version
# ---------------------------------------------------------------------
# Copyright (C) 2007-2022 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
# Python modules
import re
# NOC modules
from noc.core.script.base import BaseScript
from noc.sa.interfaces.igetversion import IGetVersion
class Script(BaseScript):
name = "Mellanox.Onyx.get_version"
interface = IGetVersion
cache = True
rx_platform = re.compile(
r"^CHASSIS\s+(?P<platform>\S+)\s+(?P<serial>\S+)\s+\S+\s+(?P<hardware>\S+)", re.MULTILINE
)
rx_version = re.compile(r"^Product release:\s+(?P<version>\S+)", re.MULTILINE)
def execute_cli(self):
v = self.cli("show inventory", cached=True)
match = self.rx_platform.search(v)
r = {
"vendor": "Mellanox",
"platform": match.group("platform"),
"attributes": {
"HW version": match.group("hardware"),
"Serial Number": match.group("serial"),
},
}
v = self.cli("show version", cached=True)
match = self.rx_version.search(v)
r["version"] = match.group("version")
return r
# ---------------------------------------------------------------------
# Mellanox.Onyx.get_vlans
# ---------------------------------------------------------------------
# Copyright (C) 2007-2022 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
# Python modules
import re
# NOC modules
from noc.core.script.base import BaseScript
from noc.sa.interfaces.igetvlans import IGetVlans
class Script(BaseScript):
name = "Mellanox.Onyx.get_vlans"
interface = IGetVlans
rx_vlan = re.compile(r"^(?P<vlan_id>\d+)\s+(?P<name>\S+)", re.MULTILINE)
def execute_cli(self):
r = []
v = self.cli("show vlan")
for match in self.rx_vlan.finditer(v):
r += [match.groupdict()]
return r
# ---------------------------------------------------------------------
# Vendor: Mellanox
# OS: Onyx
# ---------------------------------------------------------------------
# Copyright (C) 2007-2022 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
# NOC modules
from noc.core.profile.base import BaseProfile
class Profile(BaseProfile):
name = "Mellanox.Onyx"
pattern_username = rb"^[Ll]ogin: "
pattern_more = [
(rb"^lines \d+-\d+ ", b" "),
(rb"^lines \d+-\d+/\d+ \(END\) ", b"\r"),
]
pattern_unprivileged_prompt = rb"^\S+ \[.+\] > "
pattern_prompt = rb"^(?P<hostname>\S+) \[.+\] # "
command_super = b"enable"
pattern_syntax_error = rb"^% Unrecognized command \".+\"\."
command_exit = "exit"
command_disable_pager = "terminal length 999"
config_volatile = [r"^## Generated at .+?\n"]
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment