Add expect version of APC controller
[pcucontrol.git] / pcucontrol / models / exp / DRAC.exp
old mode 100644 (file)
new mode 100755 (executable)
index b3b1990..57b5e46
@@ -37,8 +37,8 @@ if { "$method" == "ssh" } {
             "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"; } 
-            timeout { send_user "DRAC ssh: timeout" ; exit; }
-            eof { if { $cont == 1 } { send_user "DRAC ssh failed twice"; exit ; } ; set cont 1 }
+            timeout { send_user "DRAC ssh: timeout\n" ; exit; }
+            eof { if { $cont == 1 } { send_user "DRAC ssh failed twice\n"; exit ; } ; set cont 1 }
         }
         if { $cont == 0 } { break; }
 
@@ -62,9 +62,11 @@ if { "$method" == "ssh" } {
 } else { 
     if { [string match "*racadm*" $method] } {
         if { "$dryrun" == "True" } {
-            set rac_cmd "getsysinfo"
+            set rac_cmd_a "getsysinfo"
+            set rac_cmd_b ""
         } else {
-            set rac_cmd "serveraction powercycle"
+            set rac_cmd_a "serveraction"
+            set rac_cmd_b "powercycle"
         }
         #send_user "/opt/dell/srvadmin/bin/$method -r $host -u $user -p '$password' $rac_cmd\n";
         set cont 0
@@ -74,28 +76,39 @@ if { "$method" == "ssh" } {
             #       on the cmdline causes racadm to fail.
             # NOTE: For unknown reason, some DRAC modules work only with
             #       stderr redirected to stdout, others only work without it.
+            # NOTE: For unknown reason, the racadm cmd does not recognize "serveraction powercycle" 
+            #       but does recognize "serveraction" "powercycle"
             if { $retry == 0 } {
-                set x [ spawn /opt/dell/srvadmin/rac5/bin/$method -i -r $host $rac_cmd 2>&1 ]
+               if { "$rac_cmd_a" == "getsysinfo" } {
+                   set x [ spawn /opt/dell/srvadmin/rac5/bin/$method -i -r $host $rac_cmd_a ]
+               } else {
+                   set x [ spawn /opt/dell/srvadmin/rac5/bin/$method -i -r $host $rac_cmd_a $rac_cmd_b  ]
+               }
             } else {
-                set x [ spawn /opt/dell/srvadmin/rac5/bin/$method -i -r $host $rac_cmd  ]
+               if { "$rac_cmd_a" == "getsysinfo" } {
+                   set x [ spawn /opt/dell/srvadmin/rac5/bin/$method -i -r $host $rac_cmd_a 2>&1 ]
+               } else {
+                   set x [ spawn /opt/dell/srvadmin/rac5/bin/$method -i -r $host $rac_cmd_a $rac_cmd_b 2>&1 ]
+               }
             }
 
             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 ; }
+                timeout { send_user "DRAC: timeout\n" ; exit }
+                eof { send_user "DRAC: early EOF\n"; 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 "ERROR: the command that was entered is not valid" { set cont 1 }
+                -re "INVALID ARGUMENT" { send_user "DRAC: received 'INVALID ARGUMENT'\n"; exit }
                 -re "RAC Information:" { sleep .1; }
-                timeout { send_user "DRAC: timeout" ; exit }
-                eof { send_user "DRAC: early EOF"; exit ; }
+                timeout { send_user "DRAC: timeout\n" ; exit }
+                eof { send_user "$reset_msg\n"; exit ; }
                 #-re "ERROR:.*" { send_user "DRAC: $expect_out(0,string)"; exit }
             }
             if { $cont == 0 } { break; }
@@ -105,7 +118,7 @@ if { "$method" == "ssh" } {
         expect {
             -re "Power Status.*" { sleep .1; } 
             -re "RAC Firmware.*" { sleep .1; }
-            eof { send_user "DRAC: early EOF"; exit ; }
+            eof { send_user "DRAC: early EOF\n"; exit ; }
         } 
         expect eof { send_user "$reset_msg\n" }
     }