From 3208e62b382f08a9ec6e2c44e0afcca12162acda Mon Sep 17 00:00:00 2001 From: root Date: Wed, 1 Sep 2021 09:25:25 +0100 Subject: add power controll to asrock, fix bug in supermicro, rename ilo -> ilo4 --- INF/ASRock.pm | 70 +++++++++++++++++++++++++---------------------------------- 1 file changed, 30 insertions(+), 40 deletions(-) (limited to 'INF/ASRock.pm') 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}; -- cgit v1.2.3