Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2012
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. ##----------------------------------------------------------------------
  3. ## Alcatel.AOS.get_interfaces
  4. ##----------------------------------------------------------------------
  5. ## Copyright (C) 2007-2011 The NOC Project
  6. ## See LICENSE for details
  7. ##----------------------------------------------------------------------
  8. """
  9. """
  10. # Python modules
  11. import re
  12. from collections import defaultdict
  13. # NOC modules
  14. from noc.sa.script import Script as NOCScript
  15. from noc.sa.interfaces import IGetInterfaces, InterfaceTypeError
  16. #from noc.sa.profiles.Cisco.IOS import uBR
  17.  
  18.  
  19. class Script(NOCScript):
  20. name = "Alcatel.AOS.get_interfaces"
  21. implements = [IGetInterfaces]
  22.  
  23. rx_line = re.compile(r"\w*Slot/Port", re.MULTILINE)
  24. rx_name = re.compile(r"\s+(?P<name>.\S+)\s+:", re.MULTILINE)
  25. rx_mac_local = re.compile(r"\s+MAC address\s+: (?P<mac>.+),", re.MULTILINE | re.IGNORECASE)
  26. rx_oper_status = re.compile(r"\s+Operational Status\s+: (?P<status>.+),", re.MULTILINE | re.IGNORECASE)
  27.  
  28. def execute(self):
  29. r = []
  30. try:
  31. v = self.cli("show interfaces")
  32. except self.CLISyntaxError:
  33. raise self.NotSupportedError()
  34. v = "\n" + v
  35. # For each interface
  36. i = {"forwarding_instance": "default", "interfaces": [], "type": "ip"}
  37. for s in self.rx_line.split(v)[1:]:
  38. n = {}
  39. match = self.rx_name.search(s)
  40. if not match:
  41. continue
  42. n["name"] = match.group("name")
  43. match = self.rx_mac_local.search(s)
  44. if not match:
  45. continue
  46. n["mac"] = match.group("mac")
  47. match = self.rx_oper_status.search(s)
  48. if not match:
  49. continue
  50. n["oper_status"] = match.group("status")
  51. n["admin_status"] = match.group("status")
  52. n["subinterfaces"] = []
  53. n["type"] = "physical"
  54. i["interfaces"] += [n]
  55. # iface = i["interfaces"]
  56. # print iface
  57. r += [n]
  58. return r
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement