Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def turn_on(self):
- host_ip = '10.44.143.26'
- user = 'apc'
- passwd = 'apc'
- try:
- tn = telnetlib.Telnet(host_ip)
- tn.read_until(b"User Name :", 10)
- tn.write(b"{}\r\n".format(user))
- tn.read_until(b"Password :", 10)
- tn.write(b"{}\r\n".format(passwd))
- tn.read_until(b"> ", 10)
- tn.write(b"1\r\n")
- tn.read_until(b"> ", 10)
- tn.write(b"2\r\n")
- tn.read_until(b"> ", 10)
- tn.write(b"1\r\n")
- tn.read_until(b"> ", 10)
- except:
- return "Can't estabilish connection to PDU via telnet!"
- i = 1
- 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]:
- if checkbox.isChecked():
- tn.write(b"{}\r\n".format(i))
- tn.read_until(b"> ", 10)
- tn.write(b"1\r\n")
- tn.read_until(b"> ", 10)
- tn.write(b"1\r\n")
- tn.read_until(b"> to cancel :", 10)
- tn.write(b"yes\r\n")
- tn.read_until(b"Press <ENTER> to continue...", 10)
- tn.write(b"\r\n")
- tn.read_until(b"> ", 10)
- tn.write(b"\x1B")
- tn.read_until(b"> ", 10)
- tn.write(b"\x1B")
- i += 1
- tn.close()
- status_dict = self.get_status_from_PDU('apc', 'apc', '10.44.143.26')
- self.set_status_info(status_dict)
- def turn_off(self):
- host_ip = '10.44.143.26'
- user = 'apc'
- passwd = 'apc'
- try:
- tn = telnetlib.Telnet(host_ip)
- tn.read_until(b"User Name :", 10)
- tn.write(b"{}\r\n".format(user))
- tn.read_until(b"Password :", 10)
- tn.write(b"{}\r\n".format(passwd))
- tn.read_until(b"> ", 10)
- tn.write(b"1\r\n")
- tn.read_until(b"> ", 10)
- tn.write(b"2\r\n")
- tn.read_until(b"> ", 10)
- tn.write(b"1\r\n")
- tn.read_until(b"> ", 10)
- except:
- pass
- i = 1
- 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]:
- if checkbox.isChecked():
- tn.write(b"{}\r\n".format(i))
- tn.read_until(b"> ", 10)
- tn.write(b"1\r\n")
- tn.read_until(b"> ", 10)
- tn.write(b"2\r\n")
- tn.read_until(b"> to cancel :", 10)
- tn.write(b"yes\r\n")
- tn.read_until(b"Press <ENTER> to continue...", 10)
- tn.write(b"\r\n")
- tn.read_until(b"> ", 10)
- tn.write(b"\x1B")
- tn.read_until(b"> ", 10)
- tn.write(b"\x1B")
- i += 1
- tn.close()
- status_dict = self.get_status_from_PDU('apc', 'apc', '10.44.143.26')
- self.set_status_info(status_dict)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement