diff --git a/xCAT-UI/js/service/service.js b/xCAT-UI/js/service/service.js index 2f938b5ba..a30f7533d 100644 --- a/xCAT-UI/js/service/service.js +++ b/xCAT-UI/js/service/service.js @@ -108,6 +108,7 @@ function loadServicePage() { success : function(data) { setUserNodes(data); + setMaxVM(); getUserNodesDef(); getNodesCurrentLoad(); loadManagePage(manageTabId); @@ -190,6 +191,18 @@ function loadServiceProvisionPage(tabId) { */ var okBtn = createButton('Ok'); okBtn.bind('click', function(event) { + var userName = $.cookie('srv_usrname'); + var tmp = $.cookie(userName + '_usrnodes'); + var nodes = tmp.split(','); + var maxVM = parseInt($.cookie(userName + '_maxvm')); + + // Do not allow user to clone if the maximum number of VMs is reached + if (nodes.length >= maxVM) { + var warn = createWarnBar('You have reached the maximum number of VMs allowed. Please de-allocate some existing VMs to free up space or contact your system administrator request more VMs.'); + warn.prependTo($('#' + tabId)); + return; + } + // Get hardware that was selected var hw = $(this).parent().find('input[name="hw"]:checked').val(); var newTabId = hw + 'ProvisionTab'; @@ -287,7 +300,7 @@ function getUserNodesDef() { } else { // Clear the tab before inserting the table $('#manageTab').children().remove(); - $('#manageTab').append(createWarnBar('You are not managing any node. Try to provision a node.')); + $('#manageTab').append(createWarnBar('Could not find any nodes that belong to you. Do you have any? Or did your session expire?')); } } @@ -446,8 +459,7 @@ function loadNodesTable(data) { $('#' + nodesDTId).dataTable({ 'iDisplayLength': 50, 'bLengthChange': false, - "sScrollX": "100%", - "sScrollXInner": "110%" + "sScrollX": "100%" }); // Set datatable header class to add color @@ -565,12 +577,13 @@ function loadNodesTable(data) { success : function(data) { // Save nodes owned by user setUserNodes(data); + getNodesCurrentLoad(); // Refresh nodes table var userName = $.cookie('srv_usrname'); var userNodes = $.cookie(userName + '_usrnodes'); - if (userNodes) { - // Get nodes definitions + if (userNodes) { + // Get nodes definitions $.ajax( { url : 'lib/srv_cmd.php', dataType : 'json', @@ -1257,7 +1270,19 @@ function monitorNode(node, monitor) { * @return Nothing */ function cloneNode(tgtNodes) { + var userName = $.cookie('srv_usrname'); var nodes = tgtNodes.split(','); + var tmp = $.cookie(userName + '_usrnodes'); + var usrNodes = tmp.split(','); + + var maxVM = parseInt($.cookie(userName + '_maxvm')); + + // Do not allow user to clone if the maximum number of VMs is reached + if (usrNodes.length >= maxVM) { + var warn = createWarnBar('You have reached the maximum number of VMs allowed. Please de-allocate some existing VMs to free up space or contact your system administrator request more VMs.'); + warn.prependTo($('#manageTab')); + return; + } for (var n in nodes) { // Get hardware that was selected @@ -2093,4 +2118,33 @@ function getNodeAttr(node, attrName) { } else { return ''; } +} + +/** + * Set the maximum number of VMs a user could have + */ +function setMaxVM() { + var userName = $.cookie('srv_usrname'); + + $.ajax( { + url : 'lib/srv_cmd.php', + dataType : 'json', + data : { + cmd : 'webportal', + tgt : '', + args : 'getmaxvm;' + userName, + msg : '' + }, + + success : function(data) { + // Get response + var rsp = jQuery.trim(data.rsp); + rsp = rsp.replace('Max allowed:', ''); + + // Set cookie to expire in 60 minutes + var exDate = new Date(); + exDate.setTime(exDate.getTime() + (240 * 60 * 1000)); + $.cookie(userName + '_maxvm', rsp, { expires: exDate }); + } + }); } \ No newline at end of file diff --git a/xCAT-UI/xcat/plugins/webportal.pm b/xCAT-UI/xcat/plugins/webportal.pm index b09bbee61..efd860f4d 100644 --- a/xCAT-UI/xcat/plugins/webportal.pm +++ b/xCAT-UI/xcat/plugins/webportal.pm @@ -36,7 +36,9 @@ sub process_request { my %authorized_cmds = ( 'lszvm' => \&lszvm, 'provzlinux' => \&provzlinux, - 'clonezlinux' => \&clonezlinux + 'clonezlinux' => \&clonezlinux, + 'genhostip' => \&genhostip, + 'getmaxvm' => \&getmaxvm ); # Check if the request is authorized @@ -470,4 +472,40 @@ sub clonezlinux { println( $callback, "$out" ); println( $callback, " rootpw = Same as source node" ); } + +sub genhostip { + my ( $request, $callback, $sub_req ) = @_; + my $group = $request->{arg}->[1]; + + my ($node, $base_digit) = gennodename( $callback, $group ); + println( $callback, "$node" ); +} + +sub getmaxvm { + my ( $request, $callback, $sub_req ) = @_; + my $user = $request->{arg}->[1]; + + my @args; + my $max; + + # Look in 'policy' table + my $tab = xCAT::Table->new( 'policy', -create => 1, -autocommit => 0 ); + my @results = $tab->getAllAttribsWhere( "name='" . $user . "'", 'comments' ); + foreach (@results) { + if ( $_->{'comments'} ) { + @args = split( ';', $_->{'comments'} ); + + # Extract max VM + foreach (@args) { + if ($_ =~ m/max-vm:/i) { + $_ =~ s/max-vm://g; + $max = $_; + last; + } + } + } + } + + $callback->( { data => "Max allowed: $max" } ); +} 1; \ No newline at end of file