def _chop_index(cls, index, entry): """ Chops a prefix OID off an index OID, based on a table entry object. If the index is prefixed by the entry object itself, or by any of its descendants (columnar objects) in the MIB, that prefix is chopped off and the suffix is returned. Non-matches will return the index unchanged. :param index: An OID object or equivalent tuple :param entry: The name of an object in this MIB, preferable a table entry object. :returns: An OID hobject. """ index = OID(index) root = cls.nodes.get(entry, None) if not root or not root.oid.is_a_prefix_of(index): return index children = (c.oid for c in six.itervalues(cls.nodes) if root.oid.is_a_prefix_of(c.oid)) matched_prefixes = [c for c in children if c.is_a_prefix_of(index) ] + [root.oid] if matched_prefixes: index = index.strip_prefix(matched_prefixes[0]) return index
def address_index_to_ip(cls, index): """Convert a row index from cIpAddressTable to an IP object.""" entry = cls.nodes['cIpAddressPfxOrigin'] index = OID(index) if entry.oid.is_a_prefix_of(index): # Chop off the entry OID+column prefix index = OID(index.strip_prefix(entry.oid)[1:]) return super(CiscoIetfIpMib, cls).address_index_to_ip(index)
def address_index_to_ip(cls, index): """Convert a row index from ipAddressTable to an IP object.""" index = OID(index) if 'ipAddressEntry' in cls.nodes: entry = cls.nodes['ipAddressEntry'] if entry.oid.is_a_prefix_of(index): # Chop off the entry OID+column prefix index = OID(index.strip_prefix(entry.oid)[1:]) ip = cls.inetaddress_to_ip(index) return ip
def prefix_index_to_ip(cls, index, prefix_entry='ipAddressPrefixEntry'): """Convert a row index from ipAddressPrefixTable to an IP object.""" index = OID(index) if prefix_entry in cls.nodes: entry = cls.nodes[prefix_entry] if entry.oid.is_a_prefix_of(index): # Chop off the entry OID+column prefix index = OID(index.strip_prefix(entry.oid)[1:]) if len(index) < 4: cls._logger.debug("prefix_index_to_ip: index too short: %r", index) return None ifindex = index[0] addr_oid = index[1:-1] prefix_length = index[-1] ip = cls.inetaddress_to_ip(addr_oid) if ip: prefix = ip.make_net(prefix_length) return prefix