ec064a50bd1e9d045af67cf31a17612e869e0e09
[pcucontrol.git] / pcucontrol / models / exp / HPiLO.exp
1 #!/usr/bin/expect
2
3 set timeout 60
4 set method [lindex $argv 0]
5 set host [lindex $argv 1]
6 set user [lindex $argv 2]
7 set password [lindex $argv 3]
8 set dryrun [lindex $argv 4]
9 set model [lindex $argv 5]
10
11 log_user 0
12
13 if { "$method" == "https" } {
14     if { "$dryrun" == "True" } {
15         set file $path/iloxml/Get_Network.xml
16     } else {
17         #set file $path/iloxml/Reset_Server.xml
18         set file $path/iloxml/Get_Network.xml
19     }
20     spawn "$path/locfg.pl" -s $host -u $user -p '$password' -f $file
21 } elseif { "$method" == "ssh" } {
22     if { "$dryrun" == "True" } {
23         set reset_cmd "POWER\r"
24         set reset_msg "Test: No error"
25     } else {
26         #set reset_cmd "reset\r"
27         set reset_cmd "POWER\r"
28         set reset_msg "Reset: No error"
29     }
30     spawn ssh $user@$host
31 } elseif { "$method" == "proxy" } {
32     set url "http://www.cs.princeton.edu/~soltesz/pcuProxy.php"
33     set query "username=$user&password=$password&hostname=$host&model=$model&dryrun=$dryrun"
34     spawn curl -s "$url?$query"
35 }
36
37 if { "$method" == "proxy" || "$method" == "https" }  {
38     # Check for any one of the following patterns, then print it and stop.
39     expect {
40         "MESSAGE='Server being reset.'" { send_user "Reset: No error" }
41         "MESSAGE='Host power is already ON.'" { send_user "$expect_out(0,string)"}
42         "MESSAGE='Host power is already OFF.'" { send_user "$expect_out(0,string)"}
43         "MESSAGE='Login credentials rejected.'" { send_user "$expect_out(0,string)"}
44         "<GET_NETWORK_SETTINGS>" { send_user "Test: No error"}
45         -re "ERROR:.*" { send_user "$expect_out(0,string)" }
46         eof { send_user "Reached EOF without status report: $expect_out(buffer)" }
47     }
48 } elseif { "$method" == "ssh" } {
49
50     expect {
51         "Are you sure you want to continue connecting (yes/no)? " { send "yes\n" ; exp_continue }
52         "password: " { send "$password\n" ; exp_continue }
53         "Permission denied" { send_user "HPiLO username/password: $expect_out(0,string)"; exit }
54         "Could not resolve hostname" { send_user "HPiLO hostname: $expect_out(0,string)"; exit }
55         "</>hpiLO-> " { send "cd system1\r" }
56     }
57
58     expect "</system1>hpiLO-> " { send $reset_cmd }
59     expect "</system1>hpiLO-> " { send "exit\r" }
60     expect eof { send_user $reset_msg }
61
62 }