Skip to content

Commit fe04623

Browse files
authored
Merge pull request #3530 from gurevichmark/rspconfig_openbmc_network
Rspconfig openbmc network
2 parents 7453088 + 91ac7b3 commit fe04623

File tree

1 file changed

+63
-21
lines changed

1 file changed

+63
-21
lines changed

xCAT-server/lib/xcat/plugins/openbmc.pm

Lines changed: 63 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ my %status_info = (
233233

234234
RSPCONFIG_GET_REQUEST => {
235235
method => "GET",
236-
init_url => "",
236+
init_url => "$openbmc_project_url/network/enumerate",
237237
},
238238
RSPCONFIG_GET_RESPONSE => {
239239
process => \&rspconfig_response,
@@ -468,7 +468,7 @@ sub parse_args {
468468
my $noderange = shift;
469469
my $check = undef;
470470

471-
xCAT::SvrUtils::sendmsg("[OpenBMC development support] Using this version of xCAT, ensure firware level is at v1.99.6-0-r1, or higher.", $callback);
471+
xCAT::SvrUtils::sendmsg("[OpenBMC development support] Using this version of xCAT, ensure firmware level is at v1.99.6-0-r1, or higher.", $callback);
472472

473473
my $subcommand = undef;
474474
my $verbose = undef;
@@ -758,9 +758,7 @@ sub parse_command_status {
758758
push @options, $key;
759759
}
760760
}
761-
$next_status{RSPCONFIG_GET_RESPONSE}{argv} = join(",", @options);
762-
xCAT::SvrUtils::sendmsg("Command $command is not available now!", $callback);
763-
return 1;
761+
$status_info{RSPCONFIG_GET_RESPONSE}{argv} = join(",", @options);
764762
}
765763

766764
if ($command eq "rvitals") {
@@ -1497,24 +1495,68 @@ sub rspconfig_response {
14971495
my $response_info = decode_json $response->content;
14981496

14991497
if ($node_info{$node}{cur_status} eq "RSPCONFIG_GET_RESPONSE") {
1500-
my $grep_string = $status_info{RSPCONFIG_GET_RESPONSE}{argv};
1501-
my $data;
1498+
my $address = "n/a";
1499+
my $gateway = "n/a";
1500+
my $prefix = "n/a";
1501+
my $vlan = "n/a";
1502+
my $default_gateway = "n/a";
1503+
my $adapter_id = "n/a";
1504+
my $error;
1505+
my $path;
15021506
my @output;
1503-
if ($grep_string =~ "ip") {
1504-
$data = ""; # got data from response
1505-
push @output, "BMC IP: $data";
1506-
}
1507-
if ($grep_string =~ "netmask") {
1508-
$data = ""; # got data from response
1509-
push @output, "BMC Netmask: $data";
1510-
}
1511-
if ($grep_string =~ "gateway") {
1512-
$data = ""; # got data from response
1513-
push @output, "BMC Gateway: $data";
1507+
my $grep_string = $status_info{RSPCONFIG_GET_RESPONSE}{argv};
1508+
foreach my $key_url (keys %{$response_info->{data}}) {
1509+
my %content = %{ ${ $response_info->{data} }{$key_url} };
1510+
1511+
if ($key_url =~ /network\/config/) {
1512+
if (defined($content{DefaultGateway}) and $content{DefaultGateway}) {
1513+
$default_gateway = $content{DefaultGateway};
1514+
}
1515+
}
1516+
1517+
1518+
($path, $adapter_id) = (split(/ipv4\//, $key_url));
1519+
1520+
if ($adapter_id) {
1521+
if (defined($content{Address}) and $content{Address}) {
1522+
unless ($address =~ /n\/a/) {
1523+
# We have already processed an entry with adapter information.
1524+
# This must be a second entry. Display an error. Currently only supporting
1525+
# an adapter with a single IP address set.
1526+
$error = "Interfaces with multiple IP addresses are not supported";
1527+
last;
1528+
}
1529+
$address = $content{Address};
1530+
}
1531+
if (defined($content{Gateway}) and $content{Gateway}) {
1532+
$gateway = $content{Gateway};
1533+
}
1534+
if (defined($content{PrefixLength}) and $content{PrefixLength}) {
1535+
$prefix = $content{PrefixLength};
1536+
}
1537+
}
15141538
}
1515-
if ($grep_string =~ "vlan") {
1516-
$data = ""; # got data from response
1517-
push @output, "BMC VLAN ID enabled: $data";
1539+
if ($error) {
1540+
# Display error message once, regardless of how many subcommands were specified
1541+
push @output, $error;
1542+
}
1543+
else {
1544+
if ($grep_string =~ "ip") {
1545+
push @output, "BMC IP: $address";
1546+
}
1547+
if ($grep_string =~ "netmask") {
1548+
if ($address) {
1549+
my $decimal_mask = (2 ** $prefix - 1) << (32 - $prefix);
1550+
my $netmask = join('.', unpack("C4", pack("N", $decimal_mask)));
1551+
push @output, "BMC Netmask: " . $netmask;
1552+
}
1553+
}
1554+
if ($grep_string =~ "gateway") {
1555+
push @output, "BMC Gateway: $gateway (default: $default_gateway)";
1556+
}
1557+
if ($grep_string =~ "vlan") {
1558+
push @output, "BMC VLAN ID enabled: $vlan";
1559+
}
15181560
}
15191561

15201562
xCAT::SvrUtils::sendmsg("$_", $callback, $node) foreach (@output);

0 commit comments

Comments
 (0)