Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
arthur-zzz
noc
Commits
7f06861e
Commit
7f06861e
authored
Jun 16, 2021
by
Dmitry Lukhtionov
Browse files
Add ability to filter subinterface by VRF
parent
56eae3b7
Changes
2
Hide whitespace changes
Inline
Side-by-side
inv/datasources.py
View file @
7f06861e
# ---------------------------------------------------------------------
# Inventory module datasources
# ---------------------------------------------------------------------
# Copyright (C) 2007-201
9
The NOC Project
# Copyright (C) 2007-20
2
1 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
...
...
@@ -10,6 +10,7 @@ from noc.lib.datasource import DataSource
from
noc.inv.models.interface
import
Interface
from
noc.inv.models.discoveryid
import
DiscoveryID
from
noc.inv.models.subinterface
import
SubInterface
from
noc.inv.models.forwardinginstance
import
ForwardingInstance
from
noc.sa.interfaces.base
import
MACAddressParameter
...
...
@@ -60,17 +61,33 @@ class InterfaceDS(DataSource):
class
ChassisDS
(
DataSource
):
_name
=
"inv.ChassisDS"
def
__init__
(
self
,
mac
=
None
,
ipv4
=
None
):
super
().
__init__
()
def
__init__
(
self
,
mac
=
None
,
ipv4
=
None
,
vrf
=
None
):
self
.
_object
=
None
if
mac
:
mac
=
MACAddressParameter
.
clean
(
mac
)
self
.
_object
=
DiscoveryID
.
find_object
(
mac
)
if
ipv4
:
if
SubInterface
.
objects
.
filter
(
ipv4_addresses
=
ipv4
).
count
()
==
1
:
self
.
_object
=
(
SubInterface
.
objects
.
filter
(
ipv4_addresses
=
ipv4
).
first
().
managed_object
)
if
vrf
is
None
or
vrf
==
"default"
:
if
SubInterface
.
objects
.
filter
(
ipv4_addresses
=
ipv4
).
count
()
==
1
:
self
.
_object
=
(
SubInterface
.
objects
.
filter
(
ipv4_addresses
=
ipv4
).
first
().
managed_object
)
else
:
if
ForwardingInstance
.
objects
.
filter
(
name
=
vrf
).
count
()
==
1
:
forw_inst
=
ForwardingInstance
.
objects
.
filter
(
name
=
vrf
).
first
()
if
(
SubInterface
.
objects
.
filter
(
ipv4_addresses
=
ipv4
,
forwarding_instance
=
forw_inst
).
count
()
==
1
):
self
.
_object
=
(
SubInterface
.
objects
.
filter
(
ipv4_addresses
=
ipv4
,
forwarding_instance
=
forw_inst
)
.
first
()
.
managed_object
)
@
property
def
object
(
self
):
...
...
inv/models/forwardinginstance.py
View file @
7f06861e
# ---------------------------------------------------------------------
# Forwarding Instance model
# ---------------------------------------------------------------------
# Copyright (C) 2007-202
0
The NOC Project
# Copyright (C) 2007-202
1
The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
...
...
@@ -28,7 +28,7 @@ class ForwardingInstance(Document):
"collection"
:
"noc.forwardinginstances"
,
"strict"
:
False
,
"auto_create_index"
:
False
,
"indexes"
:
[
"managed_object"
],
"indexes"
:
[
"managed_object"
,
"name"
],
}
managed_object
=
ForeignKeyField
(
ManagedObject
)
type
=
StringField
(
...
...
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