From 4c8dfad42dc43ccab8497f386cc35e0c2b07630d Mon Sep 17 00:00:00 2001 From: Mark Gurevich Date: Thu, 20 Jul 2017 13:50:04 -0400 Subject: [PATCH 1/3] OpenBMC rspconfig display --- xCAT-server/lib/xcat/plugins/openbmc.pm | 61 ++++++++++++++++++------- 1 file changed, 45 insertions(+), 16 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/openbmc.pm b/xCAT-server/lib/xcat/plugins/openbmc.pm index 7aabbee9d..ae6eb3c68 100644 --- a/xCAT-server/lib/xcat/plugins/openbmc.pm +++ b/xCAT-server/lib/xcat/plugins/openbmc.pm @@ -233,7 +233,7 @@ my %status_info = ( RSPCONFIG_GET_REQUEST => { method => "GET", - init_url => "", + init_url => "$openbmc_project_url/network/enumerate", }, RSPCONFIG_GET_RESPONSE => { process => \&rspconfig_response, @@ -467,7 +467,7 @@ sub parse_args { my $noderange = shift; my $check = undef; - xCAT::SvrUtils::sendmsg("[OpenBMC development support] Using this version of xCAT, ensure firware level is at v1.99.6-0-r1, or higher.", $callback); + xCAT::SvrUtils::sendmsg("[OpenBMC development support] Using this version of xCAT, ensure firmware level is at v1.99.6-0-r1, or higher.", $callback); my $subcommand = undef; my $verbose = undef; @@ -763,9 +763,7 @@ sub parse_command_status { push @options, $key; } } - $next_status{RSPCONFIG_GET_RESPONSE}{argv} = join(",", @options); - xCAT::SvrUtils::sendmsg("Command $command is not available now!", $callback); - return 1; + $status_info{RSPCONFIG_GET_RESPONSE}{argv} = join(",", @options); } if ($command eq "rvitals") { @@ -1500,24 +1498,55 @@ sub rspconfig_response { my $response_info = decode_json $response->content; if ($node_info{$node}{cur_status} eq "RSPCONFIG_GET_RESPONSE") { - my $grep_string = $status_info{RSPCONFIG_GET_RESPONSE}{argv}; - my $data; + my $address = "n/a"; + my $gateway = "n/a"; + my $prefix = "n/a"; + my $vlan = "n/a"; + my $default_gateway = "n/a"; + my $adapter_id = "n/a"; + my $path; my @output; + my $grep_string = $status_info{RSPCONFIG_GET_RESPONSE}{argv}; + foreach my $key_url (keys %{$response_info->{data}}) { + my %content = %{ ${ $response_info->{data} }{$key_url} }; + + #xCAT::SvrUtils::sendmsg("Content for $key_url\n " . Dumper(%content) , $callback); + if ($key_url =~ /network\/config/) { + if (defined($content{DefaultGateway}) and $content{DefaultGateway}) { + $default_gateway = $content{DefaultGateway}; + } + } + + + ($path, $adapter_id) = (split(/ipv4\//, $key_url)); + + if ($adapter_id) { + if (defined($content{Address}) and $content{Address}) { + $address = $content{Address}; + } + if (defined($content{Gateway}) and $content{Gateway}) { + $gateway = $content{Gateway}; + } + if (defined($content{PrefixLength}) and $content{PrefixLength}) { + $prefix = $content{PrefixLength}; + } + } + } if ($grep_string =~ "ip") { - $data = ""; # got data from response - push @output, "BMC IP: $data"; + push @output, "BMC IP: $address"; } if ($grep_string =~ "netmask") { - $data = ""; # got data from response - push @output, "BMC Netmask: $data"; + if ($address) { + my $decimal_mask = (2 ** $prefix - 1) << (32 - $prefix); + my $netmask = join('.', unpack("C4", pack("N", $decimal_mask))); + push @output, "BMC Netmask: " . $netmask; + } } if ($grep_string =~ "gateway") { - $data = ""; # got data from response - push @output, "BMC Gateway: $data"; - } + push @output, "BMC Gateway: $gateway (default: $default_gateway)"; + } if ($grep_string =~ "vlan") { - $data = ""; # got data from response - push @output, "BMC VLAN ID enabled: $data"; + push @output, "BMC VLAN ID enabled: $vlan"; } xCAT::SvrUtils::sendmsg("$_", $callback, $node) foreach (@output); From debfefb9de50ad9ecb269641e0cd266071212b18 Mon Sep 17 00:00:00 2001 From: Mark Gurevich Date: Mon, 24 Jul 2017 11:02:06 -0400 Subject: [PATCH 2/3] openbmc rspconfig query command --- xCAT-server/lib/xcat/plugins/openbmc.pm | 43 ++++++++++++++++--------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/openbmc.pm b/xCAT-server/lib/xcat/plugins/openbmc.pm index ae6eb3c68..af4f42edb 100644 --- a/xCAT-server/lib/xcat/plugins/openbmc.pm +++ b/xCAT-server/lib/xcat/plugins/openbmc.pm @@ -1504,13 +1504,13 @@ sub rspconfig_response { my $vlan = "n/a"; my $default_gateway = "n/a"; my $adapter_id = "n/a"; + my $error; my $path; my @output; my $grep_string = $status_info{RSPCONFIG_GET_RESPONSE}{argv}; foreach my $key_url (keys %{$response_info->{data}}) { my %content = %{ ${ $response_info->{data} }{$key_url} }; - #xCAT::SvrUtils::sendmsg("Content for $key_url\n " . Dumper(%content) , $callback); if ($key_url =~ /network\/config/) { if (defined($content{DefaultGateway}) and $content{DefaultGateway}) { $default_gateway = $content{DefaultGateway}; @@ -1519,6 +1519,13 @@ sub rspconfig_response { ($path, $adapter_id) = (split(/ipv4\//, $key_url)); + unless ($address =~ /n\/a/) { + # We have already processed an entry with adapter information. + # This must be a second entry. Display an error. Currently only supporting + # an adapter with a single IP address set. + $error = "Interfaces with multiple IP addresses are not supported"; + last; + } if ($adapter_id) { if (defined($content{Address}) and $content{Address}) { @@ -1532,21 +1539,27 @@ sub rspconfig_response { } } } - if ($grep_string =~ "ip") { - push @output, "BMC IP: $address"; - } - if ($grep_string =~ "netmask") { - if ($address) { - my $decimal_mask = (2 ** $prefix - 1) << (32 - $prefix); - my $netmask = join('.', unpack("C4", pack("N", $decimal_mask))); - push @output, "BMC Netmask: " . $netmask; + if ($error) { + # Display error message once, regardless of how many subcommands were specified + push @output, $error; + } + else { + if ($grep_string =~ "ip") { + push @output, "BMC IP: $address"; + } + if ($grep_string =~ "netmask") { + if ($address) { + my $decimal_mask = (2 ** $prefix - 1) << (32 - $prefix); + my $netmask = join('.', unpack("C4", pack("N", $decimal_mask))); + push @output, "BMC Netmask: " . $netmask; + } + } + if ($grep_string =~ "gateway") { + push @output, "BMC Gateway: $gateway (default: $default_gateway)"; + } + if ($grep_string =~ "vlan") { + push @output, "BMC VLAN ID enabled: $vlan"; } - } - if ($grep_string =~ "gateway") { - push @output, "BMC Gateway: $gateway (default: $default_gateway)"; - } - if ($grep_string =~ "vlan") { - push @output, "BMC VLAN ID enabled: $vlan"; } xCAT::SvrUtils::sendmsg("$_", $callback, $node) foreach (@output); From 91ac7b3488f458ee5fbdde9471a0956dccfb04ec Mon Sep 17 00:00:00 2001 From: Mark Gurevich Date: Tue, 25 Jul 2017 16:04:14 -0400 Subject: [PATCH 3/3] Catch multiple ips on the same adapter better --- xCAT-server/lib/xcat/plugins/openbmc.pm | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/openbmc.pm b/xCAT-server/lib/xcat/plugins/openbmc.pm index af4f42edb..d60978882 100644 --- a/xCAT-server/lib/xcat/plugins/openbmc.pm +++ b/xCAT-server/lib/xcat/plugins/openbmc.pm @@ -1519,16 +1519,16 @@ sub rspconfig_response { ($path, $adapter_id) = (split(/ipv4\//, $key_url)); - unless ($address =~ /n\/a/) { - # We have already processed an entry with adapter information. - # This must be a second entry. Display an error. Currently only supporting - # an adapter with a single IP address set. - $error = "Interfaces with multiple IP addresses are not supported"; - last; - } if ($adapter_id) { if (defined($content{Address}) and $content{Address}) { + unless ($address =~ /n\/a/) { + # We have already processed an entry with adapter information. + # This must be a second entry. Display an error. Currently only supporting + # an adapter with a single IP address set. + $error = "Interfaces with multiple IP addresses are not supported"; + last; + } $address = $content{Address}; } if (defined($content{Gateway}) and $content{Gateway}) {