diff --git a/xCAT-UI/js/nodes/nodes.js b/xCAT-UI/js/nodes/nodes.js
index 7b50225b5..41b19a741 100644
--- a/xCAT-UI/js/nodes/nodes.js
+++ b/xCAT-UI/js/nodes/nodes.js
@@ -11,7 +11,8 @@ var nodeAttrs;
var nodesList;
// Nodes datatable ID
var nodesTableId = 'nodesDatatable';
-
+// provision clock for provision progress stop
+var provisionClock;
/**
* Set node tab
*
@@ -807,6 +808,14 @@ function loadNodes(data) {
loadNetbootPage(tgtNodes);
}
});
+
+ var provisionLnk = $('Provision');
+ provisionLnk.click(function(){
+ var tgtNodes = getNodesChecked(nodesTableId);
+ if (tgtNodes){
+ openQuickProvisionDia(tgtNodes);
+ }
+ });
// Remote console
var rcons = $('Open console');
@@ -844,7 +853,7 @@ function loadNodes(data) {
var configMenu = createMenu([cloneLnk, deleteLnk, unlockLnk, updateLnk, editProps, installMonLnk]);
// Advanced actions
var advancedLnk = 'Advanced';
- var advancedActionMenu = createMenu([ boot2NetworkLnk, setBootStateLnk, rcons]);
+ var advancedActionMenu = createMenu([ boot2NetworkLnk, setBootStateLnk, rcons, provisionLnk]);
// Create an action menu
var actionsMenu = createMenu([ [ powerLnk, powerActionMenu ], [ configLnk, configMenu ], [ advancedLnk, advancedActionMenu ] ]);
@@ -3344,4 +3353,186 @@ function advancedLoad(group){
});
}
} // End of for
+}
+
+/**
+ * when click the provison button, show this dislog for provision
+ * this is the quick way to deploy on the nodes page.
+ *
+ * @return Nothing
+ */
+function openQuickProvisionDia(tgtnodes){
+ var nodeArray = tgtnodes.split(',');
+ var nodeName = '';
+ var index = 0;
+ var archtype = '';
+ var errormessage = '';
+ var diaDiv = $('
');
+ //check the first node's arch type
+ for (index in nodeArray){
+ nodeName = nodeArray[index];
+ //does not have arch
+ if (!origAttrs[nodeName]['arch']){
+ errormessage = 'All nodes should define arch first!';
+ break;
+ }
+
+ if (0 == index){
+ archtype = origAttrs[nodeName]['arch'];
+ }
+
+ //all nodes should have same archtype
+ if (archtype != origAttrs[nodeName]['arch']){
+ errormessage = 'All nodes should belong to same arch!
';
+ break;
+ }
+ }
+
+ //check the mac address
+ for (index in nodeArray){
+ if (!origAttrs[nodeName]['mac']){
+ errormessage += 'All nodes should define mac!
';
+ break;
+ }
+ }
+
+ if (-1 != archtype.indexOf('390')){
+ errormessage += 'System Z should use provision page.';
+ }
+
+ //error message should show in a dialog
+ if ('' != errormessage){
+ diaDiv.append(createWarnBar(errormessage));
+ diaDiv.dialog({
+ modal: true,
+ width: 400,
+ buttons: {
+ 'Close': function(){
+ $(this).dialog('destroy');
+ }
+ }
+ });
+
+ return;
+ }
+
+ //organize the provison dialog
+ var showstr = '';
+
+ diaDiv.append(showstr);
+ diaDiv.dialog({
+ modal: true,
+ width: 400,
+ height: 480,
+ close: function(){$(this).remove();},
+ buttons: {
+ 'Close': function(){$(this).remove();}
+ }
+ });
+
+ $('#deployDiv select').parent().append(createLoader());
+ $.ajax({
+ url : 'lib/cmd.php',
+ dataType : 'json',
+ data : {
+ cmd : 'lsdef',
+ tgt : '',
+ args : '-t;osimage;-w;osarch==' + archtype,
+ msg : ''
+ },
+
+ success : function(data){
+ var index = 0;
+ var imagename = 0;
+ var position = 0;
+ $('#deployDiv img').remove();
+ if (data.rsp.lenght < 1){
+ $('#deployDiv').append(createWarnBar('Please copycds and genimage in provision page first!'));
+ return;
+ }
+
+ for (index in data.rsp){
+ imagename = data.rsp[index];
+ position = imagename.indexOf(' ');
+ imagename = imagename.substr(0, position);
+
+ $('#deployDiv select').append('');
+ }
+
+ $('#deployDiv select').bind('change',function(){
+ var areaArray = $(this).val().split('-');
+ $('#deployDiv #osinput').val(areaArray[0]);
+ $('#deployDiv #provinput').val(areaArray[2]);
+ $('#deployDiv #profinput').val(areaArray[3]);
+ });
+
+ $('#deployDiv select').trigger('change');
+ $('#deployDiv').dialog( "option", "buttons", {'Ok': function(){quickProvision();},
+ 'Cancel': function(){$(this).remove();}}
+ );
+ }
+ });
+}
+
+/**
+ * get all needed field for provsion and send the command to server
+ *
+ * @return Nothing
+ */
+function quickProvision(){
+ var errormessage = '';
+ var argsArray = new Array();
+ var nodesName = '';
+ var provisionArg = '';
+ var provisionFrame;
+ $('#deployDiv .ui-state-error').remove();
+ $('#deployDiv input').each(function(){
+ if ('' == $(this).val()){
+ errormessage = 'You are missing input!';
+ return false;
+ }
+ });
+
+ if ('' != errormessage){
+ $('#deployDiv').prepend('' + errormessage + '
');
+ return;
+ }
+
+ $('#deployDiv input').each(function(){
+ argsArray.push($(this).val());
+ });
+
+ nodesName = argsArray.shift();
+ provisionArg = argsArray.join(',');
+ $('#deployDiv').empty().append(createLoader()).append('
');
+ $('#deployDiv').dialog( "option", "buttons", {'Close': function(){$(this).remove();clearTimeout(provisionClock);}});
+ $('#deployDiv').dialog( "option", "width", 600);
+ provisionFrame = $('');
+ $('#deployDiv').append(provisionFrame);
+ provisionFrame.attr('src', 'lib/cmd.php?cmd=webrun&tgt=&args=provision;' + nodesName + ';' + provisionArg + '&msg=&opts=flush');
+
+ provisionStopCheck();
+}
+
+function provisionStopCheck(){
+ var content = $('#provisionFrame').contents().find('body').text();
+ if (-1 != content.indexOf('provision stop')){
+ $('#deployDiv img').remove();
+ clearTimeout(provisionClock);
+ }
+ else{
+ provisionClock = setTimeout('provisionStopCheck()', 5000);
+ }
}
\ No newline at end of file
diff --git a/xCAT-UI/lib/functions.php b/xCAT-UI/lib/functions.php
index 8aa88130f..6416c4040 100644
--- a/xCAT-UI/lib/functions.php
+++ b/xCAT-UI/lib/functions.php
@@ -110,6 +110,7 @@ function submit_request($req, $skipVerify, $opts_array){
} else {
// Print out output by default
echo $tmp . '
';
+ ob_flush();
flush();
}
}
diff --git a/xCAT-server/lib/xcat/plugins/web.pm b/xCAT-server/lib/xcat/plugins/web.pm
index 074130b95..afb85e23c 100644
--- a/xCAT-server/lib/xcat/plugins/web.pm
+++ b/xCAT-server/lib/xcat/plugins/web.pm
@@ -48,7 +48,8 @@ sub process_request {
'monls' => \&web_monls,
'discover' => \&web_discover,
'updatevpd' => \&web_updatevpd,
- 'createimage' => \&web_createimage
+ 'createimage' => \&web_createimage,
+ 'provision' => \&web_provision
);
#check whether the request is authorized or not
@@ -1149,4 +1150,107 @@ sub web_restoreChange {
);
}
}
+
+sub web_provision{
+ my ( $request, $callback, $sub_req ) = @_;
+ my $nodes = $request->{arg}->[1];
+ my ($arch, $os, $provmethod, $profile, $inic, $pnic, $master, $tftp, $nfs)= split(/,/,$request->{arg}->[2]);
+ my $outputMessage = '';
+ my $retvalue = 0;
+ my $netboot = '';
+ if ($arch =~ /ppc/i){
+ $netboot = 'yaboot';
+ }
+ elsif($arch =~ /x.*86/i){
+ $netboot = 'xnba';
+ }
+ $outputMessage = "Do provison : $nodes \n".
+ " Arch:$arch\n OS:$os\n Provision:$provmethod\n Profile:$profile\n Install NIC:$inic\n Primary NIC:$pnic\n" .
+ " xCAT Master:$master\n TFTP Server:$tftp\n NFS Server:$nfs\n Netboot:$netboot\n";
+
+ web_infomsg($outputMessage, $callback);
+
+ #change the nodes attribute
+ my $cmd = "chdef -t node -o $nodes arch=$arch os=$os provmethod=$provmethod profile=$profile installnic=$inic tftpserver=$tftp nfsserver=$nfs netboot=$netboot" .
+ " xcatmaster=$master primarynic=$pnic";
+ web_runcmd($cmd, $callback);
+ #error return
+ if ($::RUNCMD_RC){
+ web_infomsg("Configure nodes' attributes error.\nprovision stop.", $callback);
+ return;
+ }
+
+ #dhcp
+ $cmd = "makedhcp $nodes";
+ web_runcmd($cmd, $callback);
+ if ($::RUNCMD_RC){
+ web_infomsg("Make DHCP error.\nprovision stop.", $callback);
+ return;
+ }
+ #restart dhcp
+ $cmd = "service dhcpd restart";
+ web_runcmd($cmd, $callback);
+ #conserver
+ $cmd = "makeconservercf;service conserver stop;service conserver start";
+ web_runcmd($cmd, $callback);
+ if ($::RUNCMD_RC){
+ web_infomsg("Configure conserver error.\nprovision stop.", $callback);
+ return;
+ }
+
+ #for system x, should configure boot sequence first.
+ if ($arch =~ /x.*86/i){
+ $cmd = "rbootseq $nodes net,hd";
+ web_runcmd($cmd, $callback);
+ if($::RUNCMD_RC){
+ web_infomsg("Set boot sequence error.\nprovision stop.", $callback);
+ return;
+ }
+ }
+
+ #nodeset
+ $cmd = "nodeset $nodes $provmethod";
+ web_runcmd($cmd, $callback);
+ if ($::RUNCMD_RC){
+ web_infomsg("Set nodes provision method error.\nprovision stop.", $callback);
+ return;
+ }
+
+ #reboot the node fro provision
+ if($arch =~ /ppc/i){
+ $cmd = "rnetboot $nodes";
+ }
+ else{
+ $cmd = "rpower $nodes boot";
+ }
+ web_runcmd($cmd, $callback);
+ if ($::RUNCMD_RC){
+ web_infomsg("Boot nodes error.\nprovision stop.", $callback);
+ return;
+ }
+
+ #provision complete
+ web_infomsg("Provision on $nodes success.\nprovision stop.");
+}
+
+#run the cmd by xCAT::Utils->runcmd and show information.
+sub web_runcmd{
+ my $cmd = shift;
+ my $callback = shift;
+ my $showstr = "\n" . $cmd . "\n";
+ web_infomsg($showstr, $callback);
+ my $retvalue = xCAT::Utils->runcmd($cmd, -1, 1);
+ $showstr = join("\n", @$retvalue);
+ $showstr .= "\n";
+ web_infomsg($showstr, $callback);
+}
+
+sub web_infomsg {
+ my $msg = shift;
+ my $callback = shift;
+ my %rsp;
+ push @{$rsp{info}}, $msg;
+ xCAT::MsgUtils->message('I', \%rsp, $callback);
+ return;
+}
1;