diff --git a/docs/source/advanced/restapi/restapi_resource/restapi_reference.rst b/docs/source/advanced/restapi/restapi_resource/restapi_reference.rst index 15c5ca823..1d5c37fb5 100644 --- a/docs/source/advanced/restapi/restapi_resource/restapi_reference.rst +++ b/docs/source/advanced/restapi/restapi_resource/restapi_reference.rst @@ -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 ` + +**Returns:** + +* Json format: An object which includes multiple ' : {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} ---------------------------------------------------------------------------------- diff --git a/xCAT-server/xCAT-wsapi/xcatws.cgi b/xCAT-server/xCAT-wsapi/xcatws.cgi index 86bf86e9a..bc7250505 100755 --- a/xCAT-server/xCAT-wsapi/xcatws.cgi +++ b/xCAT-server/xCAT-wsapi/xcatws.cgi @@ -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") { diff --git a/xCAT-test/autotest/testcase/restapi/node/cases1 b/xCAT-test/autotest/testcase/restapi/node/cases1 index 0b03ce7b8..db848f1f2 100644 --- a/xCAT-test/autotest/testcase/restapi/node/cases1 +++ b/xCAT-test/autotest/testcase/restapi/node/cases1 @@ -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 +