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

Merge pull request #5172 from gurevichmark/restapi_beacon

Add REST API beacon status function
This commit is contained in:
Yuan Bai 2018-05-08 14:31:55 +08:00 committed by GitHub
commit 175b7f1289
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 59 additions and 14 deletions

View File

@ -755,6 +755,29 @@ Delete all the event log for node1. ::
[URI:/nodes/{noderange}/beacon] - The beacon resource for the node {noderange}
------------------------------------------------------------------------------
GET - Get the beacon status for the node {noderange}.
`````````````````````````````````````````````````````
Refer to the man page: :doc:`rbeacon </guides/admin-guides/references/man1/rbeacon.1>`
**Returns:**
* Json format: An object which includes multiple '<name> : {att:value, attr:value ...}' pairs.
**Example:**
Get beacon for node1. ::
curl -X GET -k 'https://127.0.0.1/xcatws/nodes/node1/beacon?userName=root&userPW=cluster&pretty=1'
{
"node1":{
"beacon":[
"Front:Blink Rear:Blink"
]
}
}
PUT - Change the beacon status for the node {noderange}.
````````````````````````````````````````````````````````
@ -774,13 +797,6 @@ Turn on the beacon. ::
curl -X PUT -k 'https://127.0.0.1/xcatws/nodes/node1/beacon?userName=root&userPW=cluster&pretty=1' -H Content-Type:application/json --data '{"action":"on"}'
[
{
"name":"node1",
"beacon":"on"
}
]
[URI:/nodes/{noderange}/updating] - The updating resource for the node {noderange}
----------------------------------------------------------------------------------

View File

@ -431,15 +431,18 @@ my %URIdef = (
beacon => {
desc => "[URI:/nodes/{noderange}/beacon] - The beacon resource for the node {noderange}",
matcher => '^/nodes/[^/]*/beacon$',
GET_backup => {
GET => {
desc => "Get the beacon status for the node {noderange}.",
usage => "||$usagemsg{objreturn}|",
example => "|Get beacon for node1.|GET|/nodes/node1/beacon|{\n \"node1\":{\n \"beacon\":[\n \"Front:Blink Rear:Blink\"\n ]\n }\n}|",
cmd => "rbeacon",
fhandler => \&common,
fhandler => \&actionhdl,
outhdler => \&actionout,
},
PUT => {
desc => "Change the beacon status for the node {noderange}.",
usage => "|$usagemsg{objchparam} DataBody: {action:on/off/blink}.|$usagemsg{non_getreturn}|",
example => "|Turn on the beacon.|PUT|/nodes/node1/beacon {\"action\":\"on\"}|[\n {\n \"name\":\"node1\",\n \"beacon\":\"on\"\n }\n]|",
example => "|Turn on the beacon.|PUT|/nodes/node1/beacon {\"action\":\"on\"}||",
cmd => "rbeacon",
fhandler => \&actionhdl,
outhdler => \&noout,
@ -1563,12 +1566,12 @@ if (defined($URIdef{$uriLayer1})) {
} else {
# not matches to any resource group. Check the 'resource group' to improve the performance
error("Unspported resource.", $STATUS_NOT_FOUND);
error("Unsupported resource.", $STATUS_NOT_FOUND);
}
# the URI cannot match to any resources which are defined in %URIdef
unless ($handled) {
error("Unspported resource.", $STATUS_NOT_FOUND);
error("Unsupported resource.", $STATUS_NOT_FOUND);
}
@ -1945,7 +1948,7 @@ sub actionout {
foreach my $d (@$data) {
if (defined($d->{info})) {
# OpenBMC format
if ($param->{'resourcename'} eq "eventlog") {
if ($param->{'resourcename'} =~ /(^eventlog$|^beacon$)/) {
my ($node, $logentry) = split(/:/, $d->{info}->[0], 2);
$logentry =~ s/^\s+|\s+$//g; # trim whitespace from log entry
push @{ $jsonnode->{$node}->{ $param->{'resourcename'} } }, $logentry;
@ -2213,7 +2216,9 @@ sub actionhdl {
push @args, 'clear';
}
} elsif ($params->{'resourcename'} eq "beacon") {
if (isPut()) {
if (isGET()) {
push @args, 'stat';
} elsif (isPut()) {
push @args, $paramhash->{'action'};
}
} elsif ($params->{'resourcename'} eq "filesyncing") {

View File

@ -45,3 +45,27 @@ cmd:restapitest -m GET -r /nodes/$$CN/eventlog -u $$username -p $$password
check:rc==200
check:output=~eventlog
end
start:beacon_node_rest
description: get OpenBMC node beacon with REST API
hcp:openbmc
cmd:restapitest -m GET -r /nodes/$$CN/beacon -u $$username -p $$password
check:rc==200
check:output=~Front
check:output=~Rear
end
start:beacon_set_node_rest
description: set OpenBMC node beacon with REST API
hcp:openbmc
cmd:restapitest -m PUT -r /nodes/$$CN/beacon -d '{"action":"on"}' -u $$username -p $$password
check:rc==200
end
start:beacon_set_node_rest2
description: set IPMI node beacon with REST API
hcp:ipmi
cmd:restapitest -m PUT -r /nodes/$$CN/beacon -d '{"action":"on"}' -u $$username -p $$password
check:rc==200
end