From 291b5441a9a9f11810846a8246d787d9bff28153 Mon Sep 17 00:00:00 2001 From: mxi1 Date: Mon, 15 Jun 2009 11:23:10 +0000 Subject: [PATCH] -Add web.pm and webrun command to support xCAT web interface; webrun now can support pping and update ,but still in development git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@3578 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-client/xCAT-client.spec | 1 + xCAT-server/lib/xcat/plugins/web.pm | 92 +++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 xCAT-server/lib/xcat/plugins/web.pm diff --git a/xCAT-client/xCAT-client.spec b/xCAT-client/xCAT-client.spec index 9efacda09..34ecc383b 100644 --- a/xCAT-client/xCAT-client.spec +++ b/xCAT-client/xCAT-client.spec @@ -157,6 +157,7 @@ ln -sf ../bin/xcatclientnnr $RPM_BUILD_ROOT/%{prefix}/bin/monadd ln -sf ../bin/xcatclientnnr $RPM_BUILD_ROOT/%{prefix}/bin/monrm ln -sf ../bin/xcatclientnnr $RPM_BUILD_ROOT/%{prefix}/bin/sinv ln -sf ../bin/xcatclientnnr $RPM_BUILD_ROOT/%{prefix}/bin/rollupdate +ln -sf ../bin/xcatclientnnr $RPM_BUILD_ROOT/%{prefix}/bin/webrun ln -sf ../bin/xcatDBcmds $RPM_BUILD_ROOT/%{prefix}/bin/mkdsklsnode ln -sf ../bin/xcatDBcmds $RPM_BUILD_ROOT/%{prefix}/bin/rmdsklsnode ln -sf ../bin/xcatDBcmds $RPM_BUILD_ROOT/%{prefix}/bin/mknimimage diff --git a/xCAT-server/lib/xcat/plugins/web.pm b/xCAT-server/lib/xcat/plugins/web.pm new file mode 100644 index 000000000..b9eaa3f8b --- /dev/null +++ b/xCAT-server/lib/xcat/plugins/web.pm @@ -0,0 +1,92 @@ +# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html +#------------------------------------------------------- +=head 1 + xCAT plugin package to handle webrun command + +=cut +#------------------------------------------------------- + +package xCAT_plugin::web; +use strict; + +require xCAT::Utils; + +require xCAT::MsgUtils; + +use Getopt::Long; +use Data::Dumper; + + +sub handled_commands +{ + return { webrun => "web",}; +} + +#sub preprocess_request +#{ +#} + +sub process_request +{ + my $request = shift; + my $callback = shift; + my $sub_req = shift; + my %authorized_cmds = ( + #command => function + 'pping' => \&web_pping, + 'update'=> \&web_update, + #'xdsh' => \&web_xdsh, + #THIS list needs to be updated + ); + + #to check whether the request is authorized or not + split ' ', $request->{arg}->[0]; + my $cmd = $_[0]; + if(grep { $_ eq $cmd } keys %authorized_cmds) { + my $func = $authorized_cmds{$cmd}; + $func->($request, $callback, $sub_req); + } + else { + $callback->({error=>"$cmd is not authorizied!\n",errorcode=>[1]}); + } +} + +sub web_pping { + my ($request, $callback, $sub_req) = @_; + #treat the argument as the commandline, run it and get the return message + my $ret = `$request->{arg}->[0]`; + + #parse the message, and use $callback to send back to the web interface + + #the message is like this: + # xcat_n02: ping + # xcat_n03: ping + # xcat_n51: ping + # xcat_n52: noping + my @total_stat = split '\n', $ret; + my $str; + foreach $str(@total_stat) { + #TODO + split ':', $str; + $callback->({node=>[{name=>[$_[0]],data=>[{contents=>[$_[1]]}]}]}); + } +} + +sub web_update { + my ($request, $callback, $sub_req) = @_; + #update the xcat-web rpm package + #TODO + #Note: this is not finished now! + my $repo_dir = "/root/svn/xcat-core/trunk/aix-core-snap"; + my $REPO; + my @flist; + if( -d $repo_dir) { + opendir REPO, $repo_dir; + @flist = readdir REPO; + } + closedir REPO; + #get the name of xcat-web package + my ($file) = grep(/^xCAT\-web/, @flist); + + system("rpm -Uvh $repo_dir/$file");#TODO:use runcmd() to replace it +}