Esempio n. 1
0
    def _get_netif_or_derivative(self, hostname, netif):
        """
        Get netif or derivative names of hostname

        netif can be a macaddr, but to be conservative, it will only work if
        only one interface has this macaddr.
        """
        interfaces = self._get_interfaces_for_device(hostname)

        if netif in interfaces:
            return interfaces[netif]

        if is_macaddr(netif):
            mac_addresses = defaultdict(list)
            for i in interfaces:
                mac_addresses[macaddr_to_int(
                    interfaces[i].mac_address)].append(interfaces[i])

            int_netif_mac = macaddr_to_int(netif)
            if len(mac_addresses.get(int_netif_mac, 0)) == 1:
                return mac_addresses[int_netif_mac][0]
        else:
            for netif_deriv in self._get_all_derivatives_for_netif(netif):
                for k in interfaces:
                    for i in self._get_all_derivatives_for_netif(k):
                        if i == netif_deriv:
                            return interfaces[k]

        raise ValueError("Interface {} not found".format(netif))
Esempio n. 2
0
 def test_macaddr_to_int_is_Null(self):
     assert macaddr_to_int(None) == 0
Esempio n. 3
0
 def test_macaddr_to_int(self):
     assert macaddr_to_int('00:00:FF:00:00:FF') == 4278190335