2011-05-20 15:36:27 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
use strict;
|
|
|
|
use CGI qw/:standard/;
|
2012-09-22 16:20:24 +00:00
|
|
|
#use JSON; # require this dynamically later on so that installations that do not use xcatws.cgi do not need perl-JSON
|
2011-05-20 15:36:27 +00:00
|
|
|
use Data::Dumper;
|
|
|
|
|
|
|
|
#added the line:
|
|
|
|
#ScriptAlias /xcatws /var/www/cgi-bin/xcatws.cgi
|
|
|
|
#to /etc/httpd/conf/httpd.conf to hid the cgi-bin and .cgi extension in the uri
|
|
|
|
#
|
|
|
|
# also upgraded CGI to 3.52
|
|
|
|
|
|
|
|
#take the JSON or XML and put it into a data structure
|
|
|
|
#all data input will be done from the common structure
|
|
|
|
|
|
|
|
#turn on or off the debugging output
|
2012-03-20 09:16:06 +00:00
|
|
|
my $DEBUGGING = 0;
|
2012-09-26 07:18:39 +00:00
|
|
|
my $VERSION = "2.8";
|
2011-05-20 15:36:27 +00:00
|
|
|
|
2012-02-16 02:42:44 +00:00
|
|
|
my $q = CGI->new;
|
|
|
|
my $url = $q->url;
|
|
|
|
my $pathInfo = $q->path_info;
|
2011-05-20 15:36:27 +00:00
|
|
|
my $requestType = $ENV{'REQUEST_METHOD'};
|
|
|
|
my $queryString = $ENV{'QUERY_STRING'};
|
2012-02-16 13:06:45 +00:00
|
|
|
my %queryhash;
|
|
|
|
my @path = split(/\//, $pathInfo);
|
2011-05-20 15:36:27 +00:00
|
|
|
shift(@path);
|
2012-02-16 02:42:44 +00:00
|
|
|
my $resource = $path[0];
|
2012-02-13 08:42:47 +00:00
|
|
|
my $pageContent = '';
|
2012-02-16 02:42:44 +00:00
|
|
|
my $request = {clienttype => 'ws'};
|
2011-05-20 15:36:27 +00:00
|
|
|
|
|
|
|
#error status codes
|
2012-02-16 02:42:44 +00:00
|
|
|
my $STATUS_BAD_REQUEST = "400 Bad Request";
|
|
|
|
my $STATUS_UNAUTH = "401 Unauthorized";
|
|
|
|
my $STATUS_FORBIDDEN = "403 Forbidden";
|
|
|
|
my $STATUS_NOT_FOUND = "404 Not Found";
|
|
|
|
my $STATUS_NOT_ALLOWED = "405 Method Not Allowed";
|
|
|
|
my $STATUS_NOT_ACCEPTABLE = "406 Not Acceptable";
|
|
|
|
my $STATUS_TIMEOUT = "408 Request Timeout";
|
|
|
|
my $STATUS_EXPECT_FAILED = "417 Expectation Failed";
|
|
|
|
my $STATUS_TEAPOT = "418 I'm a teapot";
|
2011-05-20 15:36:27 +00:00
|
|
|
my $STATUS_SERVICE_UNAVAILABLE = "503 Service Unavailable";
|
|
|
|
|
|
|
|
#good status codes
|
2012-02-16 02:42:44 +00:00
|
|
|
my $STATUS_OK = "200 OK";
|
2011-05-20 15:36:27 +00:00
|
|
|
my $STATUS_CREATED = "201 Created";
|
|
|
|
|
2012-02-13 08:42:47 +00:00
|
|
|
#default format
|
|
|
|
my $format = 'html';
|
|
|
|
|
2012-02-16 02:42:44 +00:00
|
|
|
sub addPageContent {
|
2012-02-13 08:42:47 +00:00
|
|
|
my $newcontent = shift;
|
|
|
|
$pageContent .= $newcontent;
|
|
|
|
}
|
|
|
|
|
|
|
|
#send the response to client side
|
|
|
|
#the http only return once in each request, so all content shoudl save in a global variable,
|
|
|
|
#create the response header by status
|
2012-02-16 02:42:44 +00:00
|
|
|
sub sendResponseMsg {
|
|
|
|
my $code = shift;
|
2012-02-13 08:42:47 +00:00
|
|
|
my $tempFormat = '';
|
2012-02-16 02:42:44 +00:00
|
|
|
if ('json' eq $format) {
|
|
|
|
$tempFormat = 'application/json';
|
2012-02-13 08:42:47 +00:00
|
|
|
}
|
2012-02-16 02:42:44 +00:00
|
|
|
elsif ('xml' eq $format) {
|
|
|
|
$tempFormat = 'text/xml';
|
2012-02-13 08:42:47 +00:00
|
|
|
}
|
2012-02-16 02:42:44 +00:00
|
|
|
else {
|
|
|
|
$tempFormat = 'text/html';
|
2012-02-13 08:42:47 +00:00
|
|
|
}
|
2012-02-16 02:42:44 +00:00
|
|
|
print $q->header(-status => $code, -type => $tempFormat);
|
2012-02-13 08:42:47 +00:00
|
|
|
print $pageContent;
|
|
|
|
exit(0);
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 02:42:44 +00:00
|
|
|
sub unsupportedRequestType {
|
2012-02-13 08:42:47 +00:00
|
|
|
addPageContent("request method '$requestType' is not supported on resource '$resource'");
|
|
|
|
sendResponseMsg($STATUS_NOT_ALLOWED);
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
use XML::Simple;
|
2012-02-16 02:42:44 +00:00
|
|
|
$XML::Simple::PREFERRED_PARSER = 'XML::Parser';
|
2011-05-20 15:36:27 +00:00
|
|
|
|
2012-02-16 02:42:44 +00:00
|
|
|
sub genRequest {
|
|
|
|
if ($DEBUGGING) {
|
|
|
|
addPageContent($q->p("request " . Dumper($request)));
|
|
|
|
}
|
|
|
|
my $xml = XMLout($request, RootName => 'xcatrequest', NoAttr => 1, KeyAttr => []);
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#data formatters. To add one simple copy the format of an existing one
|
|
|
|
# and add it to this hash
|
2012-02-16 02:42:44 +00:00
|
|
|
my %formatters = (
|
|
|
|
'html' => \&wrapHtml,
|
|
|
|
'json' => \&wrapJson,
|
|
|
|
'xml' => \&wrapXml,);
|
2011-05-20 15:36:27 +00:00
|
|
|
|
2012-02-16 13:06:45 +00:00
|
|
|
fetchParameter($queryString);
|
|
|
|
|
|
|
|
if ($queryhash{'format'}) {
|
|
|
|
$format = $queryhash{'format'}->[0];
|
2012-02-16 02:42:44 +00:00
|
|
|
if (!exists $formatters{$format}) {
|
|
|
|
addPageContent("The format '$format' is not valid");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
2012-09-22 16:20:24 +00:00
|
|
|
|
|
|
|
if ($format eq 'json') {
|
|
|
|
# require JSON dynamically and let them know if it is not installed
|
|
|
|
my $jsoninstalled = eval { require JSON; };
|
|
|
|
unless ($jsoninstalled) {
|
2012-09-26 07:43:12 +00:00
|
|
|
addPageContent('{"data":"JSON perl module missing. Install perl-JSON before using the xCAT REST web services API."}');
|
2012-09-22 16:20:24 +00:00
|
|
|
sendResponseMsg($STATUS_SERVICE_UNAVAILABLE);
|
|
|
|
}
|
|
|
|
}
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
my $XCAT_PATH = '/opt/xcat/bin';
|
|
|
|
|
2011-06-14 18:58:31 +00:00
|
|
|
#resource handlers
|
2012-02-16 02:42:44 +00:00
|
|
|
my %resources = (
|
|
|
|
groups => \&groupsHandler,
|
|
|
|
images => \&imagesHandler,
|
|
|
|
logs => \&logsHandler,
|
|
|
|
monitors => \&monitorsHandler,
|
|
|
|
networks => \&networksHandler,
|
|
|
|
nodes => \&nodesHandler,
|
|
|
|
notifications => \¬ificationsHandler,
|
|
|
|
policies => \&policiesHandler,
|
|
|
|
site => \&siteHandler,
|
|
|
|
tables => \&tablesHandler,
|
|
|
|
accounts => \&accountsHandler,
|
|
|
|
objects => \&objectsHandler,
|
2012-02-27 15:44:59 +00:00
|
|
|
vms => \&vmsHandler,
|
2013-06-19 16:16:51 +00:00
|
|
|
debug => \&debugHandler,
|
|
|
|
hypervisor => \&hypervisorHandler,
|
2012-02-27 15:44:59 +00:00
|
|
|
version => \&versionHandler);
|
2011-05-20 15:36:27 +00:00
|
|
|
|
2011-06-14 18:58:31 +00:00
|
|
|
#if no resource was specified
|
2012-02-16 02:42:44 +00:00
|
|
|
if ($pathInfo =~ /^\/$/ || $pathInfo =~ /^$/) {
|
2012-02-13 08:42:47 +00:00
|
|
|
addPageContent($q->p("This is the root page for the xCAT Rest Web Service. Available resources are:"));
|
2012-02-16 02:42:44 +00:00
|
|
|
foreach (sort keys %resources) {
|
|
|
|
addPageContent($q->p($_));
|
2012-02-13 08:42:47 +00:00
|
|
|
}
|
|
|
|
sendResponseMsg($STATUS_OK);
|
2011-06-14 18:58:31 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 02:42:44 +00:00
|
|
|
sub doesResourceExist {
|
2012-02-13 08:42:47 +00:00
|
|
|
my $res = shift;
|
|
|
|
return exists $resources{$res};
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 02:42:44 +00:00
|
|
|
if ($DEBUGGING) {
|
|
|
|
if (defined $q->param('PUTDATA')) {
|
|
|
|
addPageContent("put data " . $q->p($q->param('PUTDATA') . "\n"));
|
2013-06-19 16:16:51 +00:00
|
|
|
} elsif (isPut()) {
|
|
|
|
my $entries = JSON::decode_json($q->param('PUTDATA'));
|
|
|
|
if (scalar(@$entries) >= 1) {
|
|
|
|
addPageContent("put data \n");
|
|
|
|
foreach (@$entries) {
|
|
|
|
addPageContent("$_\n");
|
|
|
|
}
|
|
|
|
}
|
2012-02-13 08:42:47 +00:00
|
|
|
}
|
2013-06-19 16:16:51 +00:00
|
|
|
|
2012-02-16 02:42:44 +00:00
|
|
|
if (defined $q->param('POSTDATA')) {
|
|
|
|
addPageContent("post data " . $q->p($q->param('POSTDATA') . "\n"));
|
2013-06-19 16:16:51 +00:00
|
|
|
} elsif (isPost()) {
|
|
|
|
my $entries = JSON::decode_json($q->param('POSTDATA'));
|
|
|
|
if (scalar(@$entries) >= 1) {
|
|
|
|
addPageContent("post data \n");
|
|
|
|
foreach (@$entries) {
|
|
|
|
addPageContent("$_\n");
|
|
|
|
}
|
|
|
|
}
|
2012-02-13 08:42:47 +00:00
|
|
|
}
|
2013-06-19 16:16:51 +00:00
|
|
|
|
2012-02-13 08:42:47 +00:00
|
|
|
addPageContent($q->p("Parameters "));
|
|
|
|
my @params = $q->param;
|
2012-02-16 02:42:44 +00:00
|
|
|
foreach (@params) {
|
|
|
|
addPageContent("$_ = " . join(',', $q->param($_)) . "\n");
|
|
|
|
}
|
|
|
|
addPageContent($q->p("Query String $queryString" . "\n"));
|
2012-02-16 13:06:45 +00:00
|
|
|
addPageContent($q->p("Query parameters from the Query String" . Dumper(\%queryhash) . "\n"));
|
2012-02-16 02:42:44 +00:00
|
|
|
addPageContent($q->p("HTTP Method $requestType" . "\n"));
|
|
|
|
addPageContent($q->p("URI $url" . "\n"));
|
|
|
|
addPageContent($q->p("path " . Dumper(@path) . "\n"));
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 13:06:45 +00:00
|
|
|
#when use put and post, can not fetch the url-parameter, so add this sub to support all kinks of method
|
|
|
|
sub fetchParameter {
|
|
|
|
my $parstr = shift;
|
|
|
|
unless ($parstr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
my @pairs = split(/&/, $parstr);
|
|
|
|
foreach my $pair (@pairs) {
|
2012-08-06 21:04:24 +00:00
|
|
|
my ($key, $value) = split(/=/, $pair, 2);
|
2012-02-16 13:06:45 +00:00
|
|
|
$value =~ tr/+/ /;
|
|
|
|
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/chr(hex($1))/eg;
|
|
|
|
push @{$queryhash{$key}}, $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-15 06:54:28 +00:00
|
|
|
#extract the put data or post data into perl hash, easy for retrieve
|
|
|
|
sub extractData {
|
|
|
|
my $temphash = shift;
|
|
|
|
my $parArray = shift;
|
|
|
|
my $key;
|
|
|
|
my $value;
|
|
|
|
my $position;
|
|
|
|
|
|
|
|
#traversal all element in the array
|
|
|
|
foreach (@$parArray) {
|
|
|
|
$position = index($_, '=');
|
|
|
|
if ($position < 0) {
|
|
|
|
$key = $_;
|
|
|
|
$value = 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$key = substr $_, 0, $position;
|
|
|
|
$value = substr $_, $position + 1;
|
|
|
|
}
|
|
|
|
$temphash->{$key} = $value;
|
|
|
|
|
|
|
|
if ($DEBUGGING) {
|
|
|
|
addPageContent($q->p("The parameter extract from put/post data:<br/>" . Dumper($temphash)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-14 19:19:19 +00:00
|
|
|
my $userName=http('userName');
|
|
|
|
my $password=http('password');
|
2011-05-20 15:36:27 +00:00
|
|
|
|
2012-02-16 02:42:44 +00:00
|
|
|
sub handleRequest {
|
2012-02-16 13:06:45 +00:00
|
|
|
if (defined $queryhash{'userName'}) {
|
|
|
|
$userName = $queryhash{'userName'}->[0];
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
2012-02-16 13:06:45 +00:00
|
|
|
if (defined $queryhash{'password'}) {
|
|
|
|
$password = $queryhash{'password'}->[0];
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
|
|
|
if ($userName && $password) {
|
|
|
|
$request->{becomeuser}->[0]->{username}->[0] = $userName;
|
|
|
|
$request->{becomeuser}->[0]->{password}->[0] = $password;
|
|
|
|
}
|
|
|
|
my @data = $resources{$resource}->();
|
|
|
|
wrapData(\@data);
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
my @groupFields = ('groupname', 'grouptype', 'members', 'wherevals', 'comments', 'disable');
|
|
|
|
|
|
|
|
#get is done
|
|
|
|
#post and delete are done but not tested
|
|
|
|
#groupfiles4dsh is done but not tested
|
2012-02-16 02:42:44 +00:00
|
|
|
sub groupsHandler {
|
|
|
|
my @responses;
|
|
|
|
my @args;
|
|
|
|
my $groupName;
|
|
|
|
|
|
|
|
#is the group name in the URI?
|
|
|
|
if (defined $path[1]) {
|
|
|
|
$groupName = $path[1];
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
2012-02-16 02:42:44 +00:00
|
|
|
|
|
|
|
#in the query string?
|
2011-05-20 15:36:27 +00:00
|
|
|
else {
|
2012-02-16 02:42:44 +00:00
|
|
|
$groupName = $q->param('groupName');
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
2012-02-16 02:42:44 +00:00
|
|
|
|
|
|
|
if (isGet()) {
|
|
|
|
if (defined $groupName) {
|
|
|
|
$request->{command} = 'tabget';
|
|
|
|
push @args, "groupname=$groupName";
|
|
|
|
if (defined $q->param('field')) {
|
|
|
|
foreach ($q->param('field')) {
|
|
|
|
push @args, "nodegroup.$_";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
foreach (@groupFields) {
|
|
|
|
push @args, "nodegroup.$_";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$request->{command} = 'tabdump';
|
|
|
|
push @args, 'nodegroup';
|
|
|
|
}
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
2012-02-16 02:42:44 +00:00
|
|
|
|
|
|
|
#does it make sense to even have this?
|
|
|
|
elsif (isPost()) {
|
|
|
|
my $nodeRange = $q->param('nodeRange');
|
|
|
|
if ((defined $groupName) && (defined $nodeRange)) {
|
|
|
|
$request->{command} = 'mkdef';
|
|
|
|
push @args, '-t';
|
|
|
|
push @args, 'group';
|
|
|
|
push @args, '-o';
|
|
|
|
push @args, $groupName;
|
|
|
|
push @args, "members=$nodeRange";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
addPageContent("A node range and group name must be specified for creating a group");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif (isPut()) {
|
|
|
|
|
|
|
|
#handle groupfiles4dsh -p /tmp/nodegroupfiles
|
|
|
|
if ($q->param('command') eq "4dsh") {
|
|
|
|
if ($q->param('path')) {
|
|
|
|
$request->{command} = 'groupfiles4dsh';
|
|
|
|
push @args, "p=$q->param('path')";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
addPageContent("The path must be specified for creating directories for dsh");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (defined $groupName && defined $q->param('fields')) {
|
|
|
|
$request->{command} = 'nodegrpch';
|
|
|
|
push @args, $groupName;
|
|
|
|
push @args, $q->param('field');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
addPageContent("The group and fields must be specified to update groups");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif (isDelete()) {
|
|
|
|
if (defined $groupName) {
|
|
|
|
$request->{command} = 'rmdef';
|
|
|
|
push @args, '-d';
|
|
|
|
push @args, 'group';
|
|
|
|
push @args, '-o';
|
|
|
|
push @args, $groupName;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
addPageContent("The group must be specified to delete a group");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
unsupportedRequestType();
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
push @{$request->{arg}}, @args;
|
|
|
|
my $req = genRequest();
|
|
|
|
@responses = sendRequest($req);
|
|
|
|
|
|
|
|
return @responses;
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 02:42:44 +00:00
|
|
|
my @imageFields = (
|
|
|
|
'imagename', 'profile', 'imagetype', 'provmethod', 'osname', 'osvers',
|
|
|
|
'osdistro', 'osarch', 'synclists', 'comments', 'disable');
|
2011-05-20 15:36:27 +00:00
|
|
|
|
|
|
|
#get is done, nothing else
|
2012-02-16 02:42:44 +00:00
|
|
|
sub imagesHandler {
|
|
|
|
my @responses;
|
|
|
|
my @args;
|
|
|
|
my $image;
|
2012-03-19 09:31:33 +00:00
|
|
|
my $subResource;
|
2012-02-16 02:42:44 +00:00
|
|
|
|
|
|
|
if (defined($path[1])) {
|
|
|
|
$image = $path[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isGet()) {
|
2012-03-19 08:50:55 +00:00
|
|
|
$request->{command} = 'lsdef';
|
|
|
|
push @args, '-t', 'osimage';
|
2012-02-16 02:42:44 +00:00
|
|
|
if (defined $image) {
|
2012-03-19 08:50:55 +00:00
|
|
|
push @args, '-o', $image;
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
2012-03-19 08:50:55 +00:00
|
|
|
if (defined($q->param('field'))) {
|
|
|
|
push @args, '-i';
|
|
|
|
push @args, join(',', $q->param('field'));
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
2013-06-19 16:16:51 +00:00
|
|
|
if (defined($q->param('criteria'))) {
|
|
|
|
foreach ($q->param('criteria')) {
|
|
|
|
push @args, '-w', "$_";
|
|
|
|
}
|
|
|
|
}
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
|
|
|
elsif (isPost()) {
|
2012-03-20 07:54:21 +00:00
|
|
|
my $operationname = $image;
|
|
|
|
my $entries;
|
|
|
|
my %entryhash;
|
|
|
|
|
|
|
|
#check the post data
|
|
|
|
unless (defined($q->param('POSTDATA'))) {
|
|
|
|
addPageContent("Invalid Parameters");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
2013-01-16 21:02:09 +00:00
|
|
|
$entries = JSON::decode_json($q->param('POSTDATA'));
|
2012-03-20 07:54:21 +00:00
|
|
|
if (scalar(@$entries) < 1) {
|
|
|
|
addPageContent("No set attribute was supplied.");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
|
|
|
|
|
|
|
extractData(\%entryhash, $entries);
|
|
|
|
|
|
|
|
#for image capture
|
|
|
|
if ($operationname eq 'capture') {
|
|
|
|
$request->{command} = 'imgcapture';
|
|
|
|
if (defined($entryhash{'nodename'})) {
|
|
|
|
$request->{noderange} = $entryhash{'nodename'};
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
addPageContent('No node range.');
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defined($entryhash{'profile'})) {
|
|
|
|
push @args, '-p';
|
|
|
|
push @args, $entryhash{'profile'};
|
|
|
|
}
|
|
|
|
if (defined($entryhash{'osimage'})) {
|
|
|
|
push @args, '-o';
|
|
|
|
push @args, $entryhash{'osimage'};
|
|
|
|
}
|
|
|
|
if (defined($entryhash{'bootinterface'})) {
|
|
|
|
push @args, '-i';
|
|
|
|
push @args, $entryhash{'bootinterface'};
|
|
|
|
}
|
|
|
|
if (defined($entryhash{'netdriver'})) {
|
|
|
|
push @args, '-n';
|
|
|
|
push @args, $entryhash{'netdriver'};
|
|
|
|
}
|
2013-06-19 16:16:51 +00:00
|
|
|
if (defined($entryhash{'device'})) {
|
|
|
|
push @args, '-d';
|
|
|
|
push @args, $entryhash{'device'};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif ($operationname eq 'export') {
|
|
|
|
$request->{command} = 'imgexport';
|
|
|
|
if (defined($entryhash{'osimage'})) {
|
|
|
|
push @args, $entryhash{'osimage'};
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
addPageContent('No image specified');
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defined($entryhash{'destination'})) {
|
|
|
|
push @args, $entryhash{'destination'};
|
|
|
|
}
|
|
|
|
if (defined($entryhash{'postscripts'})) {
|
|
|
|
push @args, '-p';
|
|
|
|
push @args, $entryhash{'postscripts'};
|
|
|
|
}
|
|
|
|
if (defined($entryhash{'extra'})) {
|
|
|
|
push @args, '-e';
|
|
|
|
push @args, $entryhash{'extra'};
|
|
|
|
}
|
|
|
|
if (defined($entryhash{'remotehost'})) {
|
|
|
|
push @args, '-R';
|
|
|
|
push @args, $entryhash{'remotehost'};
|
|
|
|
}
|
|
|
|
if (defined($entryhash{'verbose'})) {
|
|
|
|
push @args, '-v';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif ($operationname eq 'import') {
|
|
|
|
$request->{command} = 'imgimport';
|
|
|
|
if (defined($entryhash{'osimage'})) {
|
|
|
|
push @args, $entryhash{'osimage'};
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
addPageContent('No image specified');
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defined($entryhash{'profile'})) {
|
|
|
|
push @args, '-f';
|
|
|
|
push @args, $entryhash{'profile'};
|
|
|
|
}
|
|
|
|
if (defined($entryhash{'remotehost'})) {
|
|
|
|
push @args, '-R';
|
|
|
|
push @args, $entryhash{'remotehost'};
|
|
|
|
}
|
|
|
|
if (defined($entryhash{'postscripts'})) {
|
|
|
|
push @args, '-p';
|
|
|
|
push @args, $entryhash{'postscripts'};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defined($entryhash{'verbose'})) {
|
|
|
|
push @args, '-v';
|
|
|
|
}
|
|
|
|
}
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
2012-03-19 09:31:33 +00:00
|
|
|
elsif (isPut()) {
|
|
|
|
|
|
|
|
#check the operation type
|
|
|
|
unless (defined $path[2]) {
|
|
|
|
addPageContent("The subResource $subResource does not exist");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
|
|
|
|
|
|
|
$subResource = $path[2];
|
2012-02-16 02:42:44 +00:00
|
|
|
|
2012-03-19 09:31:33 +00:00
|
|
|
#check the image name
|
|
|
|
unless (defined $image) {
|
|
|
|
addPageContent("The image name is required to clean an os image");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($subResource eq 'check') {
|
|
|
|
$request->{command} = 'chkosimage';
|
|
|
|
if (defined($q->param('PUTDATA'))) {
|
2012-02-16 02:42:44 +00:00
|
|
|
push @args, '-c';
|
|
|
|
}
|
2012-03-19 09:31:33 +00:00
|
|
|
push @args, $image;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
addPageContent("The subResource $subResource does not exist");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif (isDelete()) {
|
|
|
|
if (defined $image) {
|
|
|
|
$request->{command} = 'rmimage';
|
|
|
|
if (defined $q->param('verbose')) {
|
|
|
|
push @args, '-v';
|
|
|
|
}
|
|
|
|
push @args, $image;
|
|
|
|
}
|
|
|
|
elsif (defined $q->param('os') && defined $q->param('arch') && defined $q->param('profile')) {
|
|
|
|
push @args, '-o';
|
|
|
|
push @args, $q->param('os');
|
|
|
|
push @args, '-a';
|
|
|
|
push @args, $q->param('arch');
|
|
|
|
push @args, '-p';
|
|
|
|
push @args, $q->param('profile');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
addPageContent(
|
|
|
|
"Either the image name or the os, architecture and profile must be specified to remove an image");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
unsupportedRequestType();
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
push @{$request->{arg}}, @args;
|
|
|
|
my $req = genRequest();
|
|
|
|
@responses = sendRequest($req);
|
|
|
|
|
|
|
|
return @responses;
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#complete
|
2012-02-16 02:42:44 +00:00
|
|
|
sub logsHandler {
|
|
|
|
my @responses;
|
|
|
|
my @args;
|
|
|
|
my $logType;
|
|
|
|
|
|
|
|
if (defined $path[1]) {
|
|
|
|
$logType = $path[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
#in the query string?
|
|
|
|
else {
|
|
|
|
$logType = $q->param('logType');
|
|
|
|
}
|
|
|
|
my $nodeRange = $q->param('nodeRange');
|
|
|
|
|
|
|
|
#no real output unless the log type is defined
|
|
|
|
if (!defined $logType) {
|
|
|
|
addPageContent("Current logs available are auditlog and eventlog");
|
2012-02-13 08:42:47 +00:00
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
2012-02-16 02:42:44 +00:00
|
|
|
exit(0);
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
2012-02-16 02:42:44 +00:00
|
|
|
|
|
|
|
if (isGet()) {
|
|
|
|
if ($logType eq "reventLog") {
|
|
|
|
if (defined $nodeRange) {
|
|
|
|
$request->{command} = 'reventlog';
|
|
|
|
push @args, $nodeRange;
|
|
|
|
if (defined $q->param('count')) {
|
|
|
|
push @args, $q->param('count');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
addPageContent("nodeRange must be specified to GET remote event logs");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$request->{command} = 'tabdump';
|
|
|
|
push @args, $logType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#this clears the log
|
|
|
|
elsif (isPut()) {
|
|
|
|
if ($logType eq "reventlog") {
|
|
|
|
if (defined $nodeRange) {
|
|
|
|
$request->{command} = 'reventlog';
|
|
|
|
push @args, $nodeRange;
|
|
|
|
push @args, 'clear';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
addPageContent("nodeRange must be specified to clean remote event logs");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
#should it return the removed entries?
|
|
|
|
if (defined $q->param('showRemoved')) {
|
|
|
|
push @args, '-V';
|
|
|
|
}
|
|
|
|
if (defined $q->param('count') || defined $q->param('percent') || defined $q->param('lastRecord')) {
|
|
|
|
|
|
|
|
#remove some of the entries
|
|
|
|
$request->{command} = 'tabprune';
|
|
|
|
|
|
|
|
#remove a certain number of records
|
|
|
|
if (defined $q->param('count')) {
|
|
|
|
push @args, ('-n', $q->param('count'));
|
|
|
|
}
|
|
|
|
|
|
|
|
#remove a percentage of the records
|
|
|
|
if (defined $q->param('percent')) {
|
|
|
|
push @args, ('-p', $q->param('percent'));
|
|
|
|
}
|
|
|
|
|
|
|
|
#remove all records before this record
|
|
|
|
if (defined $q->param('lastRecord')) {
|
|
|
|
push @args, ('-i', $q->param('lastRecord'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$request->{command} = 'tabprune';
|
|
|
|
|
|
|
|
#-a removes all
|
|
|
|
push @args, '-a';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
unsupportedRequestType();
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
push @{$request->{arg}}, @args;
|
|
|
|
my $req = genRequest();
|
|
|
|
@responses = sendRequest($req);
|
|
|
|
|
|
|
|
return @responses;
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#complete
|
2012-02-16 02:42:44 +00:00
|
|
|
sub monitorsHandler {
|
|
|
|
my @responses;
|
|
|
|
my @args;
|
|
|
|
my $monitor;
|
|
|
|
|
|
|
|
if (defined $path[1]) {
|
|
|
|
$monitor = $path[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
#in the query string?
|
|
|
|
elsif (defined $q->param('monitor')) {
|
|
|
|
push @args, $q->param('monitor');
|
|
|
|
}
|
|
|
|
if (defined $monitor) {
|
|
|
|
push @args, $monitor;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isGet()) {
|
|
|
|
$request->{command} = 'monls';
|
|
|
|
}
|
|
|
|
elsif (isPost()) {
|
|
|
|
$request->{command} = 'monadd';
|
|
|
|
if ($q->param('nodeStatMon')) {
|
|
|
|
push @args, '-n';
|
|
|
|
}
|
|
|
|
|
|
|
|
#get the plug-in specific settings array
|
|
|
|
foreach ($q->param('pluginSetting')) {
|
|
|
|
push @args, '-s';
|
|
|
|
push @args, $_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif (isDelete()) {
|
|
|
|
$request->{command} = 'monrm';
|
|
|
|
}
|
|
|
|
elsif (isPut() || isPatch()) {
|
|
|
|
my $action = $q->param('action');
|
|
|
|
if ($action eq "start") {
|
|
|
|
$request->{command} = 'monstart';
|
|
|
|
}
|
|
|
|
elsif ($action eq "stop") {
|
|
|
|
$request->{command} = 'monstop';
|
|
|
|
}
|
|
|
|
elsif ($action eq "config") {
|
|
|
|
$request->{command} = 'moncfg';
|
|
|
|
}
|
|
|
|
elsif ($action eq "deconfig") {
|
|
|
|
$request->{command} = 'mondeconfig';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
unsupportedRequestType();
|
|
|
|
}
|
|
|
|
if (!defined $q->param('nodeRange')) {
|
|
|
|
|
|
|
|
#error
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
push @args, $q->param('nodeRange');
|
|
|
|
}
|
|
|
|
if (defined $q->param('remote')) {
|
|
|
|
push @args, '-r';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
unsupportedRequestType();
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
push @{$request->{arg}}, @args;
|
|
|
|
my $req = genRequest();
|
|
|
|
@responses = sendRequest($req);
|
|
|
|
|
|
|
|
return @responses;
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 02:42:44 +00:00
|
|
|
sub networksHandler {
|
|
|
|
my @responses;
|
|
|
|
my @args;
|
2012-02-17 07:08:17 +00:00
|
|
|
my $netname = '';
|
2011-05-20 15:36:27 +00:00
|
|
|
|
2012-02-16 02:42:44 +00:00
|
|
|
if (isGet()) {
|
2012-02-17 07:08:17 +00:00
|
|
|
$request->{command} = 'lsdef';
|
|
|
|
push @{$request->{arg}}, '-t', 'network';
|
|
|
|
if (defined($path[1])) {
|
2012-02-21 05:30:56 +00:00
|
|
|
push @{$request->{arg}}, '-o', $path[1];
|
|
|
|
}
|
|
|
|
my @temparray = $q->param('field');
|
|
|
|
|
|
|
|
#add the field name to get
|
|
|
|
if (scalar(@temparray) > 0) {
|
|
|
|
push @{$request->{arg}}, '-i';
|
|
|
|
push @{$request->{arg}}, join(',', @temparray),;
|
2012-02-17 07:08:17 +00:00
|
|
|
}
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
2012-02-17 07:08:17 +00:00
|
|
|
elsif (isPut() || isPost()) {
|
|
|
|
my $entries;
|
2013-06-19 16:16:51 +00:00
|
|
|
my $iscommand = 0;
|
2012-02-17 07:08:17 +00:00
|
|
|
if (isPut()) {
|
|
|
|
$request->{command} = 'chdef';
|
2013-06-19 16:16:51 +00:00
|
|
|
if (defined($path[1])) {
|
|
|
|
if ($path[1] eq "makehosts" || $path[1] eq "makedns") {
|
|
|
|
# Issue makehost/makedns directly
|
|
|
|
$request->{command} = $path[1];
|
|
|
|
$iscommand = 1;
|
|
|
|
}
|
|
|
|
}
|
2012-02-17 07:08:17 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$request->{command} = 'mkdef';
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
|
|
|
|
2013-06-19 16:16:51 +00:00
|
|
|
if (!$iscommand) {
|
|
|
|
if (defined $path[1]) {
|
|
|
|
$netname = $path[1];
|
|
|
|
}
|
2012-02-16 02:42:44 +00:00
|
|
|
|
2013-06-19 16:16:51 +00:00
|
|
|
if ($netname eq '') {
|
|
|
|
addPageContent('A network name must be specified.');
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
|
|
|
|
|
|
|
push @{$request->{arg}}, '-t', 'network', '-o', $netname;
|
|
|
|
|
|
|
|
if (defined($q->param('PUTDATA'))) {
|
|
|
|
$entries = JSON::decode_json($q->param('PUTDATA'));
|
|
|
|
}
|
|
|
|
elsif (defined($q->param('POSTDATA'))) {
|
|
|
|
$entries = JSON::decode_json($q->param('POSTDATA'));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
addPageContent("No Field and Value map was supplied.");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
2012-02-22 02:24:16 +00:00
|
|
|
|
2013-06-19 16:16:51 +00:00
|
|
|
if (scalar($entries) < 1) {
|
|
|
|
addPageContent("No Field and Value map was supplied.");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
|
|
|
foreach (@$entries) {
|
|
|
|
push @{$request->{arg}}, $_;
|
|
|
|
}
|
2012-02-22 02:24:16 +00:00
|
|
|
}
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
|
|
|
elsif (isDelete()) {
|
2012-02-17 07:08:17 +00:00
|
|
|
$request->{command} = 'rmdef';
|
2012-02-16 02:42:44 +00:00
|
|
|
|
2012-02-17 07:08:17 +00:00
|
|
|
if (defined $path[1]) {
|
|
|
|
$netname = $path[1];
|
|
|
|
}
|
|
|
|
if ($netname eq '') {
|
|
|
|
addPageContent('A network name must be specified.');
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
|
|
|
push @{$request->{arg}}, '-t', 'network', '-o', $netname;
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
unsupportedRequestType();
|
|
|
|
exit(0);
|
|
|
|
}
|
2012-02-17 07:08:17 +00:00
|
|
|
@responses = sendRequest(genRequest());
|
2012-02-16 02:42:44 +00:00
|
|
|
|
|
|
|
return @responses;
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 02:42:44 +00:00
|
|
|
sub nodesHandler {
|
|
|
|
my @responses;
|
|
|
|
my @args;
|
2012-02-22 02:24:16 +00:00
|
|
|
my $noderange;
|
2013-06-19 16:16:51 +00:00
|
|
|
my @envs;
|
2012-02-16 02:42:44 +00:00
|
|
|
|
|
|
|
if (defined $path[1]) {
|
2012-02-22 02:24:16 +00:00
|
|
|
$noderange = $path[1];
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isGet()) {
|
|
|
|
my $subResource;
|
|
|
|
if (defined $path[2]) {
|
|
|
|
$subResource = $path[2];
|
2012-02-24 07:10:55 +00:00
|
|
|
unless (defined($noderange)) {
|
|
|
|
addPageContent("Invalid nodes and/or groups in noderange");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
|
|
|
$request->{noderange} = $noderange;
|
2012-02-16 02:42:44 +00:00
|
|
|
|
2012-02-24 07:10:55 +00:00
|
|
|
#use the corresponding command by the subresource name
|
|
|
|
if ($subResource eq "power") {
|
|
|
|
$request->{command} = 'rpower';
|
|
|
|
push @args, 'stat';
|
|
|
|
}
|
|
|
|
elsif ($subResource eq "energy") {
|
|
|
|
$request->{command} = 'renergy';
|
2012-02-16 02:42:44 +00:00
|
|
|
|
2012-02-24 07:10:55 +00:00
|
|
|
#no fields will default to 'all'
|
|
|
|
if (defined $q->param('field')) {
|
|
|
|
push @args, $q->param('field');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
push @args, 'all';
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
|
|
|
}
|
2012-02-24 07:10:55 +00:00
|
|
|
elsif ($subResource eq "status") {
|
|
|
|
$request->{command} = 'nodestat';
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
2012-02-24 07:10:55 +00:00
|
|
|
elsif ($subResource eq "inventory") {
|
|
|
|
$request->{command} = 'rinv';
|
|
|
|
if (defined $q->param('field')) {
|
|
|
|
push @args, $q->param('field');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
push @args, 'all';
|
|
|
|
}
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
2012-02-24 07:10:55 +00:00
|
|
|
elsif ($subResource eq "vitals") {
|
|
|
|
$request->{command} = 'rvitals';
|
|
|
|
if (defined $q->param('field')) {
|
|
|
|
push @args, $q->param('field');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
push @args, 'all';
|
|
|
|
}
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
2013-06-19 16:16:51 +00:00
|
|
|
elsif ($subResource eq "scan") {
|
|
|
|
$request->{command} = 'rscan';
|
|
|
|
if (defined $q->param('field')) {
|
|
|
|
push @args, $q->param('field');
|
|
|
|
}
|
|
|
|
}
|
2012-02-16 02:42:44 +00:00
|
|
|
else {
|
2012-02-24 07:10:55 +00:00
|
|
|
addPageContent("Unspported operation on nodes object.");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2012-02-16 13:06:45 +00:00
|
|
|
$request->{command} = 'lsdef';
|
2012-02-22 02:24:16 +00:00
|
|
|
push @args, "-t", "node";
|
2012-02-16 02:42:44 +00:00
|
|
|
|
2012-02-22 02:24:16 +00:00
|
|
|
#add the nodegroup into args
|
|
|
|
if (defined($noderange)) {
|
|
|
|
push @args, "-o", $noderange;
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#maybe it's specified in the parameters
|
2012-02-22 02:24:16 +00:00
|
|
|
my @temparray = $q->param('field');
|
|
|
|
if (scalar(@temparray) > 0) {
|
|
|
|
push @args, "-i";
|
|
|
|
push @args, join(',', @temparray);
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif (isPut()) {
|
|
|
|
my $subResource;
|
2012-08-06 21:04:24 +00:00
|
|
|
my @entries;
|
2013-06-19 16:16:51 +00:00
|
|
|
my $entrydata;
|
|
|
|
|
|
|
|
unless (defined($noderange)) {
|
|
|
|
addPageContent("Invalid nodes and/or groups in noderange");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
|
|
|
$request->{noderange} = $noderange;
|
|
|
|
|
|
|
|
unless ($q->param('PUTDATA')) {
|
|
|
|
#temporary allowance for the put data to be contained in the queryString
|
|
|
|
unless ($queryhash{'putData'}) {
|
|
|
|
addPageContent("No set attribute was supplied.");
|
2012-02-24 07:10:55 +00:00
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
2013-06-19 16:16:51 +00:00
|
|
|
else {
|
|
|
|
foreach my $put (@{$queryhash{'putData'}}) {
|
|
|
|
my ($key, $value) = split(/=/, $put, 2);
|
|
|
|
if ($key eq 'field' && $value) {
|
|
|
|
push @entries, $value;
|
2012-08-06 21:04:24 +00:00
|
|
|
}
|
|
|
|
}
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
2013-06-19 16:16:51 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
@entries = JSON::decode_json($q->param('PUTDATA'));
|
|
|
|
if (scalar(@entries) < 1) {
|
|
|
|
addPageContent("No set attribute was supplied.");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
2013-06-19 16:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (defined $path[2]) {
|
|
|
|
$subResource = $path[2];
|
2012-02-24 07:10:55 +00:00
|
|
|
|
2012-03-15 06:54:28 +00:00
|
|
|
if (($subResource ne "dsh") && ($subResource ne "dcp")) {
|
2013-06-19 16:16:51 +00:00
|
|
|
# For any function other than "dsh" or "dcp",
|
|
|
|
# move all operands to the argument list.
|
2012-08-06 21:04:24 +00:00
|
|
|
foreach (@entries) {
|
2013-06-19 16:16:51 +00:00
|
|
|
if (ref($_) eq 'ARRAY') {
|
|
|
|
foreach (@$_) {
|
|
|
|
push @args, $_;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
push @args, $_;
|
|
|
|
}
|
2012-03-15 06:54:28 +00:00
|
|
|
}
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
2012-02-24 07:10:55 +00:00
|
|
|
if ($subResource eq "power") {
|
|
|
|
$request->{command} = "rpower";
|
2013-06-19 16:16:51 +00:00
|
|
|
my %elements;
|
|
|
|
extractData(\%elements, @entries);
|
|
|
|
|
|
|
|
unless (scalar(%elements)) {
|
|
|
|
addPageContent("No power operands were supplied.");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
2012-02-24 07:10:55 +00:00
|
|
|
}
|
|
|
|
elsif ($subResource eq "energy") {
|
|
|
|
$request->{command} = "renergy";
|
|
|
|
}
|
2013-06-19 16:16:51 +00:00
|
|
|
elsif ($subResource eq "bootstate") {
|
2012-02-24 07:10:55 +00:00
|
|
|
$request->{command} = "nodeset";
|
|
|
|
}
|
|
|
|
elsif ($subResource eq "bootseq") {
|
|
|
|
$request->{command} = "rbootseq";
|
|
|
|
}
|
|
|
|
elsif ($subResource eq "setboot") {
|
|
|
|
$request->{command} = "rsetboot";
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
2013-06-19 16:16:51 +00:00
|
|
|
elsif ($subResource eq "migrate") {
|
|
|
|
$request->{command} = "rmigrate";
|
|
|
|
}
|
2012-03-15 06:54:28 +00:00
|
|
|
elsif ($subResource eq "dsh") {
|
|
|
|
$request->{command} = "xdsh";
|
|
|
|
my %elements;
|
2012-08-06 21:04:24 +00:00
|
|
|
extractData(\%elements, @entries);
|
2012-03-15 07:08:32 +00:00
|
|
|
if (defined($elements{'devicetype'})) {
|
2012-03-15 06:54:28 +00:00
|
|
|
push @args, '--devicetype';
|
|
|
|
push @args, $elements{'devicetype'};
|
|
|
|
}
|
2012-03-15 07:08:32 +00:00
|
|
|
if (defined($elements{'execute'})) {
|
2012-03-15 06:54:28 +00:00
|
|
|
push @args, '-e';
|
|
|
|
}
|
2012-03-15 07:08:32 +00:00
|
|
|
if (defined($elements{'environment'})) {
|
2012-03-15 06:54:28 +00:00
|
|
|
push @args, '-E';
|
|
|
|
push @args, $elements{'environment'};
|
|
|
|
}
|
2012-03-15 07:08:32 +00:00
|
|
|
if (defined($elements{'fanout'})) {
|
2012-03-15 06:54:28 +00:00
|
|
|
push @args, '-f';
|
|
|
|
push @args, $elements{'fanout'};
|
|
|
|
}
|
2012-03-15 07:08:32 +00:00
|
|
|
if (defined($elements{'nolocale'})) {
|
2012-03-15 06:54:28 +00:00
|
|
|
push @args, '-L';
|
|
|
|
}
|
2012-03-15 07:08:32 +00:00
|
|
|
if (defined($elements{'userid'})) {
|
2012-03-15 06:54:28 +00:00
|
|
|
push @args, '-l';
|
|
|
|
push @args, $elements{'userid'};
|
|
|
|
}
|
2012-03-15 07:08:32 +00:00
|
|
|
if (defined($elements{'monitor'})) {
|
2012-03-15 06:54:28 +00:00
|
|
|
push @args, '-m';
|
|
|
|
}
|
2012-03-15 07:08:32 +00:00
|
|
|
if (defined($elements{'options'})) {
|
2012-03-15 06:54:28 +00:00
|
|
|
push @args, '-o';
|
|
|
|
push @args, $elements{'options'};
|
|
|
|
}
|
2012-03-15 07:08:32 +00:00
|
|
|
if (defined($elements{'showconfig'})) {
|
2012-03-15 06:54:28 +00:00
|
|
|
push @args, '-q';
|
|
|
|
}
|
2012-03-15 07:08:32 +00:00
|
|
|
if (defined($elements{'silent'})) {
|
2012-03-15 06:54:28 +00:00
|
|
|
push @args, '-Q';
|
|
|
|
}
|
2012-03-15 07:08:32 +00:00
|
|
|
if (defined($elements{'remoteshell'})) {
|
2012-03-15 06:54:28 +00:00
|
|
|
push @args, '-r';
|
|
|
|
push @args, $elements{'remoteshell'};
|
|
|
|
}
|
2012-03-15 07:08:32 +00:00
|
|
|
if (defined($elements{'syntax'})) {
|
2012-03-15 06:54:28 +00:00
|
|
|
push @args, '-S';
|
|
|
|
push @args, $elements{'syntax'};
|
|
|
|
}
|
2012-03-15 07:08:32 +00:00
|
|
|
if (defined($elements{'timeout'})) {
|
2012-03-15 06:54:28 +00:00
|
|
|
push @args, '-t';
|
|
|
|
push @args, $elements{'timeout'};
|
|
|
|
}
|
2012-03-15 07:08:32 +00:00
|
|
|
if (defined($elements{'envlist'})) {
|
2012-03-15 06:54:28 +00:00
|
|
|
push @args, '-X';
|
|
|
|
push @args, $elements{'envlist'};
|
|
|
|
}
|
2012-03-15 07:08:32 +00:00
|
|
|
if (defined($elements{'sshsetup'})) {
|
2012-03-15 06:54:28 +00:00
|
|
|
push @args, '-K';
|
|
|
|
push @args, $elements{'sshsetup'};
|
|
|
|
}
|
2012-03-15 07:08:32 +00:00
|
|
|
if (defined($elements{'rootimg'})) {
|
2012-03-15 06:54:28 +00:00
|
|
|
push @args, '-i';
|
|
|
|
push @args, $elements{'rootimg'};
|
|
|
|
}
|
2012-03-15 07:08:32 +00:00
|
|
|
if (defined($elements{'command'})) {
|
2012-03-15 06:54:28 +00:00
|
|
|
push @args, $elements{'command'};
|
|
|
|
}
|
2013-06-19 16:16:51 +00:00
|
|
|
if (defined($elements{'remotepasswd'})) {
|
|
|
|
push @envs, 'DSH_REMOTE_PASSWORD=' . $elements{'remotepasswd'};
|
|
|
|
push @envs, 'DSH_FROM_USERID=root';
|
|
|
|
push @envs, 'DSH_TO_USERID=root';
|
|
|
|
}
|
2012-03-15 06:54:28 +00:00
|
|
|
}
|
2012-03-15 07:08:32 +00:00
|
|
|
elsif ($subResource eq "dcp") {
|
|
|
|
$request->{command} = "xdcp";
|
|
|
|
my %elements;
|
2012-08-06 21:04:24 +00:00
|
|
|
extractData(\%elements, @entries);
|
2012-03-15 07:08:32 +00:00
|
|
|
if (defined($elements{'fanout'})) {
|
2012-03-19 06:46:10 +00:00
|
|
|
push @args, '-f';
|
|
|
|
push @args, $elements{'fanout'};
|
|
|
|
}
|
|
|
|
if (defined($elements{'rootimg'})) {
|
|
|
|
push @args, '-i';
|
|
|
|
push @args, $elements{'rootimg'};
|
|
|
|
}
|
|
|
|
if (defined($elements{'options'})) {
|
|
|
|
push @args, '-o';
|
|
|
|
push @args, $elements{'options'};
|
|
|
|
}
|
|
|
|
if (defined($elements{'rsyncfile'})) {
|
|
|
|
push @args, '-F';
|
2012-03-19 08:50:55 +00:00
|
|
|
push @args, $elements{'rsyncfile'};
|
2012-03-19 06:46:10 +00:00
|
|
|
}
|
|
|
|
if (defined($elements{'preserve'})) {
|
|
|
|
push @args, '-p';
|
|
|
|
}
|
|
|
|
if (defined($elements{'pull'})) {
|
|
|
|
push @args, '-P';
|
|
|
|
}
|
|
|
|
if (defined($elements{'showconfig'})) {
|
|
|
|
push @args, '-q';
|
|
|
|
}
|
|
|
|
if (defined($elements{'remotecopy'})) {
|
|
|
|
push @args, '-r';
|
|
|
|
push @args, $elements{'remotecopy'};
|
|
|
|
}
|
|
|
|
if (defined($elements{'recursive'})) {
|
|
|
|
push @args, '-R';
|
|
|
|
}
|
|
|
|
if (defined($elements{'timeout'})) {
|
|
|
|
push @args, '-t';
|
|
|
|
push @args, $elements{'timeout'};
|
|
|
|
}
|
|
|
|
if (defined($elements{'source'})) {
|
|
|
|
push @args, $elements{'source'};
|
|
|
|
}
|
|
|
|
if (defined($elements{'target'})) {
|
|
|
|
push @args, $elements{'target'};
|
2012-03-15 07:08:32 +00:00
|
|
|
}
|
|
|
|
}
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-06-19 16:16:51 +00:00
|
|
|
my %elements;
|
|
|
|
my $name;
|
|
|
|
my $val;
|
|
|
|
|
|
|
|
$request->{command} = "tabch";
|
|
|
|
push @args, "node=" . $request->{noderange};
|
|
|
|
|
|
|
|
extractData(\%elements, @entries);
|
|
|
|
while (($name, $val) = each (%elements)) {
|
|
|
|
push @args, $name . "=" . $val;
|
|
|
|
}
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif (isPost()) {
|
2012-02-22 02:24:16 +00:00
|
|
|
$request->{command} = 'mkdef';
|
|
|
|
push @args, "-t", "node";
|
|
|
|
|
|
|
|
unless (defined($noderange)) {
|
|
|
|
addPageContent("No nodename was supplied.");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
|
|
|
|
2012-02-22 02:24:16 +00:00
|
|
|
push @args, "-o", $noderange;
|
|
|
|
|
|
|
|
if ($q->param('POSTDATA')) {
|
2013-01-16 21:02:09 +00:00
|
|
|
my $entries = JSON::decode_json($q->param('POSTDATA'));
|
2012-02-22 02:24:16 +00:00
|
|
|
if (scalar($entries) < 1) {
|
|
|
|
addPageContent("No Field and Value map was supplied.");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
|
|
|
foreach (@$entries) {
|
|
|
|
push @args, $_;
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif (isDelete()) {
|
|
|
|
|
|
|
|
#FYI: the nodeRange for delete has to be specified in the URI
|
2012-02-22 02:24:16 +00:00
|
|
|
$request->{command} = 'rmdef';
|
|
|
|
push @args, "-t", "node";
|
|
|
|
unless (defined($noderange)) {
|
|
|
|
addPageContent("No nodename was supplied.");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
|
|
|
push @args, "-o", $noderange;
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
unsupportedRequestType();
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
push @{$request->{arg}}, @args;
|
2013-06-19 16:16:51 +00:00
|
|
|
if (@envs) {
|
|
|
|
push @{$request->{env}}, @envs;
|
|
|
|
}
|
2012-02-16 02:42:44 +00:00
|
|
|
my $req = genRequest();
|
|
|
|
@responses = sendRequest($req);
|
|
|
|
|
|
|
|
return @responses;
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
my @notificationFields = ('filename', 'tables', 'tableops', 'comments', 'disable');
|
|
|
|
|
|
|
|
#complete, unless there is some way to alter existing notifications
|
2012-02-16 02:42:44 +00:00
|
|
|
sub notificationsHandler {
|
|
|
|
my @responses;
|
|
|
|
my @args;
|
|
|
|
|
|
|
|
#does not support using the notification fileName in the URI
|
|
|
|
|
|
|
|
if (isGet()) {
|
|
|
|
if (defined $q->param('fileName')) {
|
|
|
|
$request->{command} = 'gettab';
|
|
|
|
push @args, "filename" . $q->param('fileName');
|
|
|
|
|
|
|
|
#if they specified the fields, just get those
|
|
|
|
if (defined $q->param('field')) {
|
|
|
|
foreach ($q->param('field')) {
|
|
|
|
push @args, $_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#else show all of the fields
|
|
|
|
else {
|
|
|
|
foreach (@notificationFields) {
|
|
|
|
push @args, "notification.$_";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$request->{command} = 'tabdump';
|
|
|
|
push @args, "notification";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif (isPost()) {
|
|
|
|
$request->{command} = 'regnotif';
|
|
|
|
if (!defined $q->param('fileName') || !defined $q->param('table') || !defined $q->param('operation')) {
|
|
|
|
addPageContent("fileName, table and operation must be specified for a POST on /notifications");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
push @args, $q->param('fileName');
|
|
|
|
my $tables;
|
|
|
|
foreach ($q->param('table')) {
|
|
|
|
$tables .= "$_,";
|
|
|
|
}
|
2011-05-20 15:36:27 +00:00
|
|
|
|
2012-02-16 02:42:44 +00:00
|
|
|
#get rid of the extra comma
|
|
|
|
chop($tables);
|
|
|
|
push @args, $tables;
|
|
|
|
push @args, '-o';
|
|
|
|
my $operations;
|
|
|
|
foreach ($q->param('operation')) {
|
|
|
|
$operations .= "$_,";
|
|
|
|
}
|
2011-05-20 15:36:27 +00:00
|
|
|
|
2012-02-16 02:42:44 +00:00
|
|
|
#get rid of the extra comma
|
|
|
|
chop($operations);
|
|
|
|
push @args, $q->param('operation');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif (isDelete()) {
|
|
|
|
$request->{command} = 'unregnotif';
|
|
|
|
if (defined $q->param('fileName')) {
|
|
|
|
push @args, $q->param('fileName');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
addPageContent("fileName must be specified for a DELETE on /notifications");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
unsupportedRequestType();
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
push @{$request->{arg}}, @args;
|
|
|
|
addPageContent("request is " . Dumper($request));
|
|
|
|
my $req = genRequest();
|
|
|
|
@responses = sendRequest($req);
|
|
|
|
|
|
|
|
return @responses;
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 02:42:44 +00:00
|
|
|
my @policyFields =
|
|
|
|
('priority', 'name', 'host', 'commands', 'noderange', 'parameters', 'time', 'rule', 'comments', 'disable');
|
|
|
|
|
2011-05-20 15:36:27 +00:00
|
|
|
#complete
|
2012-02-16 02:42:44 +00:00
|
|
|
sub policiesHandler {
|
|
|
|
my @responses;
|
|
|
|
my @args;
|
|
|
|
my $priority;
|
|
|
|
|
|
|
|
#does it specify the prioirty in the URI?
|
|
|
|
if (defined $path[1]) {
|
|
|
|
$priority = $path[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
#in the query string?
|
|
|
|
elsif (defined $q->param('priority')) {
|
|
|
|
$priority = $q->param('priority');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isGet()) {
|
|
|
|
if (defined $priority) {
|
|
|
|
$request->{command} = 'gettab';
|
|
|
|
push @args, "priority=$priority";
|
|
|
|
my @fields = $q->param('field');
|
|
|
|
|
|
|
|
#if they specified fields to retrieve
|
|
|
|
if (@fields) {
|
|
|
|
push @args, @fields;
|
|
|
|
}
|
|
|
|
|
|
|
|
#give them everything if nothing is specified
|
|
|
|
else {
|
|
|
|
foreach (@policyFields) {
|
|
|
|
push @args, "policy.$_";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$request->{command} = 'tabdump';
|
|
|
|
push @args, 'policy';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif (isPost()) {
|
|
|
|
if (defined $priority) {
|
|
|
|
$request->{command} = 'tabch';
|
|
|
|
push @args, "priority=$priority";
|
|
|
|
for ($q->param) {
|
|
|
|
if ($_ ne /priority/) {
|
|
|
|
push @args, "policy.$_=" . $q->param($_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#some response about the priority being required
|
|
|
|
else {
|
|
|
|
addPageContent("The priority must be specified when creating a policy");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif (isDelete()) {
|
|
|
|
|
|
|
|
#just allowing a delete by priority at the moment, could expand this to anything
|
|
|
|
if (defined $priority) {
|
|
|
|
$request->{command} = 'tabch';
|
|
|
|
push @args, '-d';
|
|
|
|
push @args, "priority=$priority";
|
|
|
|
push @args, "policy";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif (isPut() || isPatch()) {
|
|
|
|
if (defined $priority) {
|
|
|
|
$request->{command} = 'tabch';
|
|
|
|
push @args, "priority=$priority";
|
|
|
|
for ($q->param) {
|
|
|
|
if ($_ ne /priority/) {
|
|
|
|
push @args, "policy.$_=" . $q->param($_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#some response about the priority being required
|
|
|
|
else {
|
|
|
|
addPageContent("The priority must be specified when updating a policy");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
unsupportedRequestType();
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
push @{$request->{arg}}, @args;
|
|
|
|
addPageContent("request is " . Dumper($request));
|
2011-05-20 15:36:27 +00:00
|
|
|
my $req = genRequest();
|
|
|
|
@responses = sendRequest($req);
|
2012-02-16 02:42:44 +00:00
|
|
|
|
|
|
|
return @responses;
|
|
|
|
}
|
|
|
|
|
|
|
|
#complete
|
|
|
|
sub siteHandler {
|
|
|
|
my @data;
|
|
|
|
my @responses;
|
|
|
|
my @args;
|
|
|
|
|
|
|
|
if (isGet()) {
|
|
|
|
$request->{command} = 'lsdef';
|
|
|
|
push @{$request->{arg}}, '-t', 'site', '-o', 'clustersite';
|
2012-02-16 13:06:45 +00:00
|
|
|
my @temparray = $q->param('field');
|
|
|
|
|
|
|
|
#add the field name to get
|
|
|
|
if (scalar(@temparray) > 0) {
|
|
|
|
push @{$request->{arg}}, '-i';
|
2012-02-22 02:24:16 +00:00
|
|
|
push @{$request->{arg}}, join(',', @temparray);
|
2012-02-16 13:06:45 +00:00
|
|
|
}
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
2012-02-16 13:06:45 +00:00
|
|
|
elsif (isPut()) {
|
|
|
|
$request->{command} = 'chdef';
|
|
|
|
push @{$request->{arg}}, '-t', 'site', '-o', 'clustersite';
|
2012-08-06 21:04:24 +00:00
|
|
|
unless ($q->param('PUTDATA')) {
|
|
|
|
#temporary allowance for the put data to be contained in the queryString
|
|
|
|
unless ($queryhash{'putData'}) {
|
|
|
|
addPageContent("No set attribute was supplied.");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
foreach my $put (@{$queryhash{'putData'}}) {
|
|
|
|
my ($key, $value) = split(/=/, $put, 2);
|
|
|
|
if ($key eq 'field' && $value) {
|
|
|
|
push @{$request->{arg}}, $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ($q->param('PUTDATA')) {
|
2013-01-16 21:02:09 +00:00
|
|
|
my $entries = JSON::decode_json($q->param('PUTDATA'));
|
2012-08-06 21:04:24 +00:00
|
|
|
foreach (@$entries) {
|
|
|
|
push @{$request->{arg}}, $_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
addPageContent("No Field and Value map was supplied.");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
|
|
|
}
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
unsupportedRequestType();
|
|
|
|
}
|
|
|
|
|
2012-02-16 13:06:45 +00:00
|
|
|
my $req = genRequest();
|
|
|
|
@responses = sendRequest($req);
|
2012-02-16 02:42:44 +00:00
|
|
|
return @responses;
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 02:42:44 +00:00
|
|
|
my $formatType;
|
2011-05-20 15:36:27 +00:00
|
|
|
|
|
|
|
#provide direct table access
|
|
|
|
#complete and tested on the site table
|
|
|
|
#use of the actual DELETE doesn't seem to fit here, since a resource would not be deleted
|
|
|
|
#using PUT or PATCH instead, though it doesn't feel all that correct either
|
2012-02-16 02:42:44 +00:00
|
|
|
sub tablesHandler {
|
|
|
|
my @responses;
|
|
|
|
my $table;
|
|
|
|
my @args;
|
|
|
|
|
|
|
|
#is the table name specified in the URI?
|
|
|
|
if (defined $path[1]) {
|
|
|
|
$table = $path[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
#handle all gets
|
|
|
|
if (isGet()) {
|
|
|
|
|
|
|
|
#table was specified
|
|
|
|
if (defined $table) {
|
2012-03-20 09:16:06 +00:00
|
|
|
if (defined($q->param('col'))) {
|
|
|
|
$request->{command} = 'gettab';
|
|
|
|
push @args, $q->param('col') . '=' . $q->param('value');
|
|
|
|
my @temparray = $q->param('attribute');
|
|
|
|
foreach (@temparray) {
|
|
|
|
push @args, $table . '.' . $_;
|
|
|
|
}
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
2012-03-20 09:16:06 +00:00
|
|
|
else {
|
|
|
|
$request->{command} = 'tabdump';
|
|
|
|
push @args, $table;
|
|
|
|
if (!defined $q->param('desc')) {
|
|
|
|
$formatType = 'splitCommas';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$request->{command} = 'tabdump';
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif (isPut() || isPatch()) {
|
|
|
|
my $condition = $q->param('condition');
|
2013-01-11 21:21:05 +00:00
|
|
|
my @vals;
|
2013-06-19 16:16:51 +00:00
|
|
|
my $entries;
|
2012-08-30 15:01:58 +00:00
|
|
|
if (!defined $condition) {
|
2013-06-19 16:16:51 +00:00
|
|
|
unless ($q->param('PUTDATA')) {
|
|
|
|
foreach my $put (@{$queryhash{'putData'}}) {
|
|
|
|
my ($key, $value) = split(/=/, $put, 2);
|
|
|
|
if ($key eq 'condition' && $value) {
|
|
|
|
$condition = $value;
|
|
|
|
}
|
2012-08-30 15:01:58 +00:00
|
|
|
}
|
2013-06-19 16:16:51 +00:00
|
|
|
foreach my $put (@{$queryhash{'putData'}}) {
|
|
|
|
my ($key, $value) = split(/=/, $put, 2);
|
|
|
|
if ($key eq 'value') {
|
|
|
|
push(@vals, $value);
|
|
|
|
}
|
|
|
|
}
|
2012-08-30 15:01:58 +00:00
|
|
|
}
|
2013-06-19 16:16:51 +00:00
|
|
|
else {
|
|
|
|
$entries = JSON::decode_json($q->param('PUTDATA'));
|
|
|
|
if (scalar(@$entries) < 1) {
|
|
|
|
addPageContent("No set attribute was supplied.");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
2013-01-11 21:21:05 +00:00
|
|
|
}
|
2013-06-19 16:16:51 +00:00
|
|
|
}
|
2012-08-30 15:01:58 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 02:42:44 +00:00
|
|
|
if (!defined $table || !defined $condition) {
|
2013-06-19 16:16:51 +00:00
|
|
|
if (scalar(@$entries) < 1) {
|
|
|
|
addPageContent("The table and condition must be specified when adding, changing or deleting an entry");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
|
|
|
$request->{command} = 'tabch';
|
2012-08-30 15:01:58 +00:00
|
|
|
my $del;
|
|
|
|
if (!defined $q->param('delete')) {
|
|
|
|
foreach my $put (@{$queryhash{'putData'}}) {
|
|
|
|
my ($key, $value) = split(/=/, $put, 2);
|
|
|
|
if ($key eq 'delete') {
|
|
|
|
$del = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defined $q->param('delete') || defined $del) {
|
2012-02-16 02:42:44 +00:00
|
|
|
push @args, '-d';
|
|
|
|
push @args, $condition;
|
|
|
|
push @args, $table;
|
|
|
|
}
|
2013-06-19 16:16:51 +00:00
|
|
|
elsif (defined $condition) {
|
2012-02-16 02:42:44 +00:00
|
|
|
push @args, $condition;
|
2013-01-11 21:21:05 +00:00
|
|
|
if ($q->param('value')) {
|
|
|
|
for ($q->param('value')) {
|
|
|
|
push @args, "$table.$_";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
@args = (@args, @vals);
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
|
|
|
}
|
2013-06-19 16:16:51 +00:00
|
|
|
else {
|
|
|
|
foreach (@$entries) {
|
|
|
|
push @args, split(/ /,$_);
|
|
|
|
}
|
|
|
|
}
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
unsupportedRequestType();
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
push @{$request->{arg}}, @args;
|
|
|
|
my $req = genRequest();
|
|
|
|
@responses = sendRequest($req);
|
|
|
|
return @responses;
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
my @accountFields = ('key', 'username', 'password', 'cryptmethod', 'comments', 'disable');
|
|
|
|
|
|
|
|
#done aside from being able to change cluster users, which xcat can't do yet
|
2012-02-16 02:42:44 +00:00
|
|
|
sub accountsHandler {
|
|
|
|
my @responses;
|
|
|
|
my @args;
|
|
|
|
my $key = $q->param('key');
|
|
|
|
|
|
|
|
if (isGet()) {
|
|
|
|
|
|
|
|
#passwd table
|
|
|
|
if (!defined $q->param('clusterUser')) {
|
|
|
|
if (defined $key) {
|
|
|
|
$request->{command} = 'tabget';
|
|
|
|
push @args, "key=$key";
|
|
|
|
if (defined $q->param('field')) {
|
|
|
|
foreach ($q->param('field')) {
|
|
|
|
push @args, "passwd.$_";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
foreach (@accountFields) {
|
|
|
|
push @args, "passwd.$_";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$request->{command} = 'tabdump';
|
|
|
|
push @args, 'passwd';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#cluster user list
|
|
|
|
else {
|
|
|
|
$request->{command} = 'xcatclientnnr';
|
|
|
|
push @args, 'clusteruserlist';
|
|
|
|
push @args, '-p';
|
|
|
|
}
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
2012-02-16 02:42:44 +00:00
|
|
|
elsif (isPost()) {
|
|
|
|
if (!defined $q->param('clusterUser')) {
|
|
|
|
if (defined $key) {
|
|
|
|
$request->{command} = 'tabch';
|
|
|
|
push @args, "key=$key";
|
|
|
|
for ($q->param) {
|
|
|
|
if ($_ !~ /key/) {
|
|
|
|
push @args, "passwd.$_=" . $q->param($_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
addPageContent("The key must be specified when creating a non-cluster user");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#active directory user
|
|
|
|
else {
|
|
|
|
if (defined $q->param('userName') && defined $q->param('userPass')) {
|
|
|
|
$request->{command} = 'xcatclientnnr';
|
|
|
|
push @args, 'clusteruseradd';
|
|
|
|
push @args, $q->param('userName');
|
|
|
|
push @{$request->{arg}}, @args;
|
|
|
|
$request->{environment} = {XCAT_USERPASS => $q->param('userPass')};
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
addPageContent("The key must be specified when creating a cluster user");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
|
|
|
}
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
2012-02-16 02:42:44 +00:00
|
|
|
elsif (isDelete()) {
|
|
|
|
if (!defined $q->param('clusterUser')) {
|
|
|
|
|
|
|
|
#just allowing a delete by key at the moment, could expand this to anything
|
|
|
|
if (defined $key) {
|
|
|
|
$request->{command} = 'tabch';
|
|
|
|
push @args, '-d';
|
|
|
|
push @args, "key=$key";
|
|
|
|
push @args, "passwd";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
addPageContent("The key must be specified when deleting a non-cluster user");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (defined $q->param('userName')) {
|
|
|
|
$request->{command} = 'xcatclientnnr';
|
|
|
|
push @args, 'clusteruserdel';
|
|
|
|
push @args, $q->param('userName');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
addPageContent("The userName must be specified when deleting a cluster user");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
|
|
|
}
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
2012-02-16 02:42:44 +00:00
|
|
|
elsif (isPut() || isPatch()) {
|
|
|
|
if (!defined $q->param('clusterUser')) {
|
|
|
|
if (defined $key) {
|
|
|
|
$request->{command} = 'tabch';
|
|
|
|
push @args, "key=$key";
|
|
|
|
for ($q->param) {
|
|
|
|
if ($_ !~ /key/) {
|
|
|
|
push @args, "passwd.$_=" . $q->param($_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
addPageContent("The key must be specified when updating a non-cluster user");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#TODO: there isn't currently a way to update cluster users
|
|
|
|
else {
|
2011-05-20 15:36:27 +00:00
|
|
|
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
unsupportedRequestType();
|
|
|
|
exit(0);
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 02:42:44 +00:00
|
|
|
push @{$request->{arg}}, @args;
|
|
|
|
my $req = genRequest();
|
|
|
|
@responses = sendRequest($req);
|
|
|
|
return @responses;
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 02:42:44 +00:00
|
|
|
sub objectsHandler {
|
|
|
|
my @responses;
|
|
|
|
my @args;
|
|
|
|
my @objectTypeList = (
|
|
|
|
"auditlog", "boottarget", "eventlog", "firmware", "group", "monitoring",
|
|
|
|
"network", "node", "notification", "osimage", "policy", "route",
|
|
|
|
"site");
|
|
|
|
|
|
|
|
#my %objectTypes;
|
|
|
|
#foreach my $item (@objectTypeList) { $objectTypes{$item} = 1 }
|
|
|
|
my @objectTypes;
|
|
|
|
my @objects;
|
|
|
|
if (defined $path[1]) {
|
|
|
|
$objectTypes[0] = $path[1];
|
|
|
|
if (defined $path[2]) {
|
|
|
|
$objects[0] = $path[2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (defined $q->param('objectType')) {
|
|
|
|
@objectTypes = $q->param('objectType');
|
|
|
|
}
|
|
|
|
if (defined $q->param('object')) {
|
|
|
|
@objects = $q->param('object');
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($q->param('verbose')) {
|
|
|
|
push @args, '-v';
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
2012-02-16 02:42:44 +00:00
|
|
|
|
|
|
|
if (isGet()) {
|
|
|
|
if (defined $objectTypes[0]) {
|
|
|
|
$request->{command} = 'lsdef';
|
|
|
|
push @args, '-l';
|
|
|
|
push @args, '-t';
|
|
|
|
push @args, join(',', @objectTypes);
|
|
|
|
if (defined $objects[0]) {
|
|
|
|
push @args, '-o';
|
|
|
|
push @args, join(',', @objects);
|
|
|
|
}
|
|
|
|
if ($q->param('info')) {
|
|
|
|
push @args, '-h';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if ($q->param('info')) {
|
|
|
|
push @args, '-h';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
#couldn't find a way to do this through xcatd, so shortcutting the request
|
|
|
|
my %resp = (data => \@objectTypeList);
|
|
|
|
return (\%resp);
|
|
|
|
}
|
|
|
|
}
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
2012-02-16 02:42:44 +00:00
|
|
|
elsif (isPut()) {
|
|
|
|
$request->{command} = 'chdef';
|
|
|
|
if ($q->param('verbose')) {
|
|
|
|
push @args, '-v';
|
|
|
|
}
|
|
|
|
if (!defined $q->param('objectType')) {
|
|
|
|
addPageContent("The object must be specified.");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
push @args, '-t';
|
|
|
|
push @args, join(',', $q->param('objectType'));
|
|
|
|
}
|
|
|
|
if ($q->param('objectName')) {
|
|
|
|
push @args, join(',', $q->param('objectName'));
|
|
|
|
}
|
|
|
|
if ($q->param('dynamic')) {
|
|
|
|
push @args, '-d';
|
|
|
|
}
|
|
|
|
if ($q->param('minus')) {
|
|
|
|
push @args, '-m';
|
|
|
|
}
|
|
|
|
if ($q->param('plus')) {
|
|
|
|
push @args, '-p';
|
|
|
|
}
|
|
|
|
if (defined $q->param('field')) {
|
|
|
|
foreach ($q->param('field')) {
|
|
|
|
|
|
|
|
#if it has ==, !=. =~ or !~ operators in the field, use the -w option
|
|
|
|
if (/==|!=|=~|!~/) {
|
|
|
|
push @args, '-w';
|
|
|
|
}
|
|
|
|
push @args, $_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($q->param('nodeRange')) {
|
|
|
|
push @args, $q->param('nodeRange');
|
|
|
|
}
|
2011-05-20 15:36:27 +00:00
|
|
|
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
|
|
|
elsif (isPost()) {
|
|
|
|
$request->{command} = 'mkdef';
|
|
|
|
if ($q->param('verbose')) {
|
|
|
|
push @args, '-v';
|
|
|
|
}
|
|
|
|
if (!defined $q->param('objectType')) {
|
|
|
|
addPageContent("The object must be specified.");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
push @args, '-t';
|
|
|
|
push @args, join(',', $q->param('objectType'));
|
|
|
|
}
|
|
|
|
if ($q->param('objectName')) {
|
|
|
|
push @args, join(',', $q->param('objectName'));
|
|
|
|
}
|
|
|
|
if ($q->param('dynamic')) {
|
|
|
|
push @args, '-d';
|
|
|
|
}
|
|
|
|
if ($q->param('force')) {
|
|
|
|
push @args, '-f';
|
|
|
|
}
|
|
|
|
if (defined $q->param('field')) {
|
|
|
|
foreach ($q->param('field')) {
|
|
|
|
|
|
|
|
#if it has ==, !=. =~ or !~ operators in the field, use the -w option
|
|
|
|
if (/==|!=|=~|!~/) {
|
|
|
|
push @args, '-w';
|
|
|
|
}
|
|
|
|
push @args, $_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($q->param('nodeRange')) {
|
|
|
|
push @args, $q->param('nodeRange');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
elsif (isDelete()) {
|
|
|
|
$request->{command} = 'rmdef';
|
|
|
|
if (defined $q->param('info')) {
|
|
|
|
push @args, '-h';
|
|
|
|
}
|
|
|
|
elsif (defined $q->param('all')) {
|
|
|
|
push @args, '-a';
|
|
|
|
}
|
|
|
|
elsif (defined $objectTypes[0]) {
|
|
|
|
push @args, '-t';
|
|
|
|
push @args, join(',', @objectTypes);
|
|
|
|
if (defined $objects[0]) {
|
|
|
|
push @args, '-o';
|
|
|
|
push @args, join(',', @objects);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
addPageContent(
|
|
|
|
"Either the help info must be requested or the object must be specified or the flag that indicates everything should be removed."
|
|
|
|
);
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
|
|
|
if (defined $q->param('nodeRange')) {
|
|
|
|
push @args, $q->param('nodeRange');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
unsupportedRequestType();
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
push @{$request->{arg}}, @args;
|
|
|
|
my $req = genRequest();
|
|
|
|
@responses = sendRequest($req);
|
|
|
|
return @responses;
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#complete i think, tho chvm could handle args better
|
2012-02-16 02:42:44 +00:00
|
|
|
sub vmsHandler {
|
|
|
|
my @args;
|
2012-03-13 08:34:30 +00:00
|
|
|
my $noderange;
|
2013-06-19 16:16:51 +00:00
|
|
|
my $subResource;
|
2012-03-13 08:34:30 +00:00
|
|
|
if (defined $path[1]) {
|
|
|
|
$noderange = $path[1];
|
|
|
|
$request->{noderange} = $noderange;
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
2012-03-13 08:34:30 +00:00
|
|
|
else {
|
|
|
|
addPageContent("Invalid nodes and/or groups in noderange");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isGet()) {
|
|
|
|
$request->{command} = 'lsvm';
|
|
|
|
if (defined $q->param('all')) {
|
|
|
|
push @args, '-a';
|
|
|
|
}
|
2013-06-19 16:16:51 +00:00
|
|
|
|
|
|
|
# for z/VM
|
|
|
|
if (defined $q->param('networknames')) {
|
|
|
|
push @args, '--getnetworknames';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defined $q->param('network')) {
|
|
|
|
push @args, '--getnetwork';
|
|
|
|
push @args, $q->param('getnetwork');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defined $q->param('diskpoolnames')) {
|
|
|
|
push @args, '--diskpoolnames';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defined $q->param('diskpool')) {
|
|
|
|
push @args, '--diskpool';
|
|
|
|
push @args, $q->param('diskpool');
|
|
|
|
}
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
|
|
|
elsif (isPost()) {
|
2012-03-13 08:34:30 +00:00
|
|
|
my $entries;
|
|
|
|
my %entryhash;
|
|
|
|
my $position;
|
|
|
|
$request->{command} = 'mkvm';
|
|
|
|
unless ($q->param('POSTDATA')) {
|
|
|
|
addPageContent("Invalid Parameters");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
|
|
|
|
2012-03-13 08:34:30 +00:00
|
|
|
#collect all parameters from the postdata
|
2013-06-19 16:16:51 +00:00
|
|
|
my $entries = JSON::decode_json($q->param('POSTDATA'));
|
2012-03-13 08:34:30 +00:00
|
|
|
if (scalar(@$entries) < 1) {
|
|
|
|
addPageContent("No set attribute was supplied.");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
|
|
|
|
2012-03-19 09:31:33 +00:00
|
|
|
extractData(\%entryhash, $entries);
|
2012-03-13 08:34:30 +00:00
|
|
|
|
|
|
|
#for system p
|
|
|
|
if (defined $entryhash{'cec'}) {
|
|
|
|
push @args, '-c';
|
|
|
|
push @args, $entryhash{'cec'};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defined $entryhash{'startId'}) {
|
|
|
|
push @args, '-i';
|
|
|
|
push @args, $entryhash{'startId'};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defined $entryhash{'source'}) {
|
|
|
|
push @args, '-l';
|
|
|
|
push @args, $entryhash{'source'};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defined $entryhash{'profile'}) {
|
|
|
|
push @args, '-p';
|
|
|
|
push @args, $entryhash{'profile'};
|
|
|
|
}
|
2012-02-16 02:42:44 +00:00
|
|
|
|
2012-03-13 08:34:30 +00:00
|
|
|
if (defined $entryhash{'full'}) {
|
|
|
|
push @args, '--full';
|
|
|
|
}
|
|
|
|
|
|
|
|
#for KVM & Vmware
|
|
|
|
if (defined $entryhash{'master'}) {
|
|
|
|
push @args, '-m';
|
|
|
|
push @args, $entryhash{'master'};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defined $entryhash{'disksize'}) {
|
|
|
|
push @args, '-s';
|
|
|
|
push @args, $entryhash{'disksize'};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defined $entryhash{'memory'}) {
|
|
|
|
push @args, '--mem';
|
|
|
|
push @args, $entryhash{'memory'};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defined $entryhash{'cpu'}) {
|
|
|
|
push @args, '--cpus';
|
|
|
|
push @args, $entryhash{'cpu'};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defined $entryhash{'force'}) {
|
|
|
|
push @args, '-f';
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
2013-06-19 16:16:51 +00:00
|
|
|
|
|
|
|
# for z/VM
|
|
|
|
if (defined $entryhash{'userid'}) {
|
|
|
|
push @args, '--userid';
|
|
|
|
push @args, $entryhash{'userid'};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defined $entryhash{'size'}) {
|
|
|
|
push @args, '--size';
|
|
|
|
push @args, $entryhash{'size'};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defined $entryhash{'password'}) {
|
|
|
|
push @args, '--password';
|
|
|
|
push @args, $entryhash{'password'};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defined $entryhash{'privilege'}) {
|
|
|
|
push @args, '--privilege';
|
|
|
|
push @args, $entryhash{'privilege'};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defined $entryhash{'diskpool'}) {
|
|
|
|
push @args, '--diskpool';
|
|
|
|
push @args, $entryhash{'diskpool'};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defined $entryhash{'diskvdev'}) {
|
|
|
|
push @args, '--diskVdev';
|
|
|
|
push @args, $entryhash{'diskvdev'};
|
|
|
|
}
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
2012-03-13 08:34:30 +00:00
|
|
|
elsif (isPut()) {
|
2012-02-16 02:42:44 +00:00
|
|
|
$request->{command} = 'chvm';
|
2012-03-13 08:34:30 +00:00
|
|
|
if ($q->param('PUTDATA')) {
|
2013-01-16 21:02:09 +00:00
|
|
|
my $entries = JSON::decode_json($q->param('PUTDATA'));
|
2012-03-13 08:34:30 +00:00
|
|
|
if (scalar(@$entries) < 1) {
|
|
|
|
addPageContent("No Field and Value map was supplied.");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
|
|
|
foreach (@$entries) {
|
2013-06-19 16:16:51 +00:00
|
|
|
# Handle blank delimited parameters
|
|
|
|
push @args, split(/ /,$_);
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-13 08:34:30 +00:00
|
|
|
else {
|
|
|
|
addPageContent("No Field and Value map was supplied.");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
|
|
|
elsif (isDelete()) {
|
|
|
|
$request->{command} = 'rmvm';
|
2012-03-13 08:34:30 +00:00
|
|
|
if (defined $q->param('retain')) {
|
|
|
|
push @args, '-r';
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
2012-03-13 08:34:30 +00:00
|
|
|
if (defined $q->param('service')) {
|
|
|
|
push @args, '--service';
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
unsupportedRequestType();
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
push @{$request->{arg}}, @args;
|
|
|
|
my $req = genRequest();
|
|
|
|
my @responses = sendRequest($req);
|
|
|
|
return @responses;
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
|
|
|
|
2012-03-13 08:34:30 +00:00
|
|
|
sub versionHandler {
|
2012-02-27 15:44:59 +00:00
|
|
|
addPageContent($q->p("API version is $VERSION"));
|
|
|
|
sendResponseMsg($STATUS_OK);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2011-05-20 15:36:27 +00:00
|
|
|
#for operations that take a 'long' time to finish, this will provide the interface to check their status
|
2012-02-16 02:42:44 +00:00
|
|
|
sub jobsHandler {
|
2011-05-20 15:36:27 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-06-19 16:16:51 +00:00
|
|
|
sub hypervisorHandler {
|
|
|
|
my @responses;
|
|
|
|
my @args;
|
|
|
|
if (isPut()) {
|
|
|
|
my %entryhash;
|
|
|
|
if (defined $path[1]) {
|
|
|
|
$request->{noderange} = $path[1];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
addPageContent("Invalid nodes and/or groups in node in noderange");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defined $path[2]) {
|
|
|
|
$request->{command} = $path[2];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$request->{command} = 'chhypervisor';
|
|
|
|
}
|
|
|
|
my $entries = JSON::decode_json( $q->param('PUTDATA') );
|
|
|
|
if (scalar(@$entries) < 1) {
|
|
|
|
addPageContent("No set attribute was supplied.");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (@$entries) {
|
|
|
|
push @args, split(/ /,$_);
|
|
|
|
}
|
|
|
|
|
|
|
|
push @{$request->{arg}}, @args;
|
|
|
|
my $req = genRequest();
|
|
|
|
@responses = sendRequest($req);
|
|
|
|
return @responses;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub debugHandler {
|
|
|
|
my @responses;
|
|
|
|
my @args;
|
|
|
|
if (isPut()) {
|
|
|
|
my %entryhash;
|
|
|
|
$request->{command} = 'xcatclientnnr xcatdebug';
|
|
|
|
|
|
|
|
#push @args, 'xcatdebug';
|
|
|
|
my $entries = JSON::decode_json( $q->param('PUTDATA') );
|
|
|
|
if (scalar(@$entries) < 1) {
|
|
|
|
addPageContent("No set attribute was supplied.");
|
|
|
|
sendResponseMsg($STATUS_BAD_REQUEST);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (@$entries) {
|
|
|
|
push @{$request->{arg}}, $_;
|
|
|
|
}
|
|
|
|
|
|
|
|
push @{$request->{arg}}, @args;
|
|
|
|
my $req = genRequest();
|
|
|
|
@responses = sendRequest($req);
|
|
|
|
return @responses;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-20 15:36:27 +00:00
|
|
|
#all data wrapping and writing is funneled through here
|
2012-02-16 02:42:44 +00:00
|
|
|
sub wrapData {
|
|
|
|
my $data = shift;
|
2012-02-13 08:42:47 +00:00
|
|
|
my $errorInformation = '';
|
2012-02-16 02:42:44 +00:00
|
|
|
|
2012-02-13 08:42:47 +00:00
|
|
|
#trim the serverdone message off
|
2012-02-16 02:42:44 +00:00
|
|
|
if (exists $data->[0]->{serverdone} && exists $data->[0]->{error}) {
|
|
|
|
$errorInformation = $data->[0]->{error}->[0];
|
|
|
|
addPageContent($q->p($errorInformation));
|
|
|
|
if (($errorInformation =~ /Permission denied/) || ($errorInformation =~ /Authentication failure/)) {
|
|
|
|
sendResponseMsg($STATUS_UNAUTH);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sendResponseMsg($STATUS_FORBIDDEN);
|
|
|
|
}
|
2012-02-13 08:42:47 +00:00
|
|
|
exit 1;
|
|
|
|
}
|
2012-02-16 02:42:44 +00:00
|
|
|
else {
|
|
|
|
pop @{$data};
|
2012-02-13 08:42:47 +00:00
|
|
|
}
|
2012-02-16 02:42:44 +00:00
|
|
|
if (exists $formatters{$format}) {
|
|
|
|
$formatters{$format}->($data);
|
2012-02-13 08:42:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#all information were add into the global varibale, call the response funcion
|
2012-08-06 21:04:24 +00:00
|
|
|
if (exists $data->[0]->{info} && $data->[0]->{info}->[0] =~ /Could not find an object/) {
|
|
|
|
sendResponseMsg($STATUS_NOT_FOUND);
|
|
|
|
}
|
|
|
|
elsif (isPost()) {
|
2012-02-13 08:42:47 +00:00
|
|
|
sendResponseMsg($STATUS_CREATED);
|
|
|
|
}
|
2012-02-16 02:42:44 +00:00
|
|
|
else {
|
2012-02-13 08:42:47 +00:00
|
|
|
sendResponseMsg($STATUS_OK);
|
|
|
|
}
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 02:42:44 +00:00
|
|
|
sub wrapJson {
|
2012-06-25 14:03:30 +00:00
|
|
|
my $data = shift;
|
2012-02-16 02:42:44 +00:00
|
|
|
my $json;
|
2012-06-25 14:03:30 +00:00
|
|
|
$json->{'data'} = $data;
|
2013-01-11 20:52:46 +00:00
|
|
|
addPageContent(JSON::to_json($json));
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 02:42:44 +00:00
|
|
|
sub wrapHtml {
|
|
|
|
my $item;
|
|
|
|
my $response = shift;
|
|
|
|
my $baseUri = $url . $pathInfo;
|
|
|
|
if ($baseUri !~ /\/^/) {
|
|
|
|
$baseUri .= "/";
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach my $element (@$response) {
|
|
|
|
|
|
|
|
#foreach my $element (@$data){
|
|
|
|
#if($element->{error}){
|
|
|
|
if ($element->{node}) {
|
|
|
|
addPageContent("<table border=1>");
|
|
|
|
foreach $item (@{$element->{node}}) {
|
|
|
|
|
|
|
|
#my $url = $baseUri.$item->{name}[0];
|
|
|
|
addPageContent("<tr><td>$item->{name}[0]</td>");
|
|
|
|
if (exists $item->{data} && exists $item->{data}[0]) {
|
|
|
|
if (ref($item->{data}[0]) eq 'HASH') {
|
|
|
|
if (exists $item->{data}[0]->{desc} && exists $item->{data}[0]->{desc}[0]) {
|
|
|
|
addPageContent("<td>$item->{data}[0]->{desc}[0]</td>");
|
|
|
|
}
|
|
|
|
if (ref($item->{data}[0]) eq 'HASH' && exists $item->{data}[0]->{contents}[0]) {
|
|
|
|
addPageContent("<td>$item->{data}[0]->{contents}[0]</td>");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
addPageContent("<td>$item->{data}[0]</td>");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif (exists $item->{error}) {
|
|
|
|
addPageContent("<td>$item->{error}[0]</td>");
|
|
|
|
}
|
|
|
|
addPageContent("</tr>");
|
|
|
|
}
|
|
|
|
addPageContent("</table>");
|
|
|
|
}
|
|
|
|
if ($element->{data}) {
|
|
|
|
addPageContent("<table border=1>");
|
|
|
|
foreach $item (@{$element->{data}}) {
|
|
|
|
my @values = split(/:/, $item, 2);
|
|
|
|
addPageContent("<tr>");
|
|
|
|
foreach (@values) {
|
|
|
|
if ($formatType =~ /splitCommas/) {
|
|
|
|
my @fields = split(/,/, $_, -1);
|
|
|
|
foreach (@fields) {
|
|
|
|
addPageContent("<td>$_</td>");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
addPageContent("<td>$_</td>");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
addPageContent("</tr>\n");
|
|
|
|
}
|
|
|
|
addPageContent("</table>");
|
|
|
|
}
|
|
|
|
if ($element->{info}) {
|
|
|
|
addPageContent("<table border=1>");
|
|
|
|
foreach $item (@{$element->{info}}) {
|
|
|
|
addPageContent("<tr>");
|
2012-02-16 13:06:45 +00:00
|
|
|
my $fieldname = '';
|
|
|
|
my $fieldvalue = '';
|
|
|
|
|
|
|
|
#strip whitespace in the string
|
|
|
|
$item =~ s/^\s+//;
|
|
|
|
$item =~ s/\s+$//;
|
|
|
|
if ($item =~ /Object/) {
|
|
|
|
($fieldname, $fieldvalue) = split(/:/, $item);
|
|
|
|
}
|
|
|
|
elsif ($item =~ /.*=.*/) {
|
|
|
|
my $position = index $item, '=';
|
|
|
|
$fieldname = substr $item, 0, $position;
|
|
|
|
$fieldvalue = substr $item, $position + 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$fieldname = $item;
|
|
|
|
}
|
|
|
|
addPageContent("<td>" . $fieldname . "</td>");
|
|
|
|
if ($fieldvalue ne '') {
|
|
|
|
addPageContent("<td>" . $fieldvalue . "</td>");
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
|
|
|
addPageContent("</tr>\n");
|
|
|
|
}
|
|
|
|
addPageContent("</table>");
|
|
|
|
}
|
|
|
|
if ($element->{error}) {
|
|
|
|
addPageContent("<table border=1>");
|
|
|
|
foreach $item (@{$element->{error}}) {
|
|
|
|
addPageContent("<tr><td>" . $item . "</td></tr>");
|
|
|
|
}
|
|
|
|
addPageContent("</table>");
|
|
|
|
}
|
|
|
|
}
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 02:42:44 +00:00
|
|
|
sub wrapXml {
|
|
|
|
my @data = shift;
|
|
|
|
foreach (@data) {
|
|
|
|
foreach (@$_) {
|
|
|
|
addPageContent(XMLout($_, RootName => '', NoAttr => 1, KeyAttr => []));
|
|
|
|
}
|
2011-06-14 18:58:31 +00:00
|
|
|
}
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#general tests for valid requests and responses with HTTP codes here
|
2012-02-16 02:42:44 +00:00
|
|
|
if (!doesResourceExist($resource)) {
|
2012-02-13 08:42:47 +00:00
|
|
|
addPageContent("Resource '$resource' does not exist");
|
|
|
|
sendResponseMsg($STATUS_NOT_FOUND);
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
2012-02-16 02:42:44 +00:00
|
|
|
else {
|
|
|
|
if ($DEBUGGING) {
|
|
|
|
addPageContent($q->p("resource is $resource"));
|
|
|
|
}
|
|
|
|
handleRequest();
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#talk to the server
|
|
|
|
use Socket;
|
|
|
|
use IO::Socket::INET;
|
|
|
|
use IO::Socket::SSL;
|
|
|
|
use lib "/opt/xcat/lib/perl";
|
|
|
|
use xCAT::Table;
|
|
|
|
|
|
|
|
# The database initialization may take some time in the system boot scenario
|
|
|
|
# wait for a while for the database initialization
|
|
|
|
#do we really need to do this for the web service?
|
2012-02-16 02:42:44 +00:00
|
|
|
sub sendRequest {
|
|
|
|
my $request = shift;
|
|
|
|
my $sitetab;
|
|
|
|
my $retries = 0;
|
|
|
|
|
|
|
|
if ($DEBUGGING) {
|
|
|
|
my $preXml = $request;
|
|
|
|
|
|
|
|
#$preXml =~ s/</<br>< /g;
|
|
|
|
#$preXml =~ s/>/><br>/g;
|
|
|
|
addPageContent($q->p("request XML<br>" . $preXml));
|
|
|
|
}
|
|
|
|
|
|
|
|
#hardcoded port for now
|
|
|
|
my $port = 3001;
|
|
|
|
my $xcatHost = "localhost:$port";
|
|
|
|
|
|
|
|
#temporary, will be using username and password
|
|
|
|
my $homedir = "/root";
|
|
|
|
my $keyfile = $homedir . "/.xcat/client-cred.pem";
|
|
|
|
my $certfile = $homedir . "/.xcat/client-cred.pem";
|
|
|
|
my $cafile = $homedir . "/.xcat/ca.pem";
|
|
|
|
|
|
|
|
my $client;
|
|
|
|
if (-r $keyfile and -r $certfile and -r $cafile) {
|
|
|
|
$client = IO::Socket::SSL->new(
|
|
|
|
PeerAddr => $xcatHost,
|
|
|
|
SSL_key_file => $keyfile,
|
|
|
|
SSL_cert_file => $certfile,
|
|
|
|
SSL_ca_file => $cafile,
|
|
|
|
SSL_use_cert => 1,
|
|
|
|
Timeout => 15,);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$client = IO::Socket::SSL->new(
|
|
|
|
PeerAddr => $xcatHost,
|
|
|
|
Timeout => 15,);
|
|
|
|
}
|
|
|
|
unless ($client) {
|
|
|
|
if ($@ =~ /SSL Timeout/) {
|
|
|
|
addPageContent("Connection failure: SSL Timeout or incorrect certificates in ~/.xcat");
|
|
|
|
sendResponseMsg($STATUS_TIMEOUT);
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-02-16 02:42:44 +00:00
|
|
|
addPageContent("Connection failurexx: $@");
|
|
|
|
sendResponseMsg($STATUS_SERVICE_UNAVAILABLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
print $client $request;
|
|
|
|
|
|
|
|
my $response;
|
|
|
|
my $rsp;
|
|
|
|
my @fullResponse;
|
|
|
|
my $cleanexit = 0;
|
|
|
|
while (<$client>) {
|
|
|
|
$response .= $_;
|
|
|
|
if (m/<\/xcatresponse>/) {
|
|
|
|
|
|
|
|
#replace ESC with xxxxESCxxx because XMLin cannot handle it
|
2012-02-22 02:24:16 +00:00
|
|
|
if ($DEBUGGING) {
|
|
|
|
addPageContent($response . "\n");
|
|
|
|
}
|
2012-02-16 02:42:44 +00:00
|
|
|
$response =~ s/\e/xxxxESCxxxx/g;
|
|
|
|
|
|
|
|
#print "responseXML is ".$response;
|
|
|
|
$rsp = XMLin($response, SuppressEmpty => undef, ForceArray => 1);
|
|
|
|
|
|
|
|
#add ESC back
|
|
|
|
foreach my $key (keys %$rsp) {
|
|
|
|
if (ref($rsp->{$key}) eq 'ARRAY') {
|
|
|
|
foreach my $text (@{$rsp->{$key}}) {
|
|
|
|
next unless defined $text;
|
|
|
|
$text =~ s/xxxxESCxxxx/\e/g;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$rsp->{$key} =~ s/xxxxESCxxxx/\e/g;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$response = '';
|
|
|
|
push(@fullResponse, $rsp);
|
|
|
|
if ($rsp->{serverdone}) {
|
|
|
|
$cleanexit = 1;
|
|
|
|
last;
|
|
|
|
}
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
2012-02-16 02:42:44 +00:00
|
|
|
}
|
|
|
|
unless ($cleanexit) {
|
|
|
|
addPageContent("ERROR/WARNING: communication with the xCAT server seems to have been ended prematurely");
|
|
|
|
sendResponseMsg($STATUS_SERVICE_UNAVAILABLE);
|
|
|
|
exit(0);
|
|
|
|
}
|
2011-05-20 15:36:27 +00:00
|
|
|
|
2012-02-16 02:42:44 +00:00
|
|
|
if ($DEBUGGING) {
|
|
|
|
addPageContent($q->p("response " . Dumper(@fullResponse)));
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
2012-02-16 02:42:44 +00:00
|
|
|
return @fullResponse;
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 02:42:44 +00:00
|
|
|
sub isGet {
|
|
|
|
return uc($requestType) eq "GET";
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 02:42:44 +00:00
|
|
|
sub isPut {
|
|
|
|
return uc($requestType) eq "PUT";
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 02:42:44 +00:00
|
|
|
sub isPost {
|
|
|
|
return uc($requestType) eq "POST";
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 02:42:44 +00:00
|
|
|
sub isPatch {
|
|
|
|
return uc($requestType) eq "PATCH";
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 02:42:44 +00:00
|
|
|
sub isDelete {
|
|
|
|
return uc($requestType) eq "DELETE";
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#check to see if this is a valid user. userName and password are already set
|
2012-02-16 02:42:44 +00:00
|
|
|
sub isAuthenticUser {
|
|
|
|
$request->{command} = 'authcheck';
|
|
|
|
my $req = genRequest();
|
|
|
|
my @responses = sendRequest($req);
|
|
|
|
if ($responses[0]->{data}[0] eq "Authenticated") {
|
|
|
|
|
|
|
|
#user is authenticated
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#authentication failure
|
|
|
|
addPageContent($responses[0]->{error}[0]);
|
|
|
|
sendResponseMsg($STATUS_UNAUTH);
|
2011-05-20 15:36:27 +00:00
|
|
|
}
|