def get_ifindex_ip_mac_mappings(self): """Retrieve the IPv6->MAC address mappings of this device. Return value: A set of tuples: set([(ifindex, ip_address, mac_address), ...]) ifindex will be an integer, ip_address will be an IPy.IP object and mac_address will be a string with a colon-separated hex representation of a MAC address. """ column = 'ipv6NetToMediaPhysAddress' waiter = defer.waitForDeferred(self.retrieve_column(column)) yield waiter ipv6_phys_addrs = waiter.getResult() mappings = set() for row_index, phys_address in ipv6_phys_addrs.items(): ifindex = row_index[0] ipv6_address = row_index[1:] ip = Ipv6Mib.ipv6address_to_ip(ipv6_address) mac = binary_mac_to_hex(phys_address) row = (ifindex, ip, mac) mappings.add(row) self._logger.debug("ip/mac pairs: Got %d rows from %s", len(ipv6_phys_addrs), column) yield mappings
def _save_bridge_address(self, bridge_address): info = self.containers.factory( (INFO_KEY_BRIDGE_INFO, INFO_VAR_BASE_ADDRESS), shadows.NetboxInfo) info.value = binary_mac_to_hex(bridge_address) info.netbox = self.netbox info.key = INFO_KEY_BRIDGE_INFO info.variable = INFO_VAR_BASE_ADDRESS
def __new__(cls, *args, **kwargs): arg = args[0] if isinstance(arg, basestring): arg = binary_mac_to_hex(arg) elif isinstance(arg, cls): return arg return IdType.__new__(cls, arg)
def __new__(cls, *args, **_kwargs): arg = args[0] if isinstance(arg, six.string_types): arg = binary_mac_to_hex(arg) elif isinstance(arg, cls): return arg return IdType.__new__(cls, arg)
def _convert_row_to_container(self, netbox, ifindex, row): """Convert a collected ifTable/ifXTable row into a container object.""" interface = self.containers.factory(ifindex, shadows.Interface) interface.ifindex = ifindex interface.ifdescr = row['ifDescr'] interface.iftype = row['ifType'] # ifSpeed spec says to use ifHighSpeed if the 32-bit unsigned # integer is maxed out if row['ifSpeed'] is not None and row['ifSpeed'] < 4294967295: interface.speed = row['ifSpeed'] / 1000000.0 elif row['ifHighSpeed'] is not None: interface.speed = float(row['ifHighSpeed']) interface.ifphysaddress = binary_mac_to_hex(row['ifPhysAddress']) interface.ifadminstatus = row['ifAdminStatus'] interface.ifoperstatus = row['ifOperStatus'] interface.ifname = row['ifName'] or interface.baseport or row['ifDescr'] interface.ifconnectorpresent = row['ifConnectorPresent'] == 1 interface.ifalias = safestring(row['ifAlias']) # Set duplex if sucessfully retrieved if 'duplex' in row and row['duplex'] in DUPLEX_MAP: interface.duplex = DUPLEX_MAP[row['duplex']] interface.gone_since = None interface.netbox = netbox return interface
def typesafe_binary_mac_to_hex(octets): """Converts binary mac addresses to hexadecimal representations for database storage. However, some devices return the wrong data types, so this method will return None if the given value cannot be converted to a Mac Address without a TypeError being raised. """ try: return binary_mac_to_hex(octets) except TypeError: return None
def _binary_mac_to_hex(mac): "Converts a binary MAC address representation to a hexstring" return binary_mac_to_hex(mac)
def test_binary_mac_too_long_should_return_last_part(self): binary_mac = 'x123456' mac = '31:32:33:34:35:36' converted_mac = binary_mac_to_hex(binary_mac) self.assertEquals(converted_mac, mac)
def test_binary_mac_too_short(self): binary_mac = '23456' mac = '00:32:33:34:35:36' converted_mac = binary_mac_to_hex(binary_mac) self.assertEquals(converted_mac, mac)
def test_binary_mac_to_hex(self): # Make a simple "binary" mac binary_mac = '123456' mac = '31:32:33:34:35:36' converted_mac = binary_mac_to_hex(binary_mac) self.assertEqual(converted_mac, mac)