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 # Inventory module datasources
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# Copyright (C) 2007-2019 The NOC Project # Copyright (C) 2007-2021 The NOC Project
# See LICENSE for details # See LICENSE for details
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
...@@ -10,6 +10,7 @@ from noc.lib.datasource import DataSource ...@@ -10,6 +10,7 @@ from noc.lib.datasource import DataSource
from noc.inv.models.interface import Interface from noc.inv.models.interface import Interface
from noc.inv.models.discoveryid import DiscoveryID from noc.inv.models.discoveryid import DiscoveryID
from noc.inv.models.subinterface import SubInterface from noc.inv.models.subinterface import SubInterface
from noc.inv.models.forwardinginstance import ForwardingInstance
from noc.sa.interfaces.base import MACAddressParameter from noc.sa.interfaces.base import MACAddressParameter
...@@ -60,17 +61,33 @@ class InterfaceDS(DataSource): ...@@ -60,17 +61,33 @@ class InterfaceDS(DataSource):
class ChassisDS(DataSource): class ChassisDS(DataSource):
_name = "inv.ChassisDS" _name = "inv.ChassisDS"
def __init__(self, mac=None, ipv4=None): def __init__(self, mac=None, ipv4=None, vrf=None):
super().__init__()
self._object = None self._object = None
if mac: if mac:
mac = MACAddressParameter.clean(mac) mac = MACAddressParameter.clean(mac)
self._object = DiscoveryID.find_object(mac) self._object = DiscoveryID.find_object(mac)
if ipv4: if ipv4:
if SubInterface.objects.filter(ipv4_addresses=ipv4).count() == 1: if vrf is None or vrf == "default":
self._object = ( if SubInterface.objects.filter(ipv4_addresses=ipv4).count() == 1:
SubInterface.objects.filter(ipv4_addresses=ipv4).first().managed_object 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 @property
def object(self): def object(self):
......
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# Forwarding Instance model # Forwarding Instance model
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# Copyright (C) 2007-2020 The NOC Project # Copyright (C) 2007-2021 The NOC Project
# See LICENSE for details # See LICENSE for details
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
...@@ -28,7 +28,7 @@ class ForwardingInstance(Document): ...@@ -28,7 +28,7 @@ class ForwardingInstance(Document):
"collection": "noc.forwardinginstances", "collection": "noc.forwardinginstances",
"strict": False, "strict": False,
"auto_create_index": False, "auto_create_index": False,
"indexes": ["managed_object"], "indexes": ["managed_object", "name"],
} }
managed_object = ForeignKeyField(ManagedObject) managed_object = ForeignKeyField(ManagedObject)
type = StringField( 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