Example #1
0
def get_poe_port_mapping(snmp_proxy, host):
    if not host in POE_PORT_MAPPING_CACHE:
        if b"IF-MIB" not in get_loaded_mibs():
            load_mib(b"IF-MIB")
        iface_port_indexes = list(
                int(k) for k, v in snmp_proxy.ifSpeed.items()
                if v in POE_PORT_SPEEDS)
        iface_type_indexes = list(
                int(k) for k, v in snmp_proxy.ifType.items()
                if int(v) == ETHERNETCSMACD)
        poe_port_indexes = list(
                (int(grp_idx), int(grp_port)) \
                for grp_idx, grp_port in snmp_proxy.pethPsePortAdminEnable.keys())
        # check if we have the same number of poe ports and 10/100/1000 ports
        if len(iface_port_indexes) == len(poe_port_indexes):
            # this probably means we can associate iface_port_indexes and
            # poe_port_indexes one by one:
            iface_to_poe_index = { a: b for a, b in \
                    zip(iface_port_indexes, poe_port_indexes) }
        # otherwise, check if we have a linear range of ethernet ports
        # (i.e. there are no holes in those port indexes)
        elif max(a-b for a, b in \
                zip(iface_type_indexes[1:], iface_type_indexes[:-1])) == 1:
            # this probably means we can associate iface_type_indexes and
            # poe_port_indexes one by one:
            iface_to_poe_index = { a: b for a, b in \
                    zip(iface_type_indexes, poe_port_indexes) }
        else:
            raise RuntimeError(MSG_ISSUE_POE_PORT_MAPPING % host)
        POE_PORT_MAPPING_CACHE[host] = iface_to_poe_index
    return POE_PORT_MAPPING_CACHE[host]
Example #2
0
def get_poe_port_mapping(snmp_proxy, host):
    if not host in POE_PORT_MAPPING_CACHE:
        if "IF-MIB" not in get_loaded_mibs():
            load_mib("IF-MIB")
        iface_port_indexes = list(
                int(k) for k, v in snmp_proxy.ifSpeed.items()
                if v in POE_PORT_SPEEDS)
        iface_type_indexes = list(
                int(k) for k, v in snmp_proxy.ifType.items()
                if int(v) == ETHERNETCSMACD)
        poe_port_indexes = list(
                (int(grp_idx), int(grp_port)) \
                for grp_idx, grp_port in snmp_proxy.pethPsePortAdminEnable.keys())
        # check if we have the same number of poe ports and 10/100/1000 ports
        if len(iface_port_indexes) == len(poe_port_indexes):
            # this probably means we can associate iface_port_indexes and
            # poe_port_indexes one by one:
            iface_to_poe_index = { a: b for a, b in \
                    zip(iface_port_indexes, poe_port_indexes) }
        # otherwise, check if we have a linear range of ethernet ports
        # (i.e. there are no holes in those port indexes)
        elif max(a-b for a, b in \
                zip(iface_type_indexes[1:], iface_type_indexes[:-1])) == 1:
            # this probably means we can associate iface_type_indexes and
            # poe_port_indexes one by one:
            iface_to_poe_index = { a: b for a, b in \
                    zip(iface_type_indexes, poe_port_indexes) }
        else:
            raise RuntimeError(MSG_ISSUE_POE_PORT_MAPPING % host)
        POE_PORT_MAPPING_CACHE[host] = iface_to_poe_index
    return POE_PORT_MAPPING_CACHE[host]
Example #3
0
def detect_correct_mib(snmp_proxy, host):
    unload_any_of_these_mibs(CANDIDATE_POE_MIBS)
    for mib in CANDIDATE_POE_MIBS:
        load_mib(mib)
        try:
            dummy = snmp_proxy.pethPsePortAdminEnable.keys()
            break # ok previous line passed with no error
        except (snmp.SNMPNoSuchObject,
                snmp.SNMPNoSuchInstance,
                snmp.SNMPEndOfMibView):
            # issue with this MIB, try next one
            unload_mib(mib)
            mib = None
    if mib == None:
        raise RuntimeError(
            'Device %s does not seem to handle PoE SNMP requests.' % \
                        host)
    return mib
Example #4
0
 def __init__(self, snmp_proxy):
     self.snmp = snmp_proxy
     load_mib(b"NETGEAR-SWITCHING-MIB")
 def __init__(self, snmp_proxy):
     self.snmp = snmp_proxy
     load_mib("NETGEAR-SWITCHING-MIB")
Example #6
0
def ensure_correct_mib(correct_mib):
    if correct_mib not in get_loaded_mibs():
        unload_any_of_these_mibs(CANDIDATE_POE_MIBS)
        load_mib(correct_mib)
Example #7
0
 def __init__(self, snmp_proxy):
     load_mib("Q-BRIDGE-MIB")
     self.snmp = snmp_proxy
Example #8
0
 def load():
     load_mib(b"TPLINK-MIB")
     load_mib(b"TPLINK-LLDP-MIB")
     load_mib(b"TPLINK-LLDPINFO-MIB")
Example #9
0
 def load():
     load_mib(b"LLDP-MIB")
Example #10
0
 def load(cls):
     load_mib(b"NETGEAR-POWER-ETHERNET-MIB")
Example #11
0
 def load(cls):
     load_mib(b"POWER-ETHERNET-MIB")
Example #12
0
 def load(cls):
     load_mib(b"TPLINK-MIB")
     load_mib(b"TPLINK-POWER-OVER-ETHERNET-MIB")
Example #13
0
 def __init__(self, snmp_proxy):
     load_mib(b"Q-BRIDGE-MIB")
     self.snmp = snmp_proxy
Example #14
0
 def __init__(self, snmp_proxy):
     self.snmp = snmp_proxy
     load_mib("LLDP-MIB")