Commit 5980caba authored by Andrey Vertiprahov's avatar Andrey Vertiprahov
Browse files

Merge branch 'cherry-pick-640cc7a1' into 'release-22.1'

release-22.1:Backport!5084

See merge request !6407
parents eaf89850 ccabcc3c
...@@ -49,11 +49,12 @@ class DiscoveryID(Document): ...@@ -49,11 +49,12 @@ class DiscoveryID(Document):
"collection": "noc.inv.discovery_id", "collection": "noc.inv.discovery_id",
"strict": False, "strict": False,
"auto_create_index": False, "auto_create_index": False,
"indexes": ["object", "hostname", "udld_id", "macs"], "indexes": ["object", "hostname", "hostname_id", "udld_id", "macs"],
} }
object = ForeignKeyField(ManagedObject) object = ForeignKeyField(ManagedObject)
chassis_mac = ListField(EmbeddedDocumentField(MACRange)) chassis_mac = ListField(EmbeddedDocumentField(MACRange))
hostname = StringField() hostname = StringField()
hostname_id = StringField()
router_id = StringField() router_id = StringField()
udld_id = StringField() # UDLD local identifier udld_id = StringField() # UDLD local identifier
# #
...@@ -115,6 +116,7 @@ class DiscoveryID(Document): ...@@ -115,6 +116,7 @@ class DiscoveryID(Document):
old_macs = set(m.first_mac for m in o.chassis_mac) old_macs = set(m.first_mac for m in o.chassis_mac)
o.chassis_mac = ranges o.chassis_mac = ranges
o.hostname = hostname o.hostname = hostname
o.hostname_id = hostname.lower()
o.router_id = router_id o.router_id = router_id
old_macs -= set(m.first_mac for m in o.chassis_mac) old_macs -= set(m.first_mac for m in o.chassis_mac)
if old_macs: if old_macs:
...@@ -124,7 +126,12 @@ class DiscoveryID(Document): ...@@ -124,7 +126,12 @@ class DiscoveryID(Document):
o.save() o.save()
else: else:
cls( 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() ).save()
@classmethod @classmethod
......
...@@ -1001,8 +1001,9 @@ class TopologyDiscoveryCheck(DiscoveryCheck): ...@@ -1001,8 +1001,9 @@ class TopologyDiscoveryCheck(DiscoveryCheck):
""" """
Resolve neighbor by hostname Resolve neighbor by hostname
""" """
hostname = hostname.lower()
if hostname not in self.neighbor_hostname_cache: 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 n = None
if len(hosts) == 1: if len(hosts) == 1:
n = hosts[0].object n = hosts[0].object
...@@ -1011,7 +1012,7 @@ class TopologyDiscoveryCheck(DiscoveryCheck): ...@@ -1011,7 +1012,7 @@ class TopologyDiscoveryCheck(DiscoveryCheck):
# Try to resolve anyway # Try to resolve anyway
m = list( m = list(
DiscoveryID.objects.filter( 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: 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