3 # Reboot specified nodes
9 import errno, time, traceback
12 import threading, popen2
15 from subprocess import PIPE, Popen
16 import pcucontrol.transports.ssh.pxssh as pxssh
17 import pcucontrol.transports.ssh.pexpect as pexpect
20 # Use our versions of telnetlib and pyssh
21 sys.path.insert(0, os.path.dirname(sys.argv[0]))
22 import pcucontrol.transports.telnetlib as telnetlib
23 sys.path.insert(0, os.path.dirname(sys.argv[0]) + "/pyssh")
24 import pcucontrol.transports.pyssh as pyssh
26 from monitor import config
27 from monitor.wrapper import plc
29 from pcucontrol.util import command
30 from pcucontrol.reboot import pcu_name, model_to_object, reboot_api, convert_oldmodelname_to_newmodelname, reboot_test_new
33 # Event class ID from pcu events
34 #NODE_POWER_CONTROL = 3
37 #MONITOR_USER_ID = 11142
40 logger = logging.getLogger("monitor")
44 def get_pcu_values(pcu_id):
45 from monitor.database.info.model import FindbadPCURecord
46 print "pcuid: %s" % pcu_id
48 pcurec = FindbadPCURecord.get_latest_by(plc_pcuid=pcu_id)
50 values = pcurec.to_dict()
59 return reboot_policy(nodename, True, False)
61 def reboot_str(nodename):
66 pcu = plc.getpcu(nodename)
68 logger.debug("no pcu for %s" % nodename)
69 print "no pcu for %s" % nodename
70 return "%s has no pcu" % nodename
72 values = get_pcu_values(pcu['pcu_id'])
74 logger.debug("No values for pcu probe %s" % nodename)
75 print "No values for pcu probe %s" % nodename
76 return "no info for pcu_id %s" % pcu['pcu_id']
79 logger.debug("Trying PCU %s %s" % (pcu['hostname'], pcu['model']))
81 ret = reboot_test_new(nodename, values, verbose, dryrun)
84 def reboot_policy(nodename, continue_probe, dryrun):
87 pcu = plc.getpcu(nodename)
89 logger.debug("no pcu for %s" % nodename)
90 print "no pcu for %s" % nodename
91 return False # "%s has no pcu" % nodename
93 values = get_pcu_values(pcu['pcu_id'])
95 logger.debug("No values for pcu probe %s" % nodename)
96 print "No values for pcu probe %s" % nodename
97 return False #"no info for pcu_id %s" % pcu['pcu_id']
100 logger.debug("Trying PCU %s %s" % (pcu['hostname'], pcu['model']))
102 ret = reboot_test_new(nodename, values, verbose, dryrun)
111 if __name__ == "__main__":
112 print "ERROR: Can not execute module as a command! Please use commands/%s.py" % os.path.splitext(__file__)[0]