diff --git a/plugins/dynamix/CPUset.page b/plugins/dynamix/CPUset.page index e78b7b7a7..a54f57688 100644 --- a/plugins/dynamix/CPUset.page +++ b/plugins/dynamix/CPUset.page @@ -72,9 +72,14 @@ function apply(form) { // show the instant wait message $('#wait-'+id).show(); // step 1: prepare the update and report back the changes - $.post('/webGui/include/UpdateOne.php',args,function(d){ - if (d.success) { - var data = d.success.split(';'); + $.post('/webGui/include/UpdateOne.php',args,function(reply){ + if (reply.error) { + swal({type:'error', title:'Assignment error', text:reply.error},function(){ + $('#wait-'+id).hide(); + $(form).find('input[value="Done"]').val('Reset').prop('disabled',false).prop('onclick',null).off('click').click(function(){reset($('form[name="'+id+'"]'));}); + }); + } else if (reply.success) { + var data = reply.success.split(';'); wait = data.length; for (var i=0; i < data.length; i++) { var name = data[i]; diff --git a/plugins/dynamix/include/UpdateOne.php b/plugins/dynamix/include/UpdateOne.php index 79248c707..f985e14d8 100644 --- a/plugins/dynamix/include/UpdateOne.php +++ b/plugins/dynamix/include/UpdateOne.php @@ -22,12 +22,16 @@ foreach($_POST as $key => $val) { } // map holds the list of each vm or container and its newly proposed cpu assignments $map = array_map(function($d){return substr($d,0,-1);},$map); - +file_put_contents('/tmp/map',print_r($map,true)); switch ($_POST['id']) { case 'vm': // report changed vms in temporary file require_once "$docroot/plugins/dynamix.vm.manager/include/libvirt_helpers.php"; foreach ($map as $name => $cpuset) { + if (!strlen($cpuset)) { + $reply = ['error' => "Not allowed to assign ZERO cores"]; + break 2; + } $uuid = $lv->domain_get_uuid($lv->get_domain_by_name($name)); $cfg = domain_to_config($uuid); $cpus = implode(',',$cfg['domain']['vcpu']); @@ -38,6 +42,7 @@ case 'vm': file_put_contents("/var/tmp/$name.tmp",$cpuset); } } + $reply = ['success' => (count($changes) ? implode(';',$changes) : '')]; break; case 'ct': // update the XML file of the container @@ -65,10 +70,10 @@ case 'ct': exec("sed -ri 's/^(<(\\/Container)/>\\n <\\1/' \"$file\""); // aftercare } } + $reply = ['success' => (count($changes) ? implode(';',$changes) : '')]; break; } // signal changes -$reply = ['success' => (count($changes) ? implode(';',$changes) : '')]; header('Content-Type: application/json'); die(json_encode($reply)); ?>