Net-ILO

 view release on metacpan or  search on metacpan

lib/Net/ILO.pm  view on Meta::CPAN

package Net::ILO;

use strict;
use warnings;

use Carp;
use Data::Dumper;
use English qw(-no_match_vars);
use IO::Socket::SSL;
use XML::Simple;

our $VERSION = '0.54';


my $METHOD_UNSUPPORTED = 'Method not supported by this iLO version';


sub address {

    my $self = shift;

    if (@_) {
        $self->{address} = shift;
    }

    return $self->{address};

}


sub add_user {

    my $self = shift;

    if (@_) {

        my $arg_ref = shift;

        my $user_name     = $arg_ref->{name}     or croak 'name required';
        my $user_login    = $arg_ref->{username} or croak 'username required';
        my $user_password = $arg_ref->{password} or croak 'password required';

        my $user_admin          = $arg_ref->{admin}                    || 'No';
        my $user_can_remote     = $arg_ref->{remote_console_privilege} || 'No';
        my $user_can_reset      = $arg_ref->{reset_privilege}          || 'No';
        my $user_can_virtual    = $arg_ref->{virtual_media_privilege}  || 'No';
        my $user_can_config     = $arg_ref->{config_ilo_privilege}     || 'No';
        my $user_can_view_logs  = $arg_ref->{view_logs_privilege}      || 'No';
        my $user_can_clear_logs = $arg_ref->{clear_logs_privilege}     || 'No';
        my $user_can_update     = $arg_ref->{update_ilo_privilege}     || 'No';

        my $ilo_command = qq|
            <USER_INFO MODE="write">
            <ADD_USER USER_NAME="$user_name" USER_LOGIN="$user_login" PASSWORD="$user_password">
            <ADMIN_PRIV value="$user_admin"/>
            <REMOTE_CONS_PRIV value="$user_can_remote"/>
            <RESET_SERVER_PRIV value="$user_can_reset"/>
            <VIRTUAL_MEDIA_PRIV value="$user_can_virtual"/>
            <CONFIG_ILO_PRIV value="$user_can_config"/>
            <VIEW_LOGS_PRIV value="$user_can_view_logs"/>
            <CLEAR_LOGS_PRIV value="$user_can_clear_logs"/>
            <UPDATE_ILO_PRIV value="$user_can_update"/>
            </ADD_USER>
            </USER_INFO>
        |;

        $ilo_command    = $self->_wrap($ilo_command);
        my $response    = $self->_send($ilo_command)    or return;
        my $xml         = $self->_serialize($response)  or return;

lib/Net/ILO.pm  view on Meta::CPAN

    }

    my $ilo_command = $self->_generate_cmd('uid_status');

    my $response    = $self->_send($ilo_command)    or return;
    my $xml         = $self->_serialize($response)  or return;

    if ( my $errmsg = _check_errors($xml) ) {
        $self->error($errmsg);
        return;
    }

    my $uid_status = $xml->{GET_UID_STATUS}->{UID};

    return lc($uid_status);

}


sub username {

    my $self = shift;

    if (@_) {
        $self->{username} = shift;
    }

    return $self->{username};

}


sub _check_errors {

    my $xml = shift;

    my $errcode = $xml->{RESPONSE}->{STATUS};
    my $errmsg  = $xml->{RESPONSE}->{MESSAGE};

    if ($errcode ne '0x0000') {
        return $errmsg;
    }
    else {
        return;
    }

}


sub _connect {

    my $self = shift;

    if ($self->{_client}) {
        return $self->{_client};
    }

    my $address = $self->address or croak "Can't connect: address not set";
    my $port    = $self->port    or croak "Can't connect: port not set";

    $self->{_client} = IO::Socket::SSL->new(
        PeerAddr => "$address:$port",
    );

    if (!$self->{_client}) {
        $self->error( "Unable to establish SSL connection with $address:$port [" . IO::Socket::SSL::errstr() . "]" );
        return;
    }

    return $self->{_client};

}


sub _debug {

    my $self = shift;

    if (@_) {
        $self->{_debug} = shift;
    }

    return $self->{_debug};

}


sub _detect_version {

    my $self = shift;

    # iLO 3 has a slightly different interface; it requires that
    # you preface commands with an HTTP header

    my $ilo_command = qq(
        POST /ribcl HTTP/1.1
        HOST: localhost
        Content-length: 30
        Connection: Close

        <RIBCL VERSION="2.0"></RIBCL>
    );

    my $response = $self->_send($ilo_command) or return;

    if ($response =~ /^HTTP\/1.1 200 OK/) {
        return 3;
    }
    else {
        return 2;
    }

}


sub _disconnect {

    my $self = shift;

    my $client = $self->{_client} or return;

    $client->close;

    delete $self->{_client};

    return 1;

lib/Net/ILO.pm  view on Meta::CPAN


    # you're fired!
    $ilo->del_user('jbeam');

Removes an existing user from the iLO.

=back

=head2 MISCELLANEOUS

=over

=item uid()

    if ($ilo->uid eq 'on') {

        $ilo->uid('off');

    }

Get the status of or control the machine's UID light.

Called without parameters simply returns the current status, either
'on' or 'off'.

You may pass values 'on' or 'off' to this method however be careful not to
set the uid light to on when it is currently on, and vice versa, as this
could throw an error, depending on iLO firmware version.

An error will be returned if you pass an invalid state.

    $ilo->uid('blinking') or die $ilo->error;

    State blinking is not valid at /somescript.pl line 13.

=back

=head1 DIAGNOSTICS

=over

=item C<User login name was not found>

General authentication error, eg. bad username or password when logging in.

Could also mean you attempted to change the settings (eg. password) for a
user which doesn't exist

=item C<Method not supported by this iLO version>

Either your machine / iLO firmware version is too old, or the method you called
requires a more advanced license than you have.

=item C<State %s is not valid>

An invalid UID state was passed to uid(). Valid states are 'on' and 'off'.

=item C<Unable to establish SSL connection with %s:%d [%s]>

An error occurred while connecting to iLO. The message in brackets is
propagated from IO::Socket::SSL, and is rarely useful.

=item C<Error transmitting command to server>

A connection was established, but something went wrong while sending the
command to the remote iLO. Try reconnecting, and ensure that your
network settings are correct.

=item C<No response received from remote machine>

A connection was established and a command successfully sent to the iLO, but
no data was received. Again, ensure that your network settings are correct.

There could also be something wrong with the remote iLO management processor.
Troubleshooting is beyond the scope of this document.

=item C<Error parsing response: %s>

An error occurred while parsing the XML response from the iLO. The error
message is propagated from XML::Simple, and could mean HP changed the iLO
API.

=back

=head1 DEPENDENCIES

    IO::Socket::SSL
    XML::Simple

=head1 AUTHOR

Nicholas Lewis, C<< <nick.lewis at gmail.com> >>

=head1 BUGS

Please report any bugs or feature requests to C<bug-net-ilo at rt.cpan.org>, or through
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-ILO>.  I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.


=head1 SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Net::ILO


You can also look for information at:

=over 4

=item * RT: CPAN's request tracker

L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-ILO>

=item * AnnoCPAN: Annotated CPAN documentation

L<http://annocpan.org/dist/Net-ILO>

=item * CPAN Ratings

L<http://cpanratings.perl.org/d/Net-ILO>

=item * Search CPAN

L<http://search.cpan.org/dist/Net-ILO>

=back


=head1 COPYRIGHT & LICENSE

Copyright 2011 Nicholas Lewis, all rights reserved.

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.


=cut



( run in 0.904 second using v1.01-cache-2.11-cpan-39bf76dae61 )