Commit 893a390d authored by Andrey Vertiprahov's avatar Andrey Vertiprahov
Browse files

Merge branch 'ds_chassis' into 'master'

Add ability to filter subinterface by VRF

See merge request noc/noc!5459
parents 3e978a3d 7f06861e
# ---------------------------------------------------------------------
# Inventory module datasources
# ---------------------------------------------------------------------
# Copyright (C) 2007-2019 The NOC Project
# Copyright (C) 2007-2021 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):
......
# ---------------------------------------------------------------------
# Forwarding Instance model
# ---------------------------------------------------------------------
# Copyright (C) 2007-2020 The NOC Project
# Copyright (C) 2007-2021 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(
......
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