Guest User

Untitled

a guest
Dec 8th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. ##----------------------------------------------------------------------
  3. ## Vendor: D-Link
  4. ## OS: DxS
  5. ## Compatible:
  6. ##----------------------------------------------------------------------
  7. ## Copyright (C) 2007-2011 The NOC Project
  8. ## See LICENSE for details
  9. ##----------------------------------------------------------------------
  10. """
  11. """
  12. import re
  13. import noc.sa.profiles
  14. from noc.sa.protocols.sae_pb2 import TELNET,SSH
  15.  
  16. class Profile(noc.sa.profiles.Profile):
  17. name="DLink.DxS"
  18. supported_schemes=[TELNET,SSH]
  19. pattern_username="([Uu]ser ?[Nn]ame|[Ll]ogin):"
  20. pattern_password="[Pp]ass[Ww]ord:"
  21. pattern_more="CTRL\+C.+?a All"
  22. pattern_unpriveleged_prompt=r"^\S+:(3|6|user|operator)#"
  23. pattern_syntax_error=r"(Available commands|Next possible completions|Ambiguous token):"
  24. command_super="enable admin"
  25. pattern_prompt=r"^(?P<hostname>\S+(:\S+)*)#"
  26. command_disable_pager="disable clipaging"
  27. command_more="a"
  28. command_exit="logout"
  29. command_save_config="save"
  30. config_volatile=["^%.*?$"]
  31. ##
  32. ## Version comparison
  33. ## Version format:
  34. ## <major>.<minor><sep><patch>
  35. ##
  36. rx_ver=re.compile(r"\d+")
  37. def cmp_version(self, x, y):
  38. return cmp([int(z) for z in self.rx_ver.findall(x)], [int(z) for z in self.rx_ver.findall(y)])
  39.  
  40. cluster_member = None
  41. dlink_pager = False
  42. rx_pager=re.compile(r"^(Clipaging|CLI Paging)\s+:\s*(?P<cp>Enabled|Disabled)\s*$", re.MULTILINE)
  43. def setup_session(self, script):
  44. # Cache "show switch" command and fetch CLI Paging from it
  45. match = self.rx_pager.search(script.cli("show switch", cached=True))
  46. if match:
  47. self.dlink_pager = (match.group("cp") == "Enabled")
  48.  
  49. # Parse path parameters
  50. for p in script.access_profile.path.split("/"):
  51. if p.startswith("cluster:"):
  52. self.cluster_member=p[8:].strip()
  53. # Switch to cluster member, if necessary
  54. if self.cluster_member:
  55. script.debug("Switching to SIM member '%s'"%script.cluster_member)
  56. script.cli("reconfig member_id %s"%script.cluster_member)
  57.  
  58. def shutdown_session(self, script):
  59. if self.cluster_member:
  60. script.cli("reconfig exit")
  61. if self.dlink_pager:
  62. script.cli("enable clipaging")
  63. else:
  64. script.cli("disable clipaging")
  65.  
  66. ## DES-3200-series
  67. def DES3200(v):
  68. return v["platform"].startswith("DES-3200")
  69.  
  70. ## DGS-3100-series
  71. def DGS3100(v):
  72. return v["platform"].startswith("DGS-3100")
  73.  
  74. ## DGS-3120-series
  75. def DGS3120(v):
  76. return v["platform"].startswith("DGS-3120")
  77.  
  78. ## DGS-3400-series
  79. def DGS3400(v):
  80. return v["platform"].startswith("DGS-34")
  81.  
  82. ## DGS-3600-series
  83. def DGS3600(v):
  84. return "DGS-3610" not in v["platform"] and v["platform"].startswith("DGS-36")
Add Comment
Please, Sign In to add comment