summaryrefslogtreecommitdiffstats
path: root/INF/ASRock.pm
diff options
context:
space:
mode:
Diffstat (limited to 'INF/ASRock.pm')
-rw-r--r--INF/ASRock.pm70
1 files changed, 30 insertions, 40 deletions
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};