Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
135
noc
Commits
df706c5c
Commit
df706c5c
authored
Feb 27, 2020
by
Andrey Vertiprahov
Browse files
Merge branch 'fix-avs-h3c-version' into 'master'
H3C.VRP. Fix get_version and add SNMP scripts. See merge request
noc/noc!3240
parents
808f22aa
b0cea1f1
Changes
8
Hide whitespace changes
Inline
Side-by-side
sa/profiles/H3C/VRP/get_chassis_id.py
View file @
df706c5c
...
...
@@ -10,7 +10,7 @@
import
re
# NOC modules
from
noc.
core.script.base
import
BaseScript
from
noc.
sa.profiles.Generic.get_chassis_id
import
Script
as
BaseScript
from
noc.sa.interfaces.igetchassisid
import
IGetChassisID
from
noc.core.mac
import
MAC
...
...
@@ -19,10 +19,10 @@ class Script(BaseScript):
name
=
"H3C.VRP.get_chassis_id"
cache
=
True
interface
=
IGetChassisID
always_prefer
=
"S"
rx_mac_old
=
re
.
compile
(
r
"MAC address[^:]*?:\s*(?P<id>\S+)"
,
re
.
IGNORECASE
|
re
.
MULTILINE
)
@
BaseScript
.
match
(
version__startswith
=
"3.02"
)
def
execute_old
(
self
):
v
=
self
.
cli
(
"display stp"
)
match
=
self
.
rx_mac_old
.
search
(
v
)
...
...
@@ -33,20 +33,24 @@ class Script(BaseScript):
rx_mac1
=
re
.
compile
(
r
"^\s*MAC(_|\s)ADDRESS[^:]*?:\s(?P<id>\S+)"
,
re
.
IGNORECASE
|
re
.
MULTILINE
)
@
BaseScript
.
match
()
def
execute_new
(
self
):
def
execute_cli
(
self
,
**
kwargs
):
if
self
.
is_old_version
:
return
self
.
execute_old
()
shift
=
0
if
self
.
match_version
(
platform__contains
=
"S3600"
)
:
if
self
.
is_S3600_platform
:
# S3600 platform has additional MAC address for L3
shift
=
1
v
=
self
.
cli
(
"display stp"
)
match
=
self
.
rx_mac
.
search
(
v
)
if
match
is
not
None
:
mac
=
match
.
group
(
"id"
)
else
:
v
=
self
.
cli
(
"display device manuinfo"
)
match
=
self
.
rx_mac1
.
search
(
v
)
try
:
v
=
self
.
cli
(
"display stp"
)
match
=
self
.
rx_mac
.
search
(
v
)
mac
=
match
.
group
(
"id"
)
except
self
.
CLISyntaxError
:
try
:
v
=
self
.
cli
(
"display device manuinfo"
)
match
=
self
.
rx_mac1
.
search
(
v
)
mac
=
match
.
group
(
"id"
)
except
self
.
CLISyntaxError
:
raise
NotImplementedError
if
shift
:
last_mac
=
str
(
MAC
(
mac
).
shift
(
shift
))
else
:
...
...
sa/profiles/H3C/VRP/get_interfaces.py
View file @
df706c5c
...
...
@@ -91,18 +91,21 @@ class Script(BaseScript):
# Get IPv4 interfaces
ipv4_interfaces
=
defaultdict
(
list
)
# interface -> [ipv4 addresses]
c_iface
=
None
for
l
in
self
.
cli
(
"display ip interface"
).
splitlines
():
match
=
self
.
rx_dis_ip_int
.
search
(
l
)
if
match
:
c_iface
=
self
.
profile
.
convert_interface_name
(
match
.
group
(
"interface"
))
continue
# Primary ip
match
=
self
.
rx_ip
.
search
(
l
)
if
not
match
:
continue
ip
=
match
.
group
(
"ip"
)
ipv4_interfaces
[
c_iface
]
+=
[
ip
]
try
:
v
=
self
.
cli
(
"display ip interface"
)
for
l
in
v
.
splitlines
():
match
=
self
.
rx_dis_ip_int
.
search
(
l
)
if
match
:
c_iface
=
self
.
profile
.
convert_interface_name
(
match
.
group
(
"interface"
))
continue
# Primary ip
match
=
self
.
rx_ip
.
search
(
l
)
if
not
match
:
continue
ip
=
match
.
group
(
"ip"
)
ipv4_interfaces
[
c_iface
]
+=
[
ip
]
except
self
.
CLISyntaxError
:
pass
interfaces
=
[]
# Get OSPF interfaces
ospfs
=
self
.
get_ospfint
()
...
...
sa/profiles/H3C/VRP/get_lldp_neighbors.py
View file @
df706c5c
...
...
@@ -11,7 +11,7 @@
import
re
# NOC modules
from
noc.
core.script.base
import
BaseScript
from
noc.
sa.profiles.Generic.get_lldp_neighbors
import
Script
as
BaseScript
from
noc.sa.interfaces.igetlldpneighbors
import
IGetLLDPNeighbors
,
MACAddressParameter
...
...
@@ -19,13 +19,6 @@ class Script(BaseScript):
name
=
"H3C.VRP.get_lldp_neighbors"
interface
=
IGetLLDPNeighbors
#
# No lldp on 3.02 and older
#
@
BaseScript
.
match
(
version__startswith
=
"3.02"
)
def
execute_old
(
self
):
raise
self
.
NotSupportedError
()
#
# Other (3.03 and newer)
#
...
...
@@ -34,14 +27,16 @@ class Script(BaseScript):
re
.
MULTILINE
|
re
.
DOTALL
|
re
.
IGNORECASE
,
)
@
BaseScript
.
match
()
def
execute_other
(
self
):
def
execute_cli
(
self
,
**
kwargs
):
if
self
.
is_old_version
:
# No lldp on 3.02 and older
raise
self
.
NotSupportedError
()
r
=
[]
i
=
{}
try
:
lldp
=
self
.
cli
(
"display lldp neighbor"
)
except
self
.
CLISyntaxError
:
r
eturn
[]
r
aise
NotImplementedError
while
True
:
match
=
self
.
rx_ifc_line
.
search
(
lldp
)
if
not
match
:
...
...
@@ -65,7 +60,11 @@ def parse_neighbor(text):
re
.
MULTILINE
|
re
.
DOTALL
|
re
.
IGNORECASE
,
)
rx_neigh
=
re
.
compile
(
r
"\s+Chassis\s*ID\s*:\s*(?P<id>\S+).*?Port\s*ID\s*(sub)*type\s*:\s*(?P<p_type>[\w\s]+)\n\s+Port\s*ID\s*:\s*(?P<p_id>.+?)\n.+?Sys.*?name\s*:\s*(?P<name>[^\n]+)\n.*?Sys.*?cap.*?enabled\s*:\s*(?P<capability>[^\n]+)"
,
r
"\s+Chassis\s*ID\s*:\s*(?P<id>\S+).*?"
r
"Port\s*ID\s*(sub)*type\s*:\s*(?P<p_type>[\w\s]+)\n\s+"
r
"Port\s*ID\s*:\s*(?P<p_id>.+?)\n.+?"
r
"Sys.*?name\s*:\s*(?P<name>[^\n]+)\n.*?"
r
"Sys.*?cap.*?enabled\s*:\s*(?P<capability>[^\n]+)"
,
re
.
MULTILINE
|
re
.
IGNORECASE
|
re
.
DOTALL
,
)
n
=
[]
...
...
sa/profiles/H3C/VRP/get_portchannel.py
View file @
df706c5c
...
...
@@ -16,7 +16,10 @@ class Script(BaseScript):
interface
=
IGetPortchannel
def
execute
(
self
):
r
=
self
.
cli
(
"display link-aggregation summary"
)
if
"No link-aggregation"
in
r
:
try
:
r
=
self
.
cli
(
"display link-aggregation summary"
)
if
"No link-aggregation"
in
r
:
return
[]
except
self
.
CLISyntaxError
:
return
[]
raise
self
.
NotSupportedError
()
sa/profiles/H3C/VRP/get_switchport.py
View file @
df706c5c
...
...
@@ -62,9 +62,9 @@ class Script(BaseScript):
# Get ports in vlans
r
=
[]
if
self
.
match
_version
(
version__startswith
=
"5.3"
)
:
if
self
.
is_53
_version
:
v
=
self
.
cli
(
"display port allow-vlan"
)
elif
self
.
match_version
(
version__startswith
=
"3.10"
)
:
elif
self
.
is_310_version
:
rx_line
=
re
.
compile
(
r
"""
(?P<interface>\S+)\scurrent\sstate
...
...
sa/profiles/H3C/VRP/get_version.py
View file @
df706c5c
...
...
@@ -25,7 +25,7 @@ class Script(BaseScript):
re
.
MULTILINE
|
re
.
DOTALL
|
re
.
IGNORECASE
,
)
rx_ver1
=
re
.
compile
(
r
"^\s*Comware\sSoftware,\s\\Version\s(?P<version>.+?),\s"
r
"^\s*Comware\sSoftware,\s
(
\\
|)
Version\s(?P<version>.+?),\s"
r
"(Release)?(?P<release>\w+(\s)?\w+).*(H3C )(?P<platform>[a-zA-Z0-9\-]+) uptime is"
,
re
.
MULTILINE
|
re
.
DOTALL
|
re
.
IGNORECASE
,
)
...
...
sa/profiles/H3C/VRP/get_vlans.py
View file @
df706c5c
...
...
@@ -5,13 +5,12 @@
# Copyright (C) 2007-2011 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
"""
"""
# Python modules
import
re
# NOC Modules
from
noc.
core.script.base
import
BaseScript
from
noc.
sa.profiles.Generic.get_vlans
import
Script
as
BaseScript
from
noc.sa.interfaces.igetvlans
import
IGetVlans
...
...
@@ -24,8 +23,7 @@ class Script(BaseScript):
re
.
IGNORECASE
|
re
.
DOTALL
|
re
.
MULTILINE
,
)
@
BaseScript
.
match
()
def
execute_vrp3
(
self
):
def
execute_cli
(
self
,
**
kwargs
):
vlans
=
self
.
cli
(
"display vlan all"
)
return
[
{
"vlan_id"
:
int
(
match
.
group
(
"vlan_id"
)),
"name"
:
match
.
group
(
"name"
)}
...
...
sa/profiles/H3C/VRP/profile.py
View file @
df706c5c
...
...
@@ -24,6 +24,13 @@ class Profile(BaseProfile):
command_disable_pager
=
""
pattern_syntax_error
=
r
"% Wrong parameter|% Unrecognized command found at"
matchers
=
{
"is_old_version"
:
{
"version"
:
{
"$regex"
:
r
"3.02.*"
}},
"is_310_version"
:
{
"version"
:
{
"$regex"
:
r
"3.10.*"
}},
"is_53_version"
:
{
"version"
:
{
"$regex"
:
r
"5.3\S+"
}},
"is_S3600_platform"
:
{
"platform"
:
{
"$regex"
:
r
".*S3600.*"
}},
}
def
generate_prefix_list
(
self
,
name
,
pl
,
strict
=
True
):
p
=
"ip ip-prefix %s permit %%s"
%
name
if
not
strict
:
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment