support provision linux for system x/p on nodes page

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@9970 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
xq2005 2011-06-28 08:37:16 +00:00
parent 1b8b430116
commit ddced88dba
3 changed files with 299 additions and 3 deletions

View File

@ -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 = $('<a>Provision</a>');
provisionLnk.click(function(){
var tgtNodes = getNodesChecked(nodesTableId);
if (tgtNodes){
openQuickProvisionDia(tgtNodes);
}
});
// Remote console
var rcons = $('<a>Open console</a>');
@ -844,7 +853,7 @@ function loadNodes(data) {
var configMenu = createMenu([cloneLnk, deleteLnk, unlockLnk, updateLnk, editProps, installMonLnk]);
// Advanced actions
var advancedLnk = '<a>Advanced</a>';
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 = $('<div title="Provision(only support Linux)" class="form" id="deployDiv"></div>');
//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!<br/>';
break;
}
}
//check the mac address
for (index in nodeArray){
if (!origAttrs[nodeName]['mac']){
errormessage += 'All nodes should define mac!<br/>';
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 = '<table><tbody>';
showstr += '<tr><td>Target node:</td><td><input id="nodesinput" value="' + tgtnodes + '" readonly="readonly"></td></tr>';
showstr += '<tr><td>Arch:</td><td><input id="archinput" value="' + archtype + '" disabled="disabled"></td></tr>';
showstr += '<tr><td>Image:</td><td><select></select></td></tr>';
showstr += '<tr><td>OS:</td><td><input id="osinput" disabled="disabled"></td></tr>';
showstr += '<tr><td>Provmethod:</td><td><input id="provinput" disabled="disabled"></td></tr>';
showstr += '<tr><td>Profile:</td><td><input id="profinput" disabled="disabled"></td></tr>';
showstr += '<tr><td>Install Nic:</td><td><input id="inicinput" value="ent0"></td></tr>';
showstr += '<tr><td>Primary Nic:</td><td><input id="pnicinput" value="ent0"></td></tr>';
showstr += '<tr><td>xCAT Master:</td><td><input id="masterinput"></td></tr>';
showstr += '<tr><td>TFTP Server:</td><td><input id="tftpinput"></td></tr>';
showstr += '<tr><td>NFS Server:</td><td><input id="nfsinput"></td></tr>';
showstr += '</tbody></table>';
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('<option value="' + imagename + '">' + imagename + '</option>');
}
$('#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('<p class="ui-state-error">' + errormessage + '</p>');
return;
}
$('#deployDiv input').each(function(){
argsArray.push($(this).val());
});
nodesName = argsArray.shift();
provisionArg = argsArray.join(',');
$('#deployDiv').empty().append(createLoader()).append('<br/>');
$('#deployDiv').dialog( "option", "buttons", {'Close': function(){$(this).remove();clearTimeout(provisionClock);}});
$('#deployDiv').dialog( "option", "width", 600);
provisionFrame = $('<iframe id="provisionFrame" width="95%" height="90%"></iframe>');
$('#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);
}
}

View File

@ -110,6 +110,7 @@ function submit_request($req, $skipVerify, $opts_array){
} else {
// Print out output by default
echo $tmp . '<br/>';
ob_flush();
flush();
}
}

View File

@ -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;