Advertisement
Guest User

Untitled

a guest
Jun 30th, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. def turn_on(self):
  2. host_ip = '10.44.143.26'
  3. user = 'apc'
  4. passwd = 'apc'
  5. try:
  6. tn = telnetlib.Telnet(host_ip)
  7. tn.read_until(b"User Name :", 10)
  8. tn.write(b"{}\r\n".format(user))
  9. tn.read_until(b"Password :", 10)
  10. tn.write(b"{}\r\n".format(passwd))
  11. tn.read_until(b"> ", 10)
  12. tn.write(b"1\r\n")
  13. tn.read_until(b"> ", 10)
  14. tn.write(b"2\r\n")
  15. tn.read_until(b"> ", 10)
  16. tn.write(b"1\r\n")
  17. tn.read_until(b"> ", 10)
  18. except:
  19. return "Can't estabilish connection to PDU via telnet!"
  20. i = 1
  21. for checkbox in [self.a_chbox, self.b_chbox, self.c_chbox, self.d_chbox, self.e_chbox, self.f_chbox, self.g_chbox, self.h_chbox]:
  22. if checkbox.isChecked():
  23. tn.write(b"{}\r\n".format(i))
  24. tn.read_until(b"> ", 10)
  25. tn.write(b"1\r\n")
  26. tn.read_until(b"> ", 10)
  27. tn.write(b"1\r\n")
  28. tn.read_until(b"> to cancel :", 10)
  29. tn.write(b"yes\r\n")
  30. tn.read_until(b"Press <ENTER> to continue...", 10)
  31. tn.write(b"\r\n")
  32. tn.read_until(b"> ", 10)
  33. tn.write(b"\x1B")
  34. tn.read_until(b"> ", 10)
  35. tn.write(b"\x1B")
  36. i += 1
  37. tn.close()
  38. status_dict = self.get_status_from_PDU('apc', 'apc', '10.44.143.26')
  39. self.set_status_info(status_dict)
  40.  
  41. def turn_off(self):
  42. host_ip = '10.44.143.26'
  43. user = 'apc'
  44. passwd = 'apc'
  45. try:
  46. tn = telnetlib.Telnet(host_ip)
  47. tn.read_until(b"User Name :", 10)
  48. tn.write(b"{}\r\n".format(user))
  49. tn.read_until(b"Password :", 10)
  50. tn.write(b"{}\r\n".format(passwd))
  51. tn.read_until(b"> ", 10)
  52. tn.write(b"1\r\n")
  53. tn.read_until(b"> ", 10)
  54. tn.write(b"2\r\n")
  55. tn.read_until(b"> ", 10)
  56. tn.write(b"1\r\n")
  57. tn.read_until(b"> ", 10)
  58. except:
  59. pass
  60. i = 1
  61. for checkbox in [self.a_chbox, self.b_chbox, self.c_chbox, self.d_chbox, self.e_chbox, self.f_chbox, self.g_chbox, self.h_chbox]:
  62. if checkbox.isChecked():
  63. tn.write(b"{}\r\n".format(i))
  64. tn.read_until(b"> ", 10)
  65. tn.write(b"1\r\n")
  66. tn.read_until(b"> ", 10)
  67. tn.write(b"2\r\n")
  68. tn.read_until(b"> to cancel :", 10)
  69. tn.write(b"yes\r\n")
  70. tn.read_until(b"Press <ENTER> to continue...", 10)
  71. tn.write(b"\r\n")
  72. tn.read_until(b"> ", 10)
  73. tn.write(b"\x1B")
  74. tn.read_until(b"> ", 10)
  75. tn.write(b"\x1B")
  76. i += 1
  77. tn.close()
  78. status_dict = self.get_status_from_PDU('apc', 'apc', '10.44.143.26')
  79. self.set_status_info(status_dict)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement