my $cmd = "ipmitool -H $mo->{Mgmt} -U $mo->{User} -P $mo->{Pass}";
- my $status = `$cmd power status`
- or die "Cannot retrieve current power status";
- chomp($status);
- logm("$status (want $onoff)");
- $status =~ s/^Chassis Power is (on|off)$/$1/
- or die "Cannot parse current power status: $status";
+ my $getstatus = sub {
+ my $status = `$cmd power status`
+ or die "Cannot retrieve current power status";
+ chomp($status);
+ logm("$status (want $onoff)");
+ $status =~ s/^Chassis Power is (on|off)$/$1/
+ or die "Cannot parse current power status: $status";
+ return $status;
+ };
- if ( $status eq $onoff ) {
+ if ( $getstatus->() eq $onoff ) {
logm("Current power status is correct");
return;
}
- system_checked("$cmd power $onoff")
+ system_checked("$cmd power $onoff");
+
+ my $count = 60;
+ for (;;) {
+ last if $getstatus->() eq $onoff;
+ die "did not power $onoff" unless --$count > 0;
+ sleep(1);
+ }
}
1;