Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Alexey Shapovalov
noc
Commits
c2b29de6
Commit
c2b29de6
authored
Jan 23, 2022
by
Andrey Vertiprahov
Browse files
Add update effective_labels on update_if_changed.
parent
65bc616f
Changes
3
Hide whitespace changes
Inline
Side-by-side
sa/profiles/Huawei/VRP3/get_interfaces.py
View file @
c2b29de6
...
...
@@ -85,7 +85,7 @@ class Script(BaseScript):
"name"
:
"FE:0/0/1"
,
"type"
:
"physical"
,
"mac"
:
mac
,
"hints"
:
[
"uplink"
],
"hints"
:
[
"
noc::interface::role::
uplink"
],
"subinterfaces"
:
[],
}
]
...
...
@@ -101,7 +101,7 @@ class Script(BaseScript):
vlans
+=
[
v
[
"vlan_id"
]]
iface
=
{
"name"
:
"FE:0/0/1"
,
"hints"
:
[
"nni"
],
"hints"
:
[
"
noc::topology::direction::
nni"
],
"type"
:
"physical"
,
"subinterfaces"
:
[
{
"name"
:
"FE:0/0/1"
,
"enabled_afi"
:
[
"BRIDGE"
],
"tagged_vlans"
:
vlans
}
...
...
@@ -110,7 +110,7 @@ class Script(BaseScript):
interfaces
+=
[
iface
]
iface
=
{
"name"
:
"FE:0/0/2"
,
"hints"
:
[
"nni"
],
"hints"
:
[
"
noc::topology::direction::
nni"
],
"type"
:
"physical"
,
"subinterfaces"
:
[
{
"name"
:
"FE:0/0/2"
,
"enabled_afi"
:
[
"BRIDGE"
],
"tagged_vlans"
:
vlans
}
...
...
services/discovery/jobs/base.py
View file @
c2b29de6
...
...
@@ -27,6 +27,7 @@ from builtins import str, object
# NOC modules
from
noc.core.scheduler.periodicjob
import
PeriodicJob
from
noc.core.models.problem
import
ProblemItem
from
noc.main.models.label
import
Label
,
MATCH_OPS
from
noc.sa.models.managedobject
import
ManagedObject
from
noc.inv.models.subinterface
import
SubInterface
from
noc.inv.models.interfaceprofile
import
InterfaceProfile
...
...
@@ -562,6 +563,19 @@ class DiscoveryCheck(object):
def
handler
(
self
):
pass
@
staticmethod
def
build_effective_labels
(
obj
)
->
List
[
str
]:
"""
Build object effective labels
:param obj:
:return:
"""
return
[
ll
for
ll
in
Label
.
merge_labels
(
obj
.
iter_effective_labels
(
obj
))
if
obj
.
can_set_label
(
ll
)
or
ll
[
-
1
]
in
MATCH_OPS
]
def
update_if_changed
(
self
,
obj
,
...
...
@@ -569,6 +583,7 @@ class DiscoveryCheck(object):
ignore_empty
:
List
[
str
]
=
None
,
wait
:
bool
=
True
,
bulk
:
Optional
[
List
[
str
]]
=
None
,
update_effective_labels
:
bool
=
False
,
):
"""
Update fields if changed.
...
...
@@ -579,6 +594,7 @@ class DiscoveryCheck(object):
:param ignore_empty: List of fields which may be ignored if empty
:param wait: Wait for operation to complete. set write concern to 0 if False
:param bulk: Execute as the bulk op instead
:param update_effective_labels:
:returns: List of changed (key, value)
:rtype: list
"""
...
...
@@ -603,6 +619,10 @@ class DiscoveryCheck(object):
continue
setattr
(
obj
,
k
,
v
)
changes
+=
[(
k
,
v
)]
if
update_effective_labels
and
hasattr
(
obj
,
"effective_labels"
):
el
=
self
.
build_effective_labels
(
obj
)
if
set
(
el
)
!=
set
(
getattr
(
obj
,
"effective_labels"
,
[])):
changes
+=
[(
"effective_labels"
,
el
)]
if
changes
:
if
bulk
is
not
None
:
op
=
{
"$set"
:
dict
(
changes
)}
...
...
services/discovery/jobs/box/interface.py
View file @
c2b29de6
...
...
@@ -279,6 +279,7 @@ class InterfaceCheck(PolicyDiscoveryCheck):
"extra_labels"
:
[
ll
for
ll
in
labels
if
Interface
.
can_set_label
(
ll
)],
},
ignore_empty
=
ignore_empty
,
update_effective_labels
=
True
,
)
self
.
log_changes
(
f
"Interface '
{
name
}
' has been changed"
,
changes
)
else
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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