Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2012
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.  
  35. # дёргаем vlan для каждого порта:
  36. switchports = {} # interface -> (untagged, tagged)
  37. for swp in self.scripts.get_switchport():
  38. switchports[swp["interface"]] = (
  39. swp["untagged"] if "untagged" in swp else None,
  40. swp["tagged"],
  41. swp["description"]
  42. )
  43.  
  44. v = "\n" + v
  45. # For each interface
  46. i = {"forwarding_instance": "default", "interfaces": [], "type": "ip"}
  47. for s in self.rx_line.split(v)[1:]:
  48. n = {}
  49. match = self.rx_name.search(s)
  50. if not match:
  51. continue
  52. n["name"] = match.group("name")
  53. match = self.rx_mac_local.search(s)
  54. if not match:
  55. continue
  56. n["mac"] = match.group("mac")
  57. match = self.rx_oper_status.search(s)
  58. if not match:
  59. continue
  60. n["oper_status"] = match.group("status")
  61. n["admin_status"] = match.group("status")
  62. n["description"] = switchports[match.group("name")][2],
  63. n["subinterfaces"] = [{
  64. "name": match.group("name"),
  65. "description": switchports[match.group("name")][2],
  66. "admin_status": match.group("status"),
  67. "oper_status": match.group("status"),
  68. "is_bridge": True,
  69. "mac": match.group("mac"),
  70. #"snmp_ifindex": self.scripts.get_ifindex(interface=name)
  71. }]
  72. }
  73.  
  74. if switchports[match.group("name")][1]:
  75. iface["subinterfaces"][0]["tagged_vlans"] = switchports[match.group("name")][1]
  76. if switchports[match.group("name")][0]:
  77. iface["subinterfaces"][0]["untagged_vlan"] = switchports[match.group("name")][0]
  78.  
  79. n["type"] = "physical"
  80. i["interfaces"] += [n]
  81. # iface = i["interfaces"]
  82. # print iface
  83. r += [n]
  84. return [{"interfaces": r}]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement