Advertisement
Guest User

Untitled

a guest
Jul 18th, 2014
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. ##----------------------------------------------------------------------
  3. ## Force10.FTOS.get_mac_address_table
  4. ##----------------------------------------------------------------------
  5. ## Copyright (C) 2007-2009 The NOC Project
  6. ## See LICENSE for details
  7. ##----------------------------------------------------------------------
  8. """
  9. """
  10. import noc.sa.script
  11. from noc.sa.interfaces import IGetMACAddressTable
  12. import re
  13.  
  14. rx_line = re.compile(r"^\s*(?P<vlan_id>\d+)\s+(?P<mac>\S+)\s+(?P<type>\S+)\s+(?P<interfaces>\S+\s+\S+).*$")
  15.  
  16.  
  17. class Script(noc.sa.script.Script):
  18. name = "Force10.FTOS.get_mac_address_table"
  19. implements = [IGetMACAddressTable]
  20.  
  21. def execute(self, interface=None, vlan=None, mac=None):
  22. cmd = "show mac-address-table"
  23. if mac is not None:
  24. cmd += " address %s" % self.profile.convert_mac(mac)
  25. if interface is not None:
  26. cmd += " interface %s" % interface
  27. if vlan is not None:
  28. cmd += " vlan %s" % vlan
  29. vlans = self.cli(cmd)
  30. r = []
  31. for l in vlans.split("\n"):
  32. match = rx_line.match(l.strip())
  33. if match:
  34. try:
  35. r.append({
  36. "vlan_id": match.group("vlan_id"),
  37. "mac": match.group("mac"),
  38. "interfaces": [match.group("interfaces")],
  39. "type": {"Dynamic": "D"}[match.group("type")],
  40. })
  41. except KeyError:
  42. continue
  43. return r
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement