diff --git a/xCAT-UI/js/configure/service.js b/xCAT-UI/js/configure/service.js index 00a4fb9ea..25ba5894a 100644 --- a/xCAT-UI/js/configure/service.js +++ b/xCAT-UI/js/configure/service.js @@ -731,7 +731,7 @@ function configGroupPanel(data) { // Create table var tableId = panelId + 'Datatable'; var table = new DataTable(tableId); - table.init(['', 'Name', 'Selectable', 'IP', 'Hostname', 'Network', 'Description']); + table.init(['', 'Name', 'Selectable', 'IP', 'Hostname', 'Description']); // Insert groups into table var nodePos = 0; @@ -787,12 +787,6 @@ function configGroupPanel(data) { desc = jQuery.trim(desc); } - // Save network - if (tmp[j].indexOf('network:') > -1) { - network = tmp[j].replace('network:', ''); - network = jQuery.trim(network); - } - // Is the group selectable? if (tmp[j].indexOf('selectable:') > -1) { selectable = tmp[j].replace('selectable:', ''); @@ -802,7 +796,7 @@ function configGroupPanel(data) { } // Columns are: name, selectable, network, and description - var cols = new Array(name, selectable, ip, hostname, network, desc); + var cols = new Array(name, selectable, ip, hostname, desc); // Add remove button where id = user name cols.unshift(''); @@ -851,10 +845,9 @@ function configGroupPanel(data) { var selectable = cols.eq(2).text(); var ip = cols.eq(3).text(); var hostnames = cols.eq(4).text(); - var network = cols.eq(5).text(); - var description = cols.eq(6).text(); + var description = cols.eq(5).text(); - editGroupDialog(group, selectable, ip, hostnames, network, description); + editGroupDialog(group, selectable, ip, hostnames, description); } } }); @@ -913,9 +906,10 @@ function groupDialog() { var selectable = $('
'); var ip = $(''); var hostnames = $(''); - var network = $(''); var comments = $(''); - groupForm.append(group, selectable, ip, hostnames, network, comments); + var ipPool = $(''); + + groupForm.append(group, selectable, ip, hostnames, comments, ipPool); // Generate tooltips groupForm.find('div input[title],textarea[title],select[title]').tooltip({ @@ -945,7 +939,7 @@ function groupDialog() { close: function(){ $(this).remove(); }, - width: 400, + width: 600, buttons: { "Ok": function() { // Remove any warning messages @@ -956,12 +950,12 @@ function groupDialog() { var selectable = $(this).find('input[name="selectable"]'); var ip = $(this).find('input[name="ip"]'); var hostnames = $(this).find('input[name="hostnames"]'); - var network = $(this).find('input[name="network"]'); var comments = $(this).find('input[name="comments"]'); + var ipPool = $(this).find('textarea[name=ip_pool]').val(); // Check that group attributes are provided before continuing var ready = 1; - var inputs = new Array(group, ip, hostnames, network); + var inputs = new Array(group, ip, hostnames); for (var i in inputs) { if (!inputs[i].val()) { inputs[i].css('border-color', 'red'); @@ -980,6 +974,10 @@ function groupDialog() { 'Close': function() {$(this).dialog("close");} }); + // A newline at the end of IP pool is needed + ipPool = ipPool.replace(/^\s+|\s+$/g, ''); + ipPool += '\n'; + // Set default description if (!comments.val()) comments.val('No description'); @@ -988,12 +986,12 @@ function groupDialog() { var args = "updategroup;" + group.val() + ";'" + ip.val() + "';'" + hostnames.val() + "';"; if (selectable.attr("checked")) - args += "'description:" + comments.val() + "|network:" + network.val() + "|selectable:yes"; + args += "'description:" + comments.val() + "|selectable:yes"; else - args += "'description:" + comments.val() + "|network:" + network.val() + "|selectable:no"; + args += "'description:" + comments.val() + "|selectable:no"; // Add image to xCAT - $.ajax( { + $.ajax({ url : 'lib/cmd.php', dataType : 'json', data : { @@ -1005,6 +1003,37 @@ function groupDialog() { success : updatePanel }); + + // Write IP pool file to /var/tmp + $.ajax({ + url : 'lib/cmd.php', + dataType : 'json', + data : { + cmd : 'write', + tgt : '/var/tmp/' + group.val() + '.pool', + args : '', + cont : ipPool, + msg : dialogId + ';' + group.val() + }, + + success : function(data) { + var args = data.msg.split(';'); + + // Create profile in xCAT + $.ajax({ + url : 'lib/cmd.php', + dataType : 'json', + data : { + cmd : 'webrun', + tgt : '', + args : 'mkippool;' + args[1], + msg : args[0] + }, + + success: updatePanel + }); + } + }); } }, "Cancel": function() { @@ -1021,10 +1050,9 @@ function groupDialog() { * @param iSelectable Is group selectable from the service page * @param iIp Group IP regex * @param iHostnames Group hostnames regex - * @param iNetwork Group network, e.g. 10.1.2.0/24 * @param iComments Group description */ -function editGroupDialog(iGroup, iSelectable, iIp, iHostnames, iNetwork, iComments) { +function editGroupDialog(iGroup, iSelectable, iIp, iHostnames, iComments) { // Create form to add profile var dialogId = 'createGroup-' + iGroup; var groupForm = $(''); @@ -1037,15 +1065,32 @@ function editGroupDialog(iGroup, iSelectable, iIp, iHostnames, iNetwork, iCommen var selectable = $(''); var ip = $(''); var hostnames = $(''); - var network = $(''); var comments = $(''); - groupForm.append(group, selectable, ip, hostnames, network, comments); + var ipPool = $(''); + + groupForm.append(group, selectable, ip, hostnames, comments, ipPool); + + // Query IP pool based on group name + $.ajax({ + url : 'lib/cmd.php', + dataType : 'json', + data : { + cmd : 'webrun', + tgt : '', + args : 'lsippool;' + iGroup, + msg : dialogId + }, + + success : function(data) { + // Populate textarea with IP pool entries + $('#' + data.msg).find('textarea[name="ip_pool"]').val(data.rsp[0]); + } + }); // Fill in group attributes groupForm.find('input[name="group"]').val(iGroup); groupForm.find('input[name="ip"]').val(iIp); groupForm.find('input[name="hostnames"]').val(iHostnames); - groupForm.find('input[name="network"]').val(iNetwork); groupForm.find('input[name="comments"]').val(iComments); if (iSelectable == "yes") groupForm.find('input[name="selectable"]').attr('checked', 'checked'); @@ -1078,7 +1123,7 @@ function editGroupDialog(iGroup, iSelectable, iIp, iHostnames, iNetwork, iCommen close: function(){ $(this).remove(); }, - width: 400, + width: 600, buttons: { "Ok": function() { // Remove any warning messages @@ -1089,12 +1134,12 @@ function editGroupDialog(iGroup, iSelectable, iIp, iHostnames, iNetwork, iCommen var selectable = $(this).find('input[name="selectable"]'); var ip = $(this).find('input[name="ip"]'); var hostnames = $(this).find('input[name="hostnames"]'); - var network = $(this).find('input[name="network"]'); var comments = $(this).find('input[name="comments"]'); + var ipPool = $(this).find('textarea[name=ip_pool]').val(); // Check that group attributes are provided before continuing var ready = 1; - var inputs = new Array(group, ip, hostnames, network); + var inputs = new Array(group, ip, hostnames); for (var i in inputs) { if (!inputs[i].val()) { inputs[i].css('border-color', 'red'); @@ -1113,6 +1158,10 @@ function editGroupDialog(iGroup, iSelectable, iIp, iHostnames, iNetwork, iCommen 'Close': function() {$(this).dialog("close");} }); + // A newline at the end of IP pool is needed + ipPool = ipPool.replace(/^\s+|\s+$/g, ''); + ipPool += '\n'; + // Set default description if (!comments.val()) comments.val('No description'); @@ -1121,9 +1170,9 @@ function editGroupDialog(iGroup, iSelectable, iIp, iHostnames, iNetwork, iCommen var args = "updategroup;" + group.val() + ";'" + ip.val() + "';'" + hostnames.val() + "';"; if (selectable.attr("checked")) - args += "'description:" + comments.val() + "|network:" + network.val() + "|selectable:yes"; + args += "'description:" + comments.val() + "|selectable:yes"; else - args += "'description:" + comments.val() + "|network:" + network.val() + "|selectable:no"; + args += "'description:" + comments.val() + "|selectable:no"; // Add image to xCAT $.ajax( { @@ -1138,6 +1187,37 @@ function editGroupDialog(iGroup, iSelectable, iIp, iHostnames, iNetwork, iCommen success : updatePanel }); + + // Write IP pool file to /var/tmp + $.ajax({ + url : 'lib/cmd.php', + dataType : 'json', + data : { + cmd : 'write', + tgt : '/var/tmp/' + group.val() + '.pool', + args : '', + cont : ipPool, + msg : dialogId + ';' + group.val() + }, + + success : function(data) { + var args = data.msg.split(';'); + + // Create profile in xCAT + $.ajax({ + url : 'lib/cmd.php', + dataType : 'json', + data : { + cmd : 'webrun', + tgt : '', + args : 'mkippool;' + args[1], + msg : args[0] + }, + + success: updatePanel + }); + } + }); } }, "Cancel": function() { diff --git a/xCAT-UI/xcat/plugins/web.pm b/xCAT-UI/xcat/plugins/web.pm index f80a6e8f0..23ecc02bf 100644 --- a/xCAT-UI/xcat/plugins/web.pm +++ b/xCAT-UI/xcat/plugins/web.pm @@ -70,6 +70,9 @@ sub process_request { 'deleteuser' => \&web_deleteuser, 'mkzprofile' => \&web_mkzprofile, 'rmzprofile' => \&web_rmzprofile, + 'mkippool' => \&web_mkippool, + 'rmippool' => \&web_rmippool, + 'lsippool' => \&web_lsippool, 'updateosimage' => \&web_updateosimage, 'rmosimage' => \&web_rmosimage, 'updategroup' => \&web_updategroup, @@ -2369,6 +2372,7 @@ sub web_mkzprofile() { `echo "$var=$size" >> /var/opt/xcat/profiles/$profile.conf`; # Move directory entry into /var/opt/xcat/profiles from /var/tmp + `mkdir -p /var/opt/xcat/profiles`; `mv /var/tmp/$profile.direct /var/opt/xcat/profiles`; my $info = "Profile successfully created/updated"; @@ -2394,6 +2398,60 @@ sub web_rmzprofile() { $callback->( { info => $info } ); } +sub web_mkippool() { + + # Create group IP pool + my ( $request, $callback, $sub_req ) = @_; + + # Get profile + my $group = $request->{arg}->[1]; + + # Move directory entry into /var/opt/xcat/ippool from /var/tmp + `mkdir -p /var/opt/xcat/ippool`; + `mv /var/tmp/$group.pool /var/opt/xcat/ippool`; + + my $info = "IP pool successfully created/updated"; + $callback->( { info => $info } ); +} + +sub web_rmippool() { + + # Delete group IP pool + my ( $request, $callback, $sub_req ) = @_; + + # Get profile + my $group = $request->{arg}->[1]; + my @groups = split( ',', $group ); + + # Delete IP pool under /var/opt/xcat/ippool + foreach (@groups) { + `rm -rf /var/opt/xcat/ippool/$_.pool`; + } + + my $info = "IP pool successfully deleted"; + $callback->( { info => $info } ); +} + +sub web_lsippool() { + + # List IP pool + my ( $request, $callback, $sub_req ) = @_; + + # Get profile + my $group = $request->{arg}->[1]; + + # IP pool contained in /var/opt/xcat/ippool where a file exists per group + my $entries; + if ( !(`test -e /var/opt/xcat/ippool/$group.pool && echo Exists`) ) { + $entries = "No IP pool found!"; + } else { + # List IP pool under /var/opt/xcat/ippool + $entries = `cat /var/opt/xcat/ippool/$group.pool`; + } + + $callback->( { info => $entries } ); +} + sub web_updateosimage() { # Add OS image to xCAT table @@ -2464,6 +2522,7 @@ sub web_rmgroup() { # Delete user from xCAT passwd and policy tables foreach (@names) { `chtab -d node=$_ hosts`; + `rm -rf /var/opt/xcat/ippool/$_.pool`; } my $info = "Group successfully deleted"; diff --git a/xCAT-UI/xcat/plugins/webportal.pm b/xCAT-UI/xcat/plugins/webportal.pm index 22b79f3c8..2f1efe902 100644 --- a/xCAT-UI/xcat/plugins/webportal.pm +++ b/xCAT-UI/xcat/plugins/webportal.pm @@ -848,7 +848,7 @@ sub findfreenode { my $ipaddr; my $hostname; - my $out = `cat /var/opt/xcat/ippool/$group.pool | sed 1d`; + my $out = `cat /var/opt/xcat/ippool/$group.pool | grep -v "#"`; my @entries = split( /\n/, $out ); if (@entries < 1) { return;