2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-08-23 19:50:21 +00:00

Merge pull request #3448 from whowutwut/rbeacon_openbmc

Add code to support rbeacon in openbmc
This commit is contained in:
xuweibj
2017-07-17 14:51:31 +08:00
committed by GitHub

View File

@@ -30,6 +30,9 @@ use xCAT::GlobalDef;
use xCAT_monitoring::monitorctrl;
$::VERBOSE = 0;
# String constants for rbeacon states
$::BEACON_STATE_OFF="off";
$::BEACON_STATE_ON="on";
# String constants for rpower states
$::POWER_STATE_OFF = "off";
$::POWER_STATE_ON = "on";
@@ -106,6 +109,23 @@ my %status_info = (
process => \&login_response,
},
RBEACON_ON_REQUEST => {
method => "PUT",
init_url => "$openbmc_project_url/led/groups/enclosure_identify/attr/Asserted",
data => "true",
},
RBEACON_ON_RESPONSE => {
process => \&rbeacon_response,
},
RBEACON_OFF_REQUEST => {
method => "PUT",
init_url => "$openbmc_project_url/led/groups/enclosure_identify/attr/Asserted",
data => "false",
},
RBEACON_OFF_RESPONSE => {
process => \&rbeacon_response,
},
REVENTLOG_REQUEST => {
method => "GET",
init_url => "$openbmc_project_url/logging/enumerate",
@@ -460,7 +480,11 @@ sub parse_args {
$subcommand = $ARGV[0]
}
if ($command eq "rpower") {
if ($command eq "rbeacon") {
unless ($subcommand =~ /^on$|^off$/) {
return ([ 1, "Unsupported command: $command $subcommand" ]);
}
} elsif ($command eq "rpower") {
unless ($subcommand =~ /^on$|^off$|^softoff$|^reset$|^boot$|^bmcreboot$|^bmcstate$|^status$|^stat$|^state$/) {
return ([ 1, "Unsupported command: $command $subcommand" ]);
}
@@ -582,6 +606,18 @@ sub parse_command_status {
return 1;
}
if ($command eq "rbeacon") {
$subcommand = $$subcommands[0];
if ($subcommand eq "on") {
$next_status{LOGIN_RESPONSE} = "RBEACON_ON_REQUEST";
$next_status{RBEACON_ON_REQUEST} = "RBEACON_ON_RESPONSE";
} elsif ($subcommand eq "off") {
$next_status{LOGIN_RESPONSE} = "RBEACON_OFF_REQUEST";
$next_status{RBEACON_OFF_REQUEST} = "RBEACON_OFF_RESPONSE";
}
}
if ($command eq "rpower") {
$subcommand = $$subcommands[0];
@@ -909,7 +945,12 @@ sub gen_send_request {
}
if ($status_info{ $node_info{$node}{cur_status} }{data}) {
$content = '{"data":"' . $status_info{ $node_info{$node}{cur_status} }{data} . '"}';
# Handle boolean values by create the json objects without wrapping with quotes
if ($status_info{ $node_info{$node}{cur_status} }{data} =~ /^1$|^true$|^True$|^0$|^false$|^False$/) {
$content = '{"data":' . $status_info{ $node_info{$node}{cur_status} }{data} . '}';
} else {
$content = '{"data":"' . $status_info{ $node_info{$node}{cur_status} }{data} . '"}';
}
}
if ($node_info{$node}{cur_url}) {
@@ -1331,6 +1372,45 @@ sub rsetboot_response {
return;
}
#-------------------------------------------------------
=head3 rbeacon_response
Deal with response of rbeacon command
Input:
$node: nodename of current response
$response: Async return response
=cut
#-------------------------------------------------------
sub rbeacon_response {
my $node = shift;
my $response = shift;
my $response_info = decode_json $response->content;
if ($node_info{$node}{cur_status} eq "RBEACON_ON_RESPONSE") {
if ($response_info->{'message'} eq $::RESPONSE_OK) {
xCAT::SvrUtils::sendmsg("$::BEACON_STATE_ON", $callback, $node);
}
}
if ($node_info{$node}{cur_status} eq "RBEACON_OFF_RESPONSE") {
if ($response_info->{'message'} eq $::RESPONSE_OK) {
xCAT::SvrUtils::sendmsg("$::BEACON_STATE_OFF", $callback, $node);
}
}
if ($next_status{ $node_info{$node}{cur_status} }) {
$node_info{$node}{cur_status} = $next_status{ $node_info{$node}{cur_status} };
gen_send_request($node);
} else {
$wait_node_num--;
}
}
#-------------------------------------------------------
=head3 reventlog_response