From 8887485857b16b9abebcf32961270f3635aafb05 Mon Sep 17 00:00:00 2001 From: daniceexi Date: Mon, 31 Mar 2014 10:17:54 -0400 Subject: [PATCH] support subnodes resource --- xCAT-server/xCAT-wsapi/genrestapidoc.pm | 2 +- xCAT-server/xCAT-wsapi/restapi.pl | 56 ++++++++++++++++++------- 2 files changed, 42 insertions(+), 16 deletions(-) diff --git a/xCAT-server/xCAT-wsapi/genrestapidoc.pm b/xCAT-server/xCAT-wsapi/genrestapidoc.pm index 5edfec304..18d761ef7 100755 --- a/xCAT-server/xCAT-wsapi/genrestapidoc.pm +++ b/xCAT-server/xCAT-wsapi/genrestapidoc.pm @@ -7,7 +7,7 @@ my @apigroups = ( groupname => 'nodes', header => "Node Resources", desc => "The URI list which can be used to create, query, change and manage node objects.", - resources => ['allnode', 'nodeallattr', 'nodeattr', 'power', 'energy', 'energyattr', 'serviceprocessor', 'nextboot', + resources => ['allnode', 'nodeallattr', 'nodeattr', 'power', 'energy', 'energyattr', 'serviceprocessor', 'nextboot', 'subnodes', 'vitals', 'vitalsattr', 'inventory', 'inventoryattr', 'eventlog', 'beacon', 'bootstate', 'updating','filesyncing','software_maintenance','postscript', 'nodeshell', 'nodecopy', 'nodestat', 'nodehost', 'nodedns', 'nodedhcp', diff --git a/xCAT-server/xCAT-wsapi/restapi.pl b/xCAT-server/xCAT-wsapi/restapi.pl index b10d26043..c393fb60f 100755 --- a/xCAT-server/xCAT-wsapi/restapi.pl +++ b/xCAT-server/xCAT-wsapi/restapi.pl @@ -494,15 +494,19 @@ my %URIdef = ( outhdler => \&infoout, }, }, - subnode => { - desc => "[URI:/nodes/{nodename}/subnode] - The sub nodes for the node {nodename}", - matcher => '^/nodes/[^/]*/subnode$', + subnodes => { + desc => "[URI:/nodes/{nodename}/subnodes] - The sub-nodes resources for the node {nodename}", + matcher => '^/nodes/[^/]*/subnodes$', GET => { - desc => "Return the Children node for the node {nodename}.", + desc => "Return the Children nodes for the node {nodename}.", + usage => "||$usagemsg{objreturn}|", + example => "|Get all the children nodes for node \'node1\'.|GET|/nodes/node1/subnodes|{\n \"cmm01node09\":{\n \"mpa\":\"ngpcmm01\",\n \"parent\":\"ngpcmm01\",\n \"serial\":\"1035CDB\",\n \"mtm\":\"789523X\",\n \"cons\":\"fsp\",\n \"hwtype\":\"blade\",\n \"objtype\":\"node\",\n \"groups\":\"blade,all,p260\",\n \"mgt\":\"fsp\",\n \"nodetype\":\"ppc,osi\",\n \"slotid\":\"9\",\n \"hcp\":\"10.1.9.9\",\n \"id\":\"1\"\n },\n ...\n}|", cmd => "rscan", - fhandler => \&common, + fhandler => \&actionhdl, + outhdler => \&defout, }, - PUT => { + # the put should be implemented by customer that using GET to get all the resources and define it with PUT /nodes/ + PUT_bak => { desc => "Update the Children node for the node {nodename}.", cmd => "rscan", fhandler => \&common, @@ -1253,14 +1257,20 @@ sub isPatch { return uc($requestType) eq "PATCH"; } sub isDelete { return uc($requestType) eq "DELETE"; } -# handle the input like +#handle the output for def command and rscan +#handle the input like # Object name: # attr=value +#OR +# : +# attr=value # --- -# TO +#TO # --- -# nodename : value -# attr : value +# { : { +# attr : value +# ... +# } ... } sub defout { my $data = shift; @@ -1268,12 +1278,22 @@ sub defout { foreach my $d (@$data) { #my $jsonnode; my $nodename; - my $lines = $d->{info}; + my $lines; + if (defined ($d->{info})) { + $lines = $d->{info}; + } elsif (defined ($d->{data})) { + my @alldata = split ('\n', $d->{data}->[0]); + $lines = \@alldata; + } foreach my $l (@$lines) { - if ($l =~ /^Object name: /) { # start new node + if ($l =~ /^Object name: / || $l =~ /^\S+:$/) { # start new node #if (defined($jsonnode)) { push @$json, $jsonnode; $nodename=undef; $jsonnode=undef;} # push previous object onto array - $l =~ /^Object name:\s+(\S+)/; - $nodename = $1; + if ($l =~ /^Object name:\s+(\S+)/) { + $nodename = $1; + } + if ($l =~ /^(\S+):$/) { + $nodename = $1; + } } else { # just an attribute of the current node if (! $nodename) { error('improperly formatted lsdef output from xcatd', $STATUS_TEAPOT); } @@ -1284,7 +1304,9 @@ sub defout { } #if (defined($jsonnode)) { push @$json, $jsonnode; $nodename=undef; $jsonnode=undef; } # push last object onto array } - addPageContent($JSON->encode($json)); + if ($json) { + addPageContent($JSON->encode($json)); + } } # handle the input like # all (node) @@ -1574,6 +1596,10 @@ sub actionhdl { if (isDelete()) { push @args, '-d'; } + } elsif ($params->{'resourcename'} eq "subnodes") { + if (isGET()) { + push @args, '-z'; + } } push @{$request->{arg}}, @args;