I wrapped Perl Net :: SSH :: Expect with a small module to reduce the template code needed to write a new script configuration for use our HP iLO cards . Although, on the one hand, I want this wrapper to be as thin as possible, so colleagues who are not programmers can use it, I also want it to be written as well as possible.
Used like this:
my $ilo = iLO->new(host => $host, password => $password);
$ilo->login;
$ilo->command("cd /system1");
$ilo->command("set oemhp_server_name=$system_name", 'status=0');
and this iLO::command():
sub command {
my ($self, $cmd, $response) = @_;
$response = 'hpiLO-> ' unless defined($response);
croak "Not logged in!\n" unless ($self->{ssh});
$self->{ssh}->send($cmd);
if ($self->{ssh}->waitfor($response, $self->{CMD_TIMEOUT}, '-re')) {
return {
before => $self->{ssh}->before(),
match => $self->{ssh}->match(),
after => $self->{ssh}->after(),
};
} else {
carp "ERROR: '$cmd' response did not match /$response/:\n\n",
$self->{ssh}->before()),
"\n";
return undef;
}
}
. -, , ? , , , - undef, - , croak() ( ). . Perl , , , // , (, 5.8). , - (iLO::response - ), $ilo->before() ( Net:: SSH:: Expect before())? - $ilo->command , - .
-, ? , , Net:: SSH:: Expect, , "". Perl, : , . ?