Commit 2adb3832 authored by Dmitry Volodin's avatar Dmitry Volodin Committed by Andrey Vertiprahov
Browse files

Merge branch 'patch-avs-ignorecase-hostname' into 'master'

#1820 Add hostname_id to DiscoveryID model

See merge request !5084

(cherry picked from commit 640cc7a1)

a02e0772 Discovery.get_neighbor_by_hostname ignore when find hostname.
6e7ce0f8 Add hostname_raw.
50b94f12 Fix typo.
parent 70b2dcdd
Pipeline #36638 passed with stages
in 13 minutes and 35 seconds
......@@ -49,11 +49,12 @@ class DiscoveryID(Document):
"collection": "noc.inv.discovery_id",
"strict": False,
"auto_create_index": False,
"indexes": ["object", "hostname", "udld_id", "macs"],
"indexes": ["object", "hostname", "hostname_id", "udld_id", "macs"],
}
object = ForeignKeyField(ManagedObject)
chassis_mac = ListField(EmbeddedDocumentField(MACRange))
hostname = StringField()
hostname_id = StringField()
router_id = StringField()
udld_id = StringField() # UDLD local identifier
#
......@@ -115,6 +116,7 @@ class DiscoveryID(Document):
old_macs = set(m.first_mac for m in o.chassis_mac)
o.chassis_mac = ranges
o.hostname = hostname
o.hostname_id = hostname.lower()
o.router_id = router_id
old_macs -= set(m.first_mac for m in o.chassis_mac)
if old_macs:
......@@ -124,7 +126,12 @@ class DiscoveryID(Document):
o.save()
else:
cls(
object=object, chassis_mac=ranges, hostname=hostname, router_id=router_id, macs=macs
object=object,
chassis_mac=ranges,
hostname=hostname,
hostname_id=hostname.lower(),
router_id=router_id,
macs=macs,
).save()
@classmethod
......
......@@ -1001,8 +1001,9 @@ class TopologyDiscoveryCheck(DiscoveryCheck):
"""
Resolve neighbor by hostname
"""
hostname = hostname.lower()
if hostname not in self.neighbor_hostname_cache:
hosts = DiscoveryID.objects.filter(hostname=hostname)[:2]
hosts = DiscoveryID.objects.filter(hostname_id=hostname)[:2]
n = None
if len(hosts) == 1:
n = hosts[0].object
......@@ -1011,7 +1012,7 @@ class TopologyDiscoveryCheck(DiscoveryCheck):
# Try to resolve anyway
m = list(
DiscoveryID.objects.filter(
hostname__istartswith=hostname + "." if "." not in hostname else hostname
hostname_id__istartswith=hostname + "." if "." not in hostname else hostname
)
)
if len(m) == 1:
......
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