From 78f1eb0afb4baf3e5a0b20c1a69a453192419b11 Mon Sep 17 00:00:00 2001 From: Victor Hu Date: Tue, 19 Dec 2017 14:06:15 -0500 Subject: [PATCH 1/5] Add support for "rvitals leds" to display the physical LEDs states on the OpenBMC P9 Box, this commit just prints key/value pairs --- xCAT-server/lib/xcat/plugins/openbmc.pm | 97 ++++++++++++++++--------- 1 file changed, 62 insertions(+), 35 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/openbmc.pm b/xCAT-server/lib/xcat/plugins/openbmc.pm index 8e439243b..b50f800b9 100644 --- a/xCAT-server/lib/xcat/plugins/openbmc.pm +++ b/xCAT-server/lib/xcat/plugins/openbmc.pm @@ -494,6 +494,13 @@ my %status_info = ( RVITALS_RESPONSE => { process => \&rvitals_response, }, + RVITALS_LEDS_REQUEST => { + method => "GET", + init_url => "$openbmc_project_url/led/physical/enumerate", + }, + RVITALS_LEDS_RESPONSE => { + process => \&rvitals_response, + }, RSPCONFIG_API_CONFIG_ON_REQUEST => { method => "PUT", init_url => "$openbmc_project_url", @@ -1124,7 +1131,7 @@ sub parse_args { } } elsif ($command eq "rvitals") { $subcommand = "all" if (!defined($ARGV[0])); - unless ($subcommand =~ /^temp$|^voltage$|^wattage$|^fanspeed$|^power$|^altitude$|^all$/) { + unless ($subcommand =~ /^leds$|^temp$|^voltage$|^wattage$|^fanspeed$|^power$|^altitude$|^all$/) { return ([ 1, "Unsupported command: $command $subcommand" ]); } } elsif ($command eq "rflash") { @@ -1627,9 +1634,15 @@ sub parse_command_status { $subcommand = "all"; } - $next_status{LOGIN_RESPONSE} = "RVITALS_REQUEST"; - $next_status{RVITALS_REQUEST} = "RVITALS_RESPONSE"; - $status_info{RVITALS_RESPONSE}{argv} = "$subcommand"; + if ($subcommand eq "leds") { + $next_status{LOGIN_RESPONSE} = "RVITALS_LEDS_REQUEST"; + $next_status{RVITALS_LEDS_REQUEST} = "RVITALS_LEDS_RESPONSE"; + $status_info{RVITALS_LEDS_RESPONSE}{argv} = "$subcommand"; + } else { + $next_status{LOGIN_RESPONSE} = "RVITALS_REQUEST"; + $next_status{RVITALS_REQUEST} = "RVITALS_RESPONSE"; + $status_info{RVITALS_RESPONSE}{argv} = "$subcommand"; + } } if ($command eq "rflash") { @@ -3605,7 +3618,12 @@ sub rvitals_response { my $response_info = decode_json $response->content; - my $grep_string = $status_info{RVITALS_RESPONSE}{argv}; + my $grep_string; + if ($node_info{$node}{cur_status} =~ "RVITALS_LEDS_RESPONSE") { + $grep_string = $status_info{RVITALS_LEDS_RESPONSE}{argv}; + } else { + $grep_string = $status_info{RVITALS_RESPONSE}{argv}; + } my $src; my $content_info; my @sorted_output; @@ -3613,43 +3631,52 @@ sub rvitals_response { foreach my $key_url (keys %{$response_info->{data}}) { my %content = %{ ${ $response_info->{data} }{$key_url} }; - # - # Skip over attributes that are not asked to be printed - # - if ($grep_string =~ "temp") { - unless ( $content{Unit} =~ "DegreesC") { next; } - } - if ($grep_string =~ "voltage") { - unless ( $content{Unit} =~ "Volts") { next; } - } - if ($grep_string =~ "wattage") { - unless ( $content{Unit} =~ "Watts") { next; } - } - if ($grep_string =~ "fanspeed") { - unless ( $content{Unit} =~ "RPMS") { next; } - } - if ($grep_string =~ "power") { - unless ( $content{Unit} =~ "Amperes" || $content{Unit} =~ "Joules" || $content{Unit} =~ "Watts" ) { next; } - } - if ($grep_string =~ "altitude") { - unless ( $content{Unit} =~ "Meters" ) { next; } - } - my $label = (split(/\//, $key_url))[ -1 ]; # replace underscore with space, uppercase the first letter $label =~ s/_/ /g; $label =~ s/\b(\w)/\U$1/g; + my $calc_value = undef; - # - # Calculate the adjusted value based on the scale attribute - # - my $calc_value = $content{Value}; - if ( $content{Scale} != 0 ) { - $calc_value = ($content{Value} * (10 ** $content{Scale})); + if ($node_info{$node}{cur_status} =~ "RVITALS_LEDS_RESPONSE") { + + # Print out Led info + $calc_value = (split(/\./, $content{State}))[-1]; + $content_info = $label . ": " . $calc_value ; + } else { + # print out Sensor info + # + # Skip over attributes that are not asked to be printed + # + if ($grep_string =~ "temp") { + unless ( $content{Unit} =~ "DegreesC") { next; } + } + if ($grep_string =~ "voltage") { + unless ( $content{Unit} =~ "Volts") { next; } + } + if ($grep_string =~ "wattage") { + unless ( $content{Unit} =~ "Watts") { next; } + } + if ($grep_string =~ "fanspeed") { + unless ( $content{Unit} =~ "RPMS") { next; } + } + if ($grep_string =~ "power") { + unless ( $content{Unit} =~ "Amperes" || $content{Unit} =~ "Joules" || $content{Unit} =~ "Watts" ) { next; } + } + if ($grep_string =~ "altitude") { + unless ( $content{Unit} =~ "Meters" ) { next; } + } + + # + # Calculate the adjusted value based on the scale attribute + # + $calc_value = $content{Value}; + if ( $content{Scale} != 0 ) { + $calc_value = ($content{Value} * (10 ** $content{Scale})); + } + + $content_info = $label . ": " . $calc_value . " " . $sensor_units{ $content{Unit} }; } - - $content_info = $label . ": " . $calc_value . " " . $sensor_units{ $content{Unit} }; push (@sorted_output, $content_info); #Save output in array } # If sorted array has any contents, sort it and print it From 69819509ffd7148c674afbb46b831c6c63a6e94d Mon Sep 17 00:00:00 2001 From: Victor Hu Date: Tue, 19 Dec 2017 14:59:43 -0500 Subject: [PATCH 2/5] Condense the output of the LEDs to less lines to create a better picture of the server --- xCAT-server/lib/xcat/plugins/openbmc.pm | 43 +++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/openbmc.pm b/xCAT-server/lib/xcat/plugins/openbmc.pm index b50f800b9..20a266579 100644 --- a/xCAT-server/lib/xcat/plugins/openbmc.pm +++ b/xCAT-server/lib/xcat/plugins/openbmc.pm @@ -3628,21 +3628,43 @@ sub rvitals_response { my $content_info; my @sorted_output; + my $f0 = ""; + my $f1 = ""; + my $f2 = ""; + my $f3 = ""; + my $front_id = ""; + my $front_fault = ""; + my $front_power = ""; + my $rear_id = ""; + my $rear_fault = ""; + my $rear_power = ""; + foreach my $key_url (keys %{$response_info->{data}}) { my %content = %{ ${ $response_info->{data} }{$key_url} }; my $label = (split(/\//, $key_url))[ -1 ]; - # replace underscore with space, uppercase the first letter $label =~ s/_/ /g; $label =~ s/\b(\w)/\U$1/g; + my $calc_value = undef; if ($node_info{$node}{cur_status} =~ "RVITALS_LEDS_RESPONSE") { - # Print out Led info $calc_value = (split(/\./, $content{State}))[-1]; $content_info = $label . ": " . $calc_value ; + + if ($key_url =~ "fan0") { $f0 = $calc_value; } + if ($key_url =~ "fan1") { $f1 = $calc_value; } + if ($key_url =~ "fan2") { $f2 = $calc_value; } + if ($key_url =~ "fan3") { $f3 = $calc_value; } + if ($key_url =~ "front_id") { $front_id = $calc_value; } + if ($key_url =~ "front_fault") { $front_fault = $calc_value; } + if ($key_url =~ "front_power") { $front_power = $calc_value; } + if ($key_url =~ "rear_id") { $rear_id = $calc_value; } + if ($key_url =~ "rear_fault") { $rear_fault = $calc_value; } + if ($key_url =~ "rear_power") { $rear_power = $calc_value; } + } else { # print out Sensor info # @@ -3676,9 +3698,24 @@ sub rvitals_response { } $content_info = $label . ": " . $calc_value . " " . $sensor_units{ $content{Unit} }; + push (@sorted_output, $content_info); #Save output in array } - push (@sorted_output, $content_info); #Save output in array } + + if ($node_info{$node}{cur_status} =~ "RVITALS_LEDS_RESPONSE") { + $content_info = "Front . . : Power:$front_power Fault:$front_fault Identify:$front_id"; + push (@sorted_output, $content_info); + $content_info = "Rear. . . : Power:$rear_power Fault:$rear_fault Identify:$rear_id"; + push (@sorted_output, $content_info); + # Fans + if ($f0 =~ "Off" and $f1 =~ "Off" and $f2 eq "Off" and $f3 eq "Off") { + $content_info = "Front Fan : No lights active"; + } else { + $content_info = "Front Fan : Fan0:$f0 Fan1:$f1 Fan2:$f2 Fan3:$f3"; + } + push (@sorted_output, $content_info); + } + # If sorted array has any contents, sort it and print it if (scalar @sorted_output > 0) { # Sort the output, alpha, then numeric From e65c6e4fad5531fa45ee062b1ceaddad578e7823 Mon Sep 17 00:00:00 2001 From: Victor Hu Date: Tue, 19 Dec 2017 15:22:11 -0500 Subject: [PATCH 3/5] Change the output message slightly --- xCAT-server/lib/xcat/plugins/openbmc.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/openbmc.pm b/xCAT-server/lib/xcat/plugins/openbmc.pm index 20a266579..854533a65 100644 --- a/xCAT-server/lib/xcat/plugins/openbmc.pm +++ b/xCAT-server/lib/xcat/plugins/openbmc.pm @@ -3709,9 +3709,9 @@ sub rvitals_response { push (@sorted_output, $content_info); # Fans if ($f0 =~ "Off" and $f1 =~ "Off" and $f2 eq "Off" and $f3 eq "Off") { - $content_info = "Front Fan : No lights active"; + $content_info = "Front Fans: No LEDs On"; } else { - $content_info = "Front Fan : Fan0:$f0 Fan1:$f1 Fan2:$f2 Fan3:$f3"; + $content_info = "Front Fans: fan0:$f0 fan1:$f1 fan2:$f2 fan3:$f3"; } push (@sorted_output, $content_info); } From af1bf635a90d9f8e0d9f1be352ac1a86f17705c4 Mon Sep 17 00:00:00 2001 From: Victor Hu Date: Wed, 20 Dec 2017 10:48:22 -0500 Subject: [PATCH 4/5] Space out the heading a little more for rvitals led --- xCAT-server/lib/xcat/plugins/openbmc.pm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/openbmc.pm b/xCAT-server/lib/xcat/plugins/openbmc.pm index 854533a65..5bdb27db6 100644 --- a/xCAT-server/lib/xcat/plugins/openbmc.pm +++ b/xCAT-server/lib/xcat/plugins/openbmc.pm @@ -3703,15 +3703,15 @@ sub rvitals_response { } if ($node_info{$node}{cur_status} =~ "RVITALS_LEDS_RESPONSE") { - $content_info = "Front . . : Power:$front_power Fault:$front_fault Identify:$front_id"; + $content_info = "Front . . . . . : Power:$front_power Fault:$front_fault Identify:$front_id"; push (@sorted_output, $content_info); - $content_info = "Rear. . . : Power:$rear_power Fault:$rear_fault Identify:$rear_id"; + $content_info = "Rear . . . . . : Power:$rear_power Fault:$rear_fault Identify:$rear_id"; push (@sorted_output, $content_info); # Fans if ($f0 =~ "Off" and $f1 =~ "Off" and $f2 eq "Off" and $f3 eq "Off") { - $content_info = "Front Fans: No LEDs On"; + $content_info = "Front Fans . . : No LEDs On"; } else { - $content_info = "Front Fans: fan0:$f0 fan1:$f1 fan2:$f2 fan3:$f3"; + $content_info = "Front Fans . . : fan0:$f0 fan1:$f1 fan2:$f2 fan3:$f3"; } push (@sorted_output, $content_info); } From 47ea0b2c8db05bf748e3fecf1257e496f68335bf Mon Sep 17 00:00:00 2001 From: Victor Hu Date: Wed, 20 Dec 2017 22:50:19 -0500 Subject: [PATCH 5/5] replace with hash to store led values --- xCAT-server/lib/xcat/plugins/openbmc.pm | 39 ++++++++++--------------- 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/openbmc.pm b/xCAT-server/lib/xcat/plugins/openbmc.pm index 5bdb27db6..e2bbc6db9 100644 --- a/xCAT-server/lib/xcat/plugins/openbmc.pm +++ b/xCAT-server/lib/xcat/plugins/openbmc.pm @@ -3628,16 +3628,7 @@ sub rvitals_response { my $content_info; my @sorted_output; - my $f0 = ""; - my $f1 = ""; - my $f2 = ""; - my $f3 = ""; - my $front_id = ""; - my $front_fault = ""; - my $front_power = ""; - my $rear_id = ""; - my $rear_fault = ""; - my $rear_power = ""; + my %leds = (); foreach my $key_url (keys %{$response_info->{data}}) { my %content = %{ ${ $response_info->{data} }{$key_url} }; @@ -3654,16 +3645,16 @@ sub rvitals_response { $calc_value = (split(/\./, $content{State}))[-1]; $content_info = $label . ": " . $calc_value ; - if ($key_url =~ "fan0") { $f0 = $calc_value; } - if ($key_url =~ "fan1") { $f1 = $calc_value; } - if ($key_url =~ "fan2") { $f2 = $calc_value; } - if ($key_url =~ "fan3") { $f3 = $calc_value; } - if ($key_url =~ "front_id") { $front_id = $calc_value; } - if ($key_url =~ "front_fault") { $front_fault = $calc_value; } - if ($key_url =~ "front_power") { $front_power = $calc_value; } - if ($key_url =~ "rear_id") { $rear_id = $calc_value; } - if ($key_url =~ "rear_fault") { $rear_fault = $calc_value; } - if ($key_url =~ "rear_power") { $rear_power = $calc_value; } + if ($key_url =~ "fan0") { $leds{fan0} = $calc_value; } + if ($key_url =~ "fan1") { $leds{fan1} = $calc_value; } + if ($key_url =~ "fan2") { $leds{fan2} = $calc_value; } + if ($key_url =~ "fan3") { $leds{fan3} = $calc_value; } + if ($key_url =~ "front_id") { $leds{front_id} = $calc_value; } + if ($key_url =~ "front_fault") { $leds{front_fault} = $calc_value; } + if ($key_url =~ "front_power") { $leds{front_power} = $calc_value; } + if ($key_url =~ "rear_id") { $leds{rear_id} = $calc_value; } + if ($key_url =~ "rear_fault") { $leds{rear_fault} = $calc_value; } + if ($key_url =~ "rear_power") { $leds{rear_power} = $calc_value; } } else { # print out Sensor info @@ -3703,15 +3694,15 @@ sub rvitals_response { } if ($node_info{$node}{cur_status} =~ "RVITALS_LEDS_RESPONSE") { - $content_info = "Front . . . . . : Power:$front_power Fault:$front_fault Identify:$front_id"; + $content_info = "Front . . . . . : Power:$leds{front_power} Fault:$leds{front_fault} Identify:$leds{front_id}"; push (@sorted_output, $content_info); - $content_info = "Rear . . . . . : Power:$rear_power Fault:$rear_fault Identify:$rear_id"; + $content_info = "Rear . . . . . : Power:$leds{rear_power} Fault:$leds{rear_fault} Identify:$leds{rear_id}"; push (@sorted_output, $content_info); # Fans - if ($f0 =~ "Off" and $f1 =~ "Off" and $f2 eq "Off" and $f3 eq "Off") { + if ($leds{fan0} =~ "Off" and $leds{fan1} =~ "Off" and $leds{fan2} eq "Off" and $leds{fan3} eq "Off") { $content_info = "Front Fans . . : No LEDs On"; } else { - $content_info = "Front Fans . . : fan0:$f0 fan1:$f1 fan2:$f2 fan3:$f3"; + $content_info = "Front Fans . . : fan0:$leds{fan0} fan1:$leds{fan1} fan2:$leds{fan2} fan3:$leds{fan3}"; } push (@sorted_output, $content_info); }