# Path: wiremaps/collector/icollector.py
# class ICollector(Interface):
#     """Interface for a collector for a given equipment"""
# 
#     def handleEquipment(oid):
#         """Does this instance handle the given equipment
# 
#         @param oid: OID identifying the kind of equipment
#         @return: C{True} if the equipment is handled
#         """
# 
#     def collectData(equipment, proxy):
#         """Collect data from the equipment
# 
#         @param equipment: equipment to complete with data
#         @param proxy: proxy to query the equipment with SNMP
# 
#         @return: an object implementing IEquipment interface and
#             containing all information for the given equipment.
#         """
# 
# Path: wiremaps/collector/datastore.py
# class Port:
#     implements(IPort)
# 
#     def __init__(self, name, state,
#                  alias=None, mac=None, speed=None, duplex=None, autoneg=None):
#         self.name = ascii(name)
#         self.state = state
#         self.alias = ascii(alias)
#         self.mac = mac
#         self.speed = speed
#         self.duplex = duplex
#         self.autoneg = autoneg
#         self.fdb = []
#         self.sonmp = None
#         self.edp = None
#         self.cdp = None
#         self.lldp = None
#         self.vlan = []
#         self.trunk = None
# 
# class Trunk:
#     implements(ITrunk)
# 
#     def __init__(self, parent):
#         self.parent = parent
# 
# class LocalVlan(Vlan):
#     implements(ILocalVlan)
# 
# Path: wiremaps/collector/helpers/arp.py
# class ArpCollector:
#     """Collect data using ARP"""
# 
#     ipNetToMediaPhysAddress = '.1.3.6.1.2.1.4.22.1.2'
# 
#     def __init__(self, equipment, proxy, config):
#         """Create a collector using ARP entries in SNMP.
# 
#         @param proxy: proxy to use to query SNMP
#         @param equipment: equipment to complete with ARP entries
#         @param config: configuration
#         """
#         self.proxy = proxy
#         self.equipment = equipment
#         self.config = config
# 
#     def gotArp(self, results):
#         """Callback handling reception of ARP
# 
#         @param results: result of walking C{IP-MIB::ipNetToMediaPhysAddress}
#         """
#         for oid in results:
#             ip = ".".join([m for m in oid.split(".")[-4:]])
#             mac = ":".join("%02x" % ord(m) for m in results[oid])
#             self.equipment.arp[ip] = mac
# 
#     def collectData(self):
#         """Collect data from SNMP using ipNetToMediaPhysAddress.
#         """
#         print "Collecting ARP for %s" % self.proxy.ip
#         d = self.proxy.walk(self.ipNetToMediaPhysAddress)
#         d.addCallback(self.gotArp)
#         return d


from zope.interface import implements
from twisted.plugin import IPlugin
from twisted.internet import defer
from wiremaps.collector.icollector import ICollector
from wiremaps.collector.datastore import Port, Trunk, LocalVlan
from wiremaps.collector.helpers.arp import ArpCollector
            self.association[kind].append((string1, string2))


    def completeEquipment(self):
        # Interfaces
        names = {}
        status = {}
        mac = {}
        speed = {}
        duplex = {}
        interfaces = []
        for p in self.data["status"]:
            interfaces.append([x.isdigit() and int(x) or x for x in p.split(".")])
        interfaces.sort()
        interfaces = [".".join([str(y) for y in x]) for x in interfaces]
        for p in self.data["status"]:
            index = interfaces.index(p) + 1
            self.equipment.ports[index] = \
                Port(p,
                     self.data["status"][p] == 0 and 'up' or 'down',
                     mac=(self.data["mac"].get(p, None) and \
                              ":".join([("%02x" % ord(m))
                                        for m in self.data["mac"][p]])),
                     speed=self.data["speed"].get(p, None),
                     duplex={0: None,
                             1: 'half',
                             2: 'full'}[self.data["duplex"].get(p, 0)])
        for trunk, port in self.association["trunk"]:
            if port not in interfaces: continue
            self.equipment.ports[interfaces.index(port) + 1].trunk = \

# Path: wiremaps/collector/icollector.py
# class ICollector(Interface):
#     """Interface for a collector for a given equipment"""
# 
#     def handleEquipment(oid):
#         """Does this instance handle the given equipment
# 
#         @param oid: OID identifying the kind of equipment
#         @return: C{True} if the equipment is handled
#         """
# 
#     def collectData(equipment, proxy):
#         """Collect data from the equipment
# 
#         @param equipment: equipment to complete with data
#         @param proxy: proxy to query the equipment with SNMP
# 
#         @return: an object implementing IEquipment interface and
#             containing all information for the given equipment.
#         """
# 
# Path: wiremaps/collector/datastore.py
# class Port:
#     implements(IPort)
# 
#     def __init__(self, name, state,
#                  alias=None, mac=None, speed=None, duplex=None, autoneg=None):
#         self.name = ascii(name)
#         self.state = state
#         self.alias = ascii(alias)
#         self.mac = mac
#         self.speed = speed
#         self.duplex = duplex
#         self.autoneg = autoneg
#         self.fdb = []
#         self.sonmp = None
#         self.edp = None
#         self.cdp = None
#         self.lldp = None
#         self.vlan = []
#         self.trunk = None
# 
# class Trunk:
#     implements(ITrunk)
# 
#     def __init__(self, parent):
#         self.parent = parent
# 
# class LocalVlan(Vlan):
#     implements(ILocalVlan)
# 
# Path: wiremaps/collector/helpers/arp.py
# class ArpCollector:
#     """Collect data using ARP"""
# 
#     ipNetToMediaPhysAddress = '.1.3.6.1.2.1.4.22.1.2'
# 
#     def __init__(self, equipment, proxy, config):
#         """Create a collector using ARP entries in SNMP.
# 
#         @param proxy: proxy to use to query SNMP
#         @param equipment: equipment to complete with ARP entries
#         @param config: configuration
#         """
#         self.proxy = proxy
#         self.equipment = equipment
#         self.config = config
# 
#     def gotArp(self, results):
#         """Callback handling reception of ARP
# 
#         @param results: result of walking C{IP-MIB::ipNetToMediaPhysAddress}
#         """
#         for oid in results:
#             ip = ".".join([m for m in oid.split(".")[-4:]])
#             mac = ":".join("%02x" % ord(m) for m in results[oid])
#             self.equipment.arp[ip] = mac
# 
#     def collectData(self):
#         """Collect data from SNMP using ipNetToMediaPhysAddress.
#         """
#         print "Collecting ARP for %s" % self.proxy.ip
#         d = self.proxy.walk(self.ipNetToMediaPhysAddress)
#         d.addCallback(self.gotArp)
#         return d


# Path: wiremaps/collector/equipment/f5.py
from zope.interface import implements
from twisted.plugin import IPlugin
from twisted.internet import defer
from wiremaps.collector.icollector import ICollector
from wiremaps.collector.datastore import Port, Trunk, LocalVlan
from wiremaps.collector.helpers.arp import ArpCollector

            self.association[kind].append((string1, string2))


    def completeEquipment(self):
        # Interfaces
        names = {}
        status = {}
        mac = {}
        speed = {}
        duplex = {}
        interfaces = []
        for p in self.data["status"]:
            interfaces.append([x.isdigit() and int(x) or x for x in p.split(".")])
        interfaces.sort()
        interfaces = [".".join([str(y) for y in x]) for x in interfaces]
        for p in self.data["status"]:
            index = interfaces.index(p) + 1
            self.equipment.ports[index] = \
                Port(p,
                     self.data["status"][p] == 0 and 'up' or 'down',
                     mac=(self.data["mac"].get(p, None) and \
                              ":".join([("%02x" % ord(m))
                                        for m in self.data["mac"][p]])),
                     speed=self.data["speed"].get(p, None),
                     duplex={0: None,
                             1: 'half',
                             2: 'full'}[self.data["duplex"].get(p, 0)])
        for trunk, port in self.association["trunk"]:
            if port not in interfaces: continue
            self.equipment.ports[interfaces.index(port) + 1].trunk = \

                Trunk(interfaces.index(trunk) + 1)