mirror of
https://github.com/unraid/webgui.git
synced 2026-05-03 16:29:45 -05:00
WIP Update.
This commit is contained in:
@@ -326,15 +326,15 @@ _(ISO Image)_:
|
||||
<td><span id="VMBeingCloned"></span></td></tr>
|
||||
|
||||
<tr><td>_(New VM)_:</td>
|
||||
<td><input type="text" id="target" autocomplete="off" spellcheck="false" value="" ></td></tr>
|
||||
<td><input type="text" id="target" autocomplete="off" spellcheck="false" value="" onclick="this.select()" ></td></tr>
|
||||
|
||||
<tr><td>_(Overwrite)_:</td>
|
||||
<td><input type="checkbox" id="Overwrite" value="" ></td></tr>
|
||||
|
||||
<tr><td>_(Start Cloned VM)_:</td>
|
||||
<tr hidden><td>_(Start Cloned VM)_:</td>
|
||||
<td><input type="checkbox" id="Start" value="" ></td></tr>
|
||||
|
||||
<tr><td>_(Edit VM after clone)_:</td>
|
||||
<tr hidden><td>_(Edit VM after clone)_:</td>
|
||||
<td><input type="checkbox" id="Edit" value="" ></td></tr>
|
||||
|
||||
<tr><td>_(Check Free Space)_:</td>
|
||||
|
||||
@@ -1481,13 +1481,16 @@ private static $encoding = 'UTF-8';
|
||||
|
||||
If option to edit, show VMUpdate
|
||||
*/
|
||||
|
||||
$uuid = $lv->domain_get_uuid($clone) ;
|
||||
write("addLog\0".htmlspecialchars("checking if Clone UUID exists $uuid"));
|
||||
if ($uuid) { $arrResponse = ['error' => _("Clone VM name already inuse")]; return $arrResponse ;}
|
||||
#VM must be shutdown.
|
||||
$res = $lv->get_domain_by_name($vm);
|
||||
$dom = $lv->domain_get_info($res);
|
||||
$state = $lv->domain_state_translate($dom['state']);
|
||||
file_put_contents("/tmp/cloningxml" ,$lv->domain_get_xml($res)) ;
|
||||
# if VM running shutdown. Record was running.
|
||||
if ($state != 'shutdown') $arrResponse = $lv->domain_destroy($vm) ;
|
||||
if ($state != 'shutoff') {write("addLog\0".htmlspecialchars("Shuting down $vm current $state")); $arrResponse = $lv->domain_destroy($vm) ; }
|
||||
# Wait for shutdown?
|
||||
|
||||
$disks =$lv->get_disk_stats($vm) ;
|
||||
@@ -1498,7 +1501,6 @@ private static $encoding = 'UTF-8';
|
||||
$file = $disk["file"] ;
|
||||
$pathinfo = pathinfo($file) ;
|
||||
$filenew = $pathinfo["dirname"].'/'.$pathinfo["filename"].'.'.$name.'qcow2' ;
|
||||
$diskspec .= " --diskspec '".$disk["device"]."',snapshot=external,file='".$filenew."'" ;
|
||||
$capacity = $capacity + $disk["capacity"] ;
|
||||
}
|
||||
$dirpath = $pathinfo["dirname"] ;
|
||||
@@ -1509,7 +1511,7 @@ private static $encoding = 'UTF-8';
|
||||
|
||||
$capacity *= 1 ;
|
||||
|
||||
if ($free == "yes" && $dirfree < $capacity) { $arrResponse = ['error' => _("Insufficent Storage for Clone")]; return $arrResponse ;}
|
||||
if ($free == "yes" && $dirfree < $capacity) { write("addLog\0".htmlspecialchars("Insufficent Storage for Clone")); return false ;}
|
||||
|
||||
#Clone XML
|
||||
$uuid = $lv->domain_get_uuid($vm) ;
|
||||
@@ -1523,23 +1525,28 @@ private static $encoding = 'UTF-8';
|
||||
$config["domain"]["type"] = "kvm";
|
||||
|
||||
$files_exist = false ;
|
||||
$files_clone = array() ;
|
||||
foreach ($config["disk"] as $diskid => $disk) {
|
||||
$file_clone[$diskid]["source"] = $config["disk"][$diskid]["new"] ;
|
||||
$config["disk"][$diskid]["new"] = str_replace($vm,$clone,$config["disk"][$diskid]["new"]) ;
|
||||
$pi = pathinfo($config["disk"][$diskid]["new"]) ;
|
||||
$isdir = is_dir($pi['dirname']) ;
|
||||
if (is_file($config["disk"][$diskid]["new"])) $file_exists = true ;
|
||||
|
||||
$file_clone[$diskid]["target"] = $config["disk"][$diskid]["new"] ;
|
||||
}
|
||||
|
||||
$clonedir = $domain_cfg['DOMAINDIR'].$clone ;
|
||||
if (!is_dir($clonedir)) mkdir($clonedir) ;
|
||||
#write("addLog\0".htmlspecialchars("Overwrite $overwrite Start $start Edit $edit Check Freespace $free"));
|
||||
write("addLog\0".htmlspecialchars("Checking for image files"));
|
||||
if ($file_exists && $overwrite != "yes") { $arrResponse = ['error' => _("New image file names exist and Overwrite is no")]; return $arrResponse ;}
|
||||
if ($file_exists && $overwrite != "yes") { write("addLog\0".htmlspecialchars("New image file names exist and Overwrite is set to No")); return( false) ; }
|
||||
|
||||
#Create duplicate files.
|
||||
foreach($config["disk"] as $diskid => $disk) {
|
||||
$cmdstr = "touch {$config['disk'][$diskid]['new']}" ;
|
||||
foreach($file_clone as $diskid => $disk) {
|
||||
$cmdstr = "touch {$disk['target']}" ;
|
||||
$sparse = "-S ";
|
||||
$target = $disk['target'] ;
|
||||
$source = $disk['source'] ;
|
||||
$cmdstr = "rsync -ahPIX $sparse --out-format=%f --info=flist0,misc0,stats0,name1,progress2 '$source' '$target'" ;
|
||||
$error = execCommand_nchan($cmdstr,$path) ;
|
||||
if (!$error) {
|
||||
$arrResponse = ['error' => substr($output[0],6) ] ;
|
||||
@@ -1549,14 +1556,12 @@ private static $encoding = 'UTF-8';
|
||||
}
|
||||
|
||||
}
|
||||
write("<p class='logLine'></p>","addLog\0<fieldset class='docker'><legend>"._("Options for Block $action").": </legend><p class='logLine'></p><span id='wait-$waitID'>"._('Please wait')." </span></fieldset>");
|
||||
write("<p class='logLine'></p>","addLog\0<fieldset class='docker'><legend>"._("Options for Block $action").": </legend><p class='logLine'></p><span id='wait-$waitID'></span></fieldset>");
|
||||
write("addLog\0".htmlspecialchars("Creating new XML $clone"));
|
||||
$xml = $lv->config_to_xml($config) ;
|
||||
file_put_contents("/tmp/xml" ,$xml) ;
|
||||
|
||||
|
||||
$arrResponse = ['error' => _("Insufficent Storage for Clone")];
|
||||
return$arrResponse ;
|
||||
file_put_contents("/tmp/clonexml" ,$xml) ;
|
||||
$rtn = $lv->domain_define($xml) ;
|
||||
return($rtn) ;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -278,10 +278,9 @@ function VMClone(uuid, name){
|
||||
var height = 200;
|
||||
box.html($("#templateClone").html());
|
||||
box.find('#VMBeingCloned').html(name).change() ;
|
||||
box.find('#target').val(name + "_clone") ;
|
||||
document.getElementById("Free").checked = true ;
|
||||
document.getElementById("Overwrite").checked = true ;
|
||||
//document.getElementById("targetsnapkeep").checked = true ;
|
||||
//document.getElementById("targetsnapfspc").checked = true ;
|
||||
|
||||
box.dialog({
|
||||
title: "VM Clone",
|
||||
@@ -300,8 +299,6 @@ function VMClone(uuid, name){
|
||||
} else target = '';
|
||||
|
||||
var clone = box.find("#target").prop('value') ;
|
||||
|
||||
|
||||
x = box.find('#Start').prop('checked') ;
|
||||
if (x) start = 'yes' ; else start = 'no' ;
|
||||
x = box.find('#Edit').prop('checked') ;
|
||||
|
||||
@@ -39,14 +39,15 @@ function execCommand_nchan($command,$idx) {
|
||||
$waitID = mt_rand();
|
||||
[$cmd,$args] = explode(' ',$command,2);
|
||||
write("<p class='logLine'></p>","addLog\0<fieldset class='docker'><legend>"._('Command execution')."</legend>".basename($cmd).' '.str_replace(" -","<br> -",htmlspecialchars($args))."<br><span id='wait-$waitID'>"._('Please wait')." </span><p class='logLine'></p></fieldset>","show_Wait\0$waitID");
|
||||
write("addLog\0<br>") ;
|
||||
|
||||
write("addToID\0$idx\0 $action") ;
|
||||
$proc = popen("$command 2>&1",'r');
|
||||
while ($out = fgets($proc)) {
|
||||
$proc = popen("$command 2>&1 &",'r');
|
||||
while ($out = fread($proc,100)) {
|
||||
$out = preg_replace("%[\t\n\x0B\f\r]+%", '',$out);
|
||||
if (substr($out,0,1) == "B") { ;
|
||||
write("progress\0$idx\0".htmlspecialchars(substr($out,strrpos($out,"Block Pull")))) ;
|
||||
} else echo write("addToID\0$idx\0 ".htmlspecialchars($out));
|
||||
$out = trim($out) ;
|
||||
$values = explode(' ',$out) ;
|
||||
$string = "Data copied: ".$values[0]." Percentage: ".$values[1]." Transfer Rate: ".$values[2]." Time remaining: ".$values[3]." ".$values[4]." ".$values[5];
|
||||
write("progress\0$idx\0".htmlspecialchars($string)) ;
|
||||
}
|
||||
$retval = pclose($proc);
|
||||
$out = $retval ? _('The command failed').'.' : _('The command finished successfully').'!';
|
||||
@@ -73,18 +74,15 @@ foreach (explode('&', $url) as $chunk) {
|
||||
$id = 1 ;
|
||||
write(implode($style)."<p class='logLine'></p>");
|
||||
$process = " " ;
|
||||
write("<p class='logLine'></p>","addLog\0<fieldset class='docker'><legend>"._("Options for Block $action").": </legend><p class='logLine'></p><span id='wait-$waitID'>"._('Please wait')." </span></fieldset>");
|
||||
write("addLog\0".htmlspecialchars("VMName $name "));
|
||||
write("addLog\0".htmlspecialchars("Clone $clone "));
|
||||
write("addLog\0".htmlspecialchars("Overwrite $overwrite Start $start Edit $edit Check Freespace $free"));
|
||||
$actiontxt = ucfirst($action) ;
|
||||
write("<p class='logLine'></p>","addLog\0<fieldset class='docker'><legend>"._("Options for $actiontxt").": </legend><p class='logLine'></p></fieldset>");
|
||||
write("addLog\0".htmlspecialchars("Cloning $name to $clone"));
|
||||
|
||||
switch ($action) {
|
||||
case "clone":
|
||||
vm_clone($name,$clone,$overwrite,$start,$edit,$free,$waitID) ;
|
||||
break ;
|
||||
$rtn = vm_clone($name,$clone,$overwrite,$start,$edit,$free,$waitID) ;
|
||||
break ;
|
||||
}
|
||||
#execCommand_nchan("ls /") ;
|
||||
write("stop_Wait\0$waitID") ;
|
||||
write('_DONE_','');
|
||||
|
||||
if ($rtn) write('_DONE_',''); else write('_ERROR_','');
|
||||
?>
|
||||
@@ -181,6 +181,7 @@ div.last{padding-bottom:12px}
|
||||
div.leftside{float:left;width:66%}
|
||||
div.rightside{float:right;margin:0;text-align:center}
|
||||
div[id$=chart]{margin:-12px 8px -24px -18px}
|
||||
div.template,div#dialogWindow,input#upload{display:none}
|
||||
span.green,span.red,span.orange{padding-left:0}
|
||||
span.ctrl{float:right;margin-top:0;margin-right:10px}
|
||||
span.ctrl span{font-size:2rem!important}
|
||||
@@ -1504,4 +1505,47 @@ $(function() {
|
||||
$.post('/webGui/include/InitCharts.php',{cmd:'set',data:JSON.stringify(data)});
|
||||
});
|
||||
});
|
||||
function dialogStyle() {
|
||||
$('.ui-dialog-titlebar-close').css({'background':'transparent','border':'none','font-size':'1.8rem','margin-top':'-14px','margin-right':'-18px'}).html('<i class="fa fa-times"></i>').prop('title');
|
||||
$('.ui-dialog-title').css({'text-align':'center','width':'100%','font-size':'1.8rem'});
|
||||
$('.ui-dialog-content').css({'padding-top':'15px','vertical-align':'bottom'});
|
||||
$('.ui-button-text').css({'padding':'0px 5px'});
|
||||
}
|
||||
</script>
|
||||
|
||||
<div id="dialogWindow"></div>
|
||||
<div markdown="1" id="templateClone" class="template">
|
||||
<html <?=$display['rtl']?>lang="<?=strtok($locale,'_')?:'en'?>">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="format-detection" content="telephone=no">
|
||||
<meta name="viewport" content="width=1600">
|
||||
<meta name="robots" content="noindex, nofollow">
|
||||
<meta name="referrer" content="same-origin">
|
||||
<link type="text/css" rel="stylesheet" href="<?autov("/webGui/styles/default-fonts.css")?>">
|
||||
</head>
|
||||
<body>
|
||||
<br>
|
||||
<table>
|
||||
<tr><td>_(VM Being Cloned)_:</td>
|
||||
<td><span id="VMBeingCloned"></span></td></tr>
|
||||
|
||||
<tr><td>_(New VM)_:</td>
|
||||
<td><input type="text" id="target" autocomplete="off" spellcheck="false" value="" onclick="this.select()"></td></tr>
|
||||
|
||||
<tr><td>_(Overwrite)_:</td>
|
||||
<td><input type="checkbox" id="Overwrite" value="" ></td></tr>
|
||||
|
||||
<tr hidden><td>_(Start Cloned VM)_:</td>
|
||||
<td><input type="checkbox" id="Start" value="" ></td></tr>
|
||||
|
||||
<tr hidden><td>_(Edit VM after clone)_:</td>
|
||||
<td><input type="checkbox" id="Edit" value="" ></td></tr>
|
||||
|
||||
<tr><td>_(Check Free Space)_:</td>
|
||||
<td><input type="checkbox" id="Free" value="" ></td></tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
</div>
|
||||
@@ -410,6 +410,14 @@ function openDone(data) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function openError(data) {
|
||||
if (data == '_ERROR_') {
|
||||
$('div.spinner.fixed').hide();
|
||||
$('button.confirm').text("<?=_('Error')?>").prop('disabled',false).show();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function showStatus(name,plugin,job) {
|
||||
$.post('/webGui/include/ProcessStatus.php',{name:name,plugin:plugin,job:job},function(status){$(".tabs").append(status);});
|
||||
}
|
||||
@@ -940,7 +948,7 @@ nchan_docker.on('message', function(data) {
|
||||
});
|
||||
var nchan_vmaction = new NchanSubscriber('/sub/vmaction',{subscriber:'websocket'});
|
||||
nchan_vmaction.on('message', function(data) {
|
||||
if (!data || openDone(data)) return;
|
||||
if (!data || openDone(data) || openError(data)) return;
|
||||
var box = $('pre#swaltext');
|
||||
data = data.split('\0');
|
||||
switch (data[0]) {
|
||||
|
||||
Reference in New Issue
Block a user