diff options
-rw-r--r-- | INF.pm | 6 | ||||
-rw-r--r-- | INF/ASRock.pm | 70 | ||||
-rw-r--r-- | INF/ILO4.pm (renamed from INF/ILO.pm) | 2 | ||||
-rw-r--r-- | INF/ILO5.pm | 2 | ||||
-rw-r--r-- | INF/SuperMicro.pm | 5 | ||||
-rw-r--r-- | Makefile | 2 |
6 files changed, 40 insertions, 47 deletions
@@ -2,7 +2,7 @@ package INF; use INF::APC; use INF::DSRx020; use INF::ILO2; -use INF::ILO; #ilo 4 confusingly +use INF::ILO4; use INF::ILO5; use INF::SuperMicro; use INF::ASRock; @@ -45,10 +45,10 @@ sub new ($;$) { return INF::ILO2->new($inf); } elsif ( $inf->{inf_type} eq 'ilo' ) { - return INF::ILO->new($inf); + return INF::ILO4->new($inf); } elsif ( $inf->{inf_type} eq 'ilo4' ) { - return INF::ILO->new($inf); + return INF::ILO4->new($inf); } elsif ( $inf->{inf_type} eq 'ilo5' ) { return INF::ILO5->new($inf); diff --git a/INF/ASRock.pm b/INF/ASRock.pm index 9ae247f..d13e564 100644 --- a/INF/ASRock.pm +++ b/INF/ASRock.pm @@ -45,8 +45,6 @@ sub login($) { $self->{csrftoken} = $json->{CSRFToken}; - print "csrftoken " . $self->{csrftoken} . "\n"; - return 0; } @@ -135,33 +133,24 @@ sub get_host_power($) { $self->login() unless defined $self->{logged_in}; - my $post = POST( $self->{bmc_url} . '/cgi/ipmi.cgi' ); - my $form_content = 'op=POWER_INFO.XML&r=(0%2C0)'; + my $get = GET( $self->{bmc_url} . '/api/chassis-status' ); - $post->header( 'Content-Type' => 'application/x-www-form-urlencoded' ); - $post->header( 'Content-Length' => length($form_content) ); - $post->content($form_content); + $get->header( 'X-CSRFTOKEN' => $self->{csrftoken} ); + $get->header( 'Cookie' => 'lang=en-us' ); - my $res = $self->{ua}->request($post); + my $res = $self->{ua}->request($get); unless ( $res->is_success ) { print STDERR " get host power - did not get 200\n"; return undef; } - my $xml = new XML::Simple; - - my $c = $res->content; - - $c =~ s/^[\s\n\r]+//s; - - my $data = $xml->XMLin($c); + my $json = decode_json( $res->content ); - return undef unless defined $data->{'POWER_INFO'}; - return undef unless defined $data->{'POWER_INFO'}->{'POWER'}; - return undef unless defined $data->{'POWER_INFO'}->{'POWER'}->{'STATUS'}; + return "ON" if $json->{power_status} == "1"; + return "OFF" if $json->{power_status} == "0"; - return $data->{'POWER_INFO'}->{'POWER'}->{'STATUS'}; + return undef; } sub set_host_power($$) { @@ -169,13 +158,17 @@ sub set_host_power($$) { $self->login() unless defined $self->{logged_in}; - my $post = POST( $self->{bmc_url} . '/cgi/ipmi.cgi' ); - my $form_content = 'op=POWER_INFO.XML&r=(1%2C' . $what . ')'; + my $payload = '{"power_command":' . $what . '}'; - $post->header( 'Content-Type' => 'application/x-www-form-urlencoded' ); - $post->header( 'Content-Length' => length($form_content) ); - $post->content($form_content); + my $post = POST( $self->{bmc_url} . '/api/actions/power' ); + + $post->header( 'X-CSRFTOKEN' => $self->{csrftoken} ); + $post->header( 'Cookie' => 'lang=en-us' ); + $post->header( 'Content-Type' => 'application/json' ); + $post->header( 'Content-Length' => length($payload) ); + $post->content($payload); + my $res = $self->{ua}->request($post); unless ( $res->is_success ) { @@ -183,44 +176,35 @@ sub set_host_power($$) { return 0; } - my $xml = new XML::Simple; - - my $c = $res->content; - - $c =~ s/^[\s\n\r]+//s; - - my $data = $xml->XMLin($c); - - return 0 unless defined $data->{'POWER_INFO'}; - return 0 unless defined $data->{'POWER_INFO'}->{'POWER'}; - return 0 unless defined $data->{'POWER_INFO'}->{'POWER'}->{'STATUS'}; + my $json = decode_json( $res->content ); + return 0 unless defined $json->{power_command}; return 1; } sub reset($) { my $self = shift; - return $self->set_host_power('0'); + return $self->set_host_power('3'); } sub port_off($) { my $self = shift; - return $self->set_host_power('1'); + return $self->set_host_power('0'); } sub orderly_shutdown($) { my $self = shift; - return $self->set_host_power('2'); + return $self->set_host_power('5'); } sub port_on($) { my $self = shift; - return $self->set_host_power('3'); + return $self->set_host_power('1'); } sub port_cycle($) { my $self = shift; - return $self->set_host_power('5'); + return $self->set_host_power('2'); } sub port_state_get($$) { @@ -228,6 +212,12 @@ sub port_state_get($$) { return $self->get_host_power(); } +sub port_state_get_no_cache($$) { + my $self = shift; + return $self->get_host_power(); +} + + sub port_name_get($$) { my $self = shift; return $self->{name}; @@ -1,6 +1,6 @@ #!/usr/bin/env perl -package INF::ILO; +package INF::ILO4; use HTTP::Daemon::SSL; use HTTP::Server::Brick; diff --git a/INF/ILO5.pm b/INF/ILO5.pm index f406762..d2689fd 100644 --- a/INF/ILO5.pm +++ b/INF/ILO5.pm @@ -210,7 +210,6 @@ sub login($) { $self->{skey} = undef; return -1; } - print STDERR "Login good!\n"; my $json = decode_json( $res->content ); @@ -320,7 +319,6 @@ sub get_host_power($) { my $state = decode_json $res->content; return $state->{'hostpwr_state'}; - } sub set_host_power($$) { diff --git a/INF/SuperMicro.pm b/INF/SuperMicro.pm index 7284826..121d36a 100644 --- a/INF/SuperMicro.pm +++ b/INF/SuperMicro.pm @@ -226,6 +226,11 @@ sub port_state_get($$) { return $self->get_host_power(); } +sub port_state_get_no_cache($$) { + my $self = shift; + return $self->get_host_power(); +} + sub port_name_get($$) { my $self = shift; return $self->{name}; @@ -16,8 +16,8 @@ install: install -m 644 INF/INF.pm /usr/local/share/inf/INF install -m 644 INF/APC.pm /usr/local/share/inf/INF install -m 644 INF/DSRx020.pm /usr/local/share/inf/INF - install -m 644 INF/ILO.pm /usr/local/share/inf/INF install -m 644 INF/ILO2.pm /usr/local/share/inf/INF + install -m 644 INF/ILO4.pm /usr/local/share/inf/INF install -m 644 INF/ILO5.pm /usr/local/share/inf/INF install -m 644 INF/Cyclades.pm /usr/local/share/inf/INF install -m 644 INF/SuperMicro.pm /usr/local/share/inf/INF |