summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorroot <root@ka-ata-killa.panaceas.james.local>2021-09-01 09:25:25 +0100
committerroot <root@ka-ata-killa.panaceas.james.local>2021-09-01 09:25:25 +0100
commit3208e62b382f08a9ec6e2c44e0afcca12162acda (patch)
treee46877ad962e75d294fb13ab2e9d4006f3ec061f
parentffd666e52164d06bc67d3d134ae8f53eb268bf6b (diff)
downloadinf-3208e62b382f08a9ec6e2c44e0afcca12162acda.tar.gz
inf-3208e62b382f08a9ec6e2c44e0afcca12162acda.tar.bz2
inf-3208e62b382f08a9ec6e2c44e0afcca12162acda.zip
add power controll to asrock, fix bug in supermicro, rename ilo -> ilo4
-rw-r--r--INF.pm6
-rw-r--r--INF/ASRock.pm70
-rw-r--r--INF/ILO4.pm (renamed from INF/ILO.pm)2
-rw-r--r--INF/ILO5.pm2
-rw-r--r--INF/SuperMicro.pm5
-rw-r--r--Makefile2
6 files changed, 40 insertions, 47 deletions
diff --git a/INF.pm b/INF.pm
index 47e381e..ab247b8 100644
--- a/INF.pm
+++ b/INF.pm
@@ -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};
diff --git a/INF/ILO.pm b/INF/ILO4.pm
index 577d0c6..3f76ac9 100644
--- a/INF/ILO.pm
+++ b/INF/ILO4.pm
@@ -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};
diff --git a/Makefile b/Makefile
index b5b6696..51202d8 100644
--- a/Makefile
+++ b/Makefile
@@ -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