from pcucontrol.reboot import *
+import subprocess
class APCControl(PCUControl):
supported_ports = [22,23,80,443]
cmd = cmd % ( self.username, self.password, self.host)
print "CMD: %s" % cmd
- p = os.popen(cmd)
+ p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).stdout
+
result = p.read()
if len(result.split('\n')) > 2:
self.logout()
raise ExceptionNoTransport("Unsupported transport to get version")
cmd = cmd % ( self.username, self.password, self.host)
- p = os.popen(cmd)
+ p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).stdout
result = p.read()
return result.strip()
raise ExceptionNoTransport("Unsupported transport to logout")
cmd = cmd % ( self.username, self.password, self.host)
- p = os.popen(cmd)
+ p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).stdout
print p.read()
class APCControl12p3(APCControl):
class DRAC(BasicPCUControl):
supported_ports = [22,443,5869]
def run_drac(self, node_port, dryrun):
- return self.run_expect_script("DRAC.exp racadm5", dryrun=dryrun, model="None")
+ return self.run_expect_script("DRAC.exp racadm", dryrun=dryrun, model="None")
def run_ssh(self, node_port, dryrun):
return self.run_expect_script("DRAC.exp ssh", dryrun=dryrun, model="None")
- def pcu_run(self, node_port):
+ def pcu_run(self, node_port, dryrun=False):
r = self.run_ssh(node_port, dryrun=False)
if "No error" in r:
return r
return r2
return r + " :: " +r2
- def pcu_test(self, node_port):
+ def pcu_test(self, node_port, dryrun=True):
r = self.run_ssh(node_port, dryrun=True)
if "No error" in r:
return r
else:
raise ExceptionNoTransport("Unimplemented Transport for HPiLO %s" % self.type)
- def pcu_run(self, node_port):
+ def pcu_run(self, node_port, dryrun=False):
r = self.run_https(node_port, dryrun=False)
if "No error" in r:
return r
return r2
return r + " :: " +r2
- def pcu_test(self, node_port):
+ def pcu_test(self, node_port, dryrun=True):
r = self.run_https(node_port, dryrun=True)
if "No error" in r:
return r
from pcucontrol.reboot import *
+import subprocess
class OpenIPMI(PCUControl):
supported_ports = [80,443,623]
# TODO: get exit codes to determine success or failure...
+ def run_http(self, node_port, dryrun):
+ return self.run_ipmi(node_port, dryrun)
+ def run_https(self, node_port, dryrun):
+ return self.run_ipmi(node_port, dryrun)
+
def run_ipmi(self, node_port, dryrun):
if not dryrun:
- cmd = "ipmitool -I lanplus -H %s -U %s -P '%s' power cycle "
- (i,p) = os.popen4(cmd % ( self.host, self.username, self.password) )
- result = p.read()
- print "RESULT: ", result
+ ipmi_cmd = "power cycle"
else:
- cmd = "ipmitool -I lanplus -H %s -U %s -P '%s' user list "
- (i,p) = os.popen4(cmd % ( self.host, self.username, self.password) )
- result = p.read()
- print "RESULT: ", result
+ ipmi_cmd = "user list"
+
+ cmd = "ipmitool -I lanplus -H %s -U %s -P '%s' %s"
+ cmd = cmd % ( self.host, self.username, self.password, ipmi_cmd )
+ p = subprocess.Popen(cmd, shell=True,
+ stdin=subprocess.PIPE, stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT, close_fds=True)
+ (i,p) = (p.stdin, p.stdout)
+ result = p.read()
+ #print "RESULT: ", result
if "Error" in result:
return result
#!/usr/bin/expect
-set timeout 20
+set timeout 60
set method [lindex $argv 0]
set host [lindex $argv 1]
set user [lindex $argv 2]
if { "$method" == "ssh" } {
- send_user "spawn ssh -o StrictHostKeyChecking=no -o PasswordAuthentication=yes -o PubkeyAuthentication=no $user@$host\n"
+ #send_user "spawn ssh -o StrictHostKeyChecking=no -o PasswordAuthentication=yes -o PubkeyAuthentication=no $user@$host\n"
set cont 0
for { set retry 0 } { $retry < 2 } { incr retry 1 } {
# NOTE: For unknown reason, some DRAC modules work only with
# stderr redirected to stdout, others only work without it.
if { $retry == 0 } {
- spawn ssh -o StrictHostKeyChecking=no -o PasswordAuthentication=yes -o PubkeyAuthentication=no $user@$host 2>&1
- } else {
spawn ssh -o StrictHostKeyChecking=no -o PasswordAuthentication=yes -o PubkeyAuthentication=no $user@$host
+ } else {
+ spawn ssh -o StrictHostKeyChecking=no -o PasswordAuthentication=yes -o PubkeyAuthentication=no $user@$host 2>&1
}
expect {
"password: " { send "$password\n" ; exp_continue }
"Permission denied" { send_user "DRAC ssh: username/password: $expect_out(0,string)"; exit }
"Could not resolve hostname" { send_user "DRAC ssh: $expect_out(0,string)"; exit }
+ "Connection timed out" { send_user "DRAC ssh: $expect_out(0,string)"; exit }
-re "Received disconnect.*" { send_user "DRAC ssh: $expect_out(0,string)"; exit}
-re "\\$|/.*>|\[$user\]#" { send "\r"; }
- eof { set cont 1 }
+ timeout { send_user "DRAC ssh: timeout" ; exit; }
+ eof { if { $cont == 1 } { send_user "DRAC ssh failed twice"; exit ; } ; set cont 1 }
}
if { $cont == 0 } { break; }
} else {
set rac_cmd "serveraction powercycle"
}
- send_user "/opt/dell/srvadmin/bin/$method -r $host -u $user -p '$password' $rac_cmd\n";
+ #send_user "/opt/dell/srvadmin/bin/$method -r $host -u $user -p '$password' $rac_cmd\n";
set cont 0
for { set retry 0 } { $retry < 2 } { incr retry 1 } {
# NOTE: For unknown reason, some DRAC modules work only with
# stderr redirected to stdout, others only work without it.
if { $retry == 0 } {
- set x [ spawn /opt/dell/srvadmin/bin/$method -i -r $host $rac_cmd 2>&1 ]
+ set x [ spawn /opt/dell/srvadmin/rac5/bin/$method -i -r $host $rac_cmd 2>&1 ]
} else {
- set x [ spawn /opt/dell/srvadmin/bin/$method -i -r $host $rac_cmd ]
+ set x [ spawn /opt/dell/srvadmin/rac5/bin/$method -i -r $host $rac_cmd ]
}
expect {
-re "ERROR:.*" { send_user "DRAC: $expect_out(0,string)"; exit }
-re "UserName:|username:" { send "$user\r" ; exp_continue };
-re "Password:|password:" { send "$password\r" };
+ timeout { send_user "DRAC: timeout" ; exit }
+ eof { send_user "DRAC: early EOF"; exit ; }
}
expect {
-re "Authentication failed.*" { send_user "DRAC: $expect_out(0,string)"; exit }
-re "This.*not support remote RACADM" { send_user "DRAC: $expect_out(0,string)" ; exit }
-re "ERROR: The syntax of the command specified is not correct." { set cont 1 }
+ -re "INVALID ARGUMENT" { send_user "DRAC: received 'INVALID ARGUMENT'"; exit }
-re "RAC Information:" { sleep .1; }
+ timeout { send_user "DRAC: timeout" ; exit }
+ eof { send_user "DRAC: early EOF"; exit ; }
#-re "ERROR:.*" { send_user "DRAC: $expect_out(0,string)"; exit }
}
if { $cont == 0 } { break; }
expect {
-re "Power Status.*" { sleep .1; }
-re "RAC Firmware.*" { sleep .1; }
+ eof { send_user "DRAC: early EOF"; exit ; }
}
expect eof { send_user "$reset_msg\n" }
}
log_user 0
+set path [ file dirname [ file dirname $argv0 ] ]
+
if { "$method" == "https" } {
if { "$dryrun" == "True" } {
- set file $path/iloxml/Get_Network.xml
+ set file $path/hpilo/iloxml/Get_Network.xml
} else {
- #set file $path/iloxml/Reset_Server.xml
- set file $path/iloxml/Get_Network.xml
+ set file $path/hpilo/iloxml/Reset_Server.xml
+ #set file $path/hpilo/iloxml/Get_Network.xml
}
- spawn "$path/locfg.pl" -s $host -u $user -p '$password' -f $file
+ spawn "$path/hpilo/locfg.pl" -s $host -u $user -p $password -f $file
} elseif { "$method" == "ssh" } {
if { "$dryrun" == "True" } {
set reset_cmd "POWER\r"
set reset_msg "Test: No error"
} else {
- #set reset_cmd "reset\r"
- set reset_cmd "POWER\r"
+ #set reset_cmd "POWER\r"
+ set reset_cmd "reset\r"
set reset_msg "Reset: No error"
}
spawn ssh $user@$host
"MESSAGE='Host power is already ON.'" { send_user "$expect_out(0,string)"}
"MESSAGE='Host power is already OFF.'" { send_user "$expect_out(0,string)"}
"MESSAGE='Login credentials rejected.'" { send_user "$expect_out(0,string)"}
+ "MESSAGE='User login name was not found'" { send_user "$expect_out(0,string)"}
"<GET_NETWORK_SETTINGS>" { send_user "Test: No error"}
-re "ERROR:.*" { send_user "$expect_out(0,string)" }
eof { send_user "Reached EOF without status report: $expect_out(buffer)" }
"password: " { send "$password\n" ; exp_continue }
"Permission denied" { send_user "HPiLO username/password: $expect_out(0,string)"; exit }
"Could not resolve hostname" { send_user "HPiLO hostname: $expect_out(0,string)"; exit }
+ "Connection timed out" { send_user "HPiLO ssh timeout: $expect_out(0,string)"; exit }
"</>hpiLO-> " { send "cd system1\r" }
+ eof { send_user "HPiLO early EOF\n"; exit }
}
expect "</system1>hpiLO-> " { send $reset_cmd }
raise Exception("No such Node ID: %d" % node_id)
- def catcherror(self, function, node_port):
+ def catcherror(self, function, node_port, dryrun):
try:
- return function(node_port)
+ return function(node_port, dryrun)
except ExceptionNotFound, err:
return "Not found: " + str(err)
except ExceptionPassword, err:
cmd = cmd_str + "%s %s %s '%s' %s %s " % (
scriptname, self.host, self.username,
self.password, args['dryrun'], args['model'])
+ print cmd
cmd_out, cmd_err = locfg.run_noexcept(cmd)
return cmd_out.strip() + cmd_err.strip()
print "found function %s in model %s" % (looking_for_fxn, self.model)
reboot_fxn = getattr(self, looking_for_fxn)
- ret = self.catcherror(reboot_fxn, node_port)
+ ret = self.catcherror(reboot_fxn, node_port, dryrun)
return ret
<?php
+$DEBUG=FALSE;
function logit($string){
+ global $DEBUG;
+ if ( $DEBUG )
+ {
$f = fopen("output.log", 'a');
fwrite($f, $string);
fclose($f);
+ }
}
function run_hp_script($script, $host, $username, $password)
echo system("which ipmitool 2>&1");
} else
{
- echo "what do you want me to do with this?";
+ echo "Unrecognized pcu type: $model";
}
} else {