Exemple #1
0
 def get_neighbor_by_ip(self, ip):
     """
     Resolve neighbor by hostname
     """
     if ip not in self.neighbor_ip_cache:
         mo = DiscoveryID.find_object(ipv4_address=ip)
         self.neighbor_ip_cache[ip] = mo
     return self.neighbor_ip_cache[ip]
Exemple #2
0
 def get_neighbor_by_mac(self, mac):
     """
     Resolve neighbor by hostname
     """
     if mac not in self.neighbor_mac_cache:
         mo = DiscoveryID.find_object(mac=mac)
         self.neighbor_mac_cache[mac] = mo
     return self.neighbor_mac_cache[mac]
Exemple #3
0
def test_id_macs(discovery_object):
    xmacs = get_by_path(discovery_object, "checks.id.macs")
    if not xmacs:
        pytest.skip("macs are not expected")
    d = DiscoveryID.objects.filter(object=discovery_object.id).first()
    assert d
    for expected in xmacs:
        first = expected["first"]
        last = expected["last"]
        m = [x for x in d.chassis_mac if x.first_mac == first and x.last_mac == last]
        assert m
        mo = DiscoveryID.find_object(mac=first)
        assert mo
        assert mo.id == discovery_object.id
        mo = DiscoveryID.find_object(mac=last)
        assert mo
        assert mo.id == discovery_object.id
Exemple #4
0
 def __init__(self, mac=None, ipv4=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
Exemple #5
0
 def get_stp_status(object_id):
     roots = set()
     blocked = set()
     object = ManagedObject.get_by_id(object_id)
     sr = object.scripts.get_spanning_tree()
     for instance in sr["instances"]:
         ro = DiscoveryID.find_object(instance["root_id"])
         if ro:
             roots.add(ro)
         for i in instance["interfaces"]:
             if i["state"] == "discarding" and i["role"] == "alternate":
                 iface = object.get_interface(i["interface"])
                 if iface:
                     link = iface.link
                     if link:
                         blocked.add(str(link.id))
     return object_id, roots, blocked
Exemple #6
0
 def get_neighbor_by_mac(self, mac):
     """
     Find neighbor by MAC address
     :param mac:
     :return:
     """
     # Use cached values
     o = self.neighbor_by_mac_cache.get(mac)
     if not o:
         # Find in discovery cache
         o = DiscoveryID.find_object(mac=mac)
         if not o:
             # Fallback to interface's MAC
             mos = set(i.managed_object
                       for i in Interface.objects.filter(mac=mac))
             if len(mos) == 1:
                 o = mos.pop()
         self.neighbor_by_mac_cache[mac] = o
     return o