Advertisement
Guest User

Untitled

a guest
Sep 18th, 2013
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.23 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. ##----------------------------------------------------------------------
  3. ## Alcatel.7324RU.get_interfaces
  4. ##----------------------------------------------------------------------
  5. ## Copyright (C) 2007-2013 The NOC Project
  6. ## See LICENSE for details
  7. ##----------------------------------------------------------------------
  8. """
  9. """
  10. import re
  11. ## NOC modules
  12. from noc.sa.script import Script as NOCScript
  13. from noc.sa.interfaces import IGetInterfaces
  14. from noc.lib.text import *
  15. from collections import defaultdict
  16.  
  17.  
  18. class Script(NOCScript):
  19. name = "Alcatel.7324RU.get_interfaces"
  20. implements = [IGetInterfaces]
  21. rx_vlan = re.compile(r"[ ]*(?P<vid>\d+)[ ]*(?P<vname>[A-Za-z0-9\-\.]+)\n([ 0-9]+)\n[ ]+(?P<vstatus>enabled|disabled)[ 0-9]+\n([ \-xnf]+)\n[ ]+(?P<portmask>[\-tu]+)[ ]*(?P<uplinkmask>[\-tu]*)", re.MULTILINE | re.IGNORECASE)
  22. rx_mac = re.compile(r"MAC\saddress:\s(?P<mac>[0-9a-z:]*)\s*", re.IGNORECASE)
  23.  
  24. def execute(self):
  25. # ADSL ports
  26. phy_ports = self.cli("adsl show")
  27. oper_ports = self.cli("statistics adsl show")
  28. sub_ports = self.cli("adsl pvc show")
  29. vlans = self.cli("switch vlan show *")
  30. phy_ports = phy_ports.split("Subscriber Info:")
  31. i = []
  32. for phy in parse_table(phy_ports[0]):
  33. admin_status = False
  34. if phy[1] == "V":
  35. admin_status = True
  36. oper_status = False
  37. if parse_table(oper_ports)[int(phy[0])-1][1] == "V":
  38. oper_status = True
  39. description = ''
  40. if parse_table(phy_ports[1])[int(phy[0])-1][1] != "-":
  41. description = parse_table(phy_ports[1])[int(phy[0])-1][1] + " " + parse_table(phy_ports[1])[int(phy[0])-1][2]
  42. sub = []
  43. for s in parse_table(sub_ports):
  44. if s[0] == phy[0]:
  45. sub += [{
  46. "name": s[0],
  47. "admin_status": True,
  48. "oper_status": True,
  49. "enabled_afi": ["ATM", "BRIDGE"],
  50. "untagged_vlan": s[3],
  51. "vpi": s[1],
  52. "vci": s[2]
  53. }]
  54. i += [{
  55. "name": phy[0],
  56. "type": "physical",
  57. "admin_status": admin_status,
  58. "oper_status": oper_status,
  59. "description": description,
  60. "subinterfaces": sub
  61. }]
  62. # Enet ports info
  63. sys_mac = self.cli("sys info show")
  64. enet_ports = self.cli("statistics enet")
  65. tagged = defaultdict(list)
  66. mac = re.findall(self.rx_mac, sys_mac)[0]
  67. for match in re.finditer(self.rx_vlan, vlans):
  68. up = 0
  69. if match.group("vstatus")=="enabled":
  70. for x in match.group("uplinkmask"):
  71. up += 1
  72. if x=="T":
  73. tagged[up]+=[match.group("vid")]
  74. for y in range(up):
  75. oper_status = True
  76. admin_status = True
  77. if parse_table(enet_ports)[y][1] == "disabled":
  78. admin_status = False
  79. oper_status = False
  80. elif parse_table(enet_ports)[y][1] == "link down":
  81. oper_status = False
  82. i+= [{
  83. "name": "enet%d" % (y+1),
  84. "type": "physical",
  85. "admin_status": admin_status,
  86. "oper_status": oper_status,
  87. "mac": mac,
  88. "subinterfaces": [{
  89. "admin_status": admin_status,
  90. "enabled_afi": ["BRIDGE"],
  91. "oper_status": oper_status,
  92. "name": "enet%d" % (y+1),
  93. "mac": mac,
  94. "tagged_vlans": tagged[y+1]
  95. }]
  96. }]
  97. r = [{"forwarding instance" : "default",
  98. "interfaces": i
  99. }]
  100. return r
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement