WIP Update

This commit is contained in:
SimonFair
2023-06-25 20:51:00 +01:00
parent ec04a03ee3
commit 276406c830
3 changed files with 28 additions and 36 deletions
@@ -204,7 +204,7 @@ function getisoimage(uuid,dev,bus,file){
dialogStyle();
}
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',"_(Close)_").prop('onclick',null).off('click').click(function(){box.dialog('close');});
$('.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'});
@@ -1490,8 +1490,6 @@ private static $encoding = 'UTF-8';
if ($state != 'shutdown') $arrResponse = $lv->domain_destroy($vm) ;
# Wait for shutdown?
$disks =$lv->get_disk_stats($vm) ;
$capacity = 0 ;
@@ -1511,55 +1509,52 @@ 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) { $arrResponse = ['error' => _("Insufficent Storage for Clone")]; return $arrResponse ;}
#Clone XML
$res = $lv->domain_get_domain_by_uuid($uuid);
$strXML = $lv->domain_get_xml($res);
$uuid = $lv->domain_get_uuid($vm) ;
var_dump($uuid) ;
$config=domain_to_config($uuid) ;
#$config = array_replace_recursive($arrConfigDefaults, domain_to_config($uuid));
#$config = domain_to_config($uuid);
$config["domain"]["name"] = $clone ;
$config["domain"]["uuid"] = $lv->domain_generate_uuid() ;
$config["nic"]["0"]["mac"] = $lv->generate_random_mac_addr() ;
foreach($config["nic"] as $index => $detail) {
$config["nic"][$index]["mac"] = $lv->generate_random_mac_addr() ;
}
$config["domain"]["type"] = "kvm";
$files_exist = false ;
foreach ($config["disk"] as $diskid => $disk) {
$config["disk"][$diskid]["new"] = str_replace($name,$clonename,$config["disk"][$diskid]["new"]) ;
#var_dump(pathinfo($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 ;
#var_dump($isdir,$pi['dirname']) ;
}
$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") { $arrResponse = ['error' => _("New image file names exist and Overwrite is no")]; return $arrResponse ;}
#Create duplicate files.
foreach($config["disk"] as $diskid => $disk) {
$cmdstr = "touch {$config['disk'][$diskid]['new']}" ;
$error = execCommand_nchan($cmdstr,$path) ;
if (!$error) {
$arrResponse = ['error' => substr($output[0],6) ] ;
return($arrResponse) ;
} else {
$arrResponse = ['success' => true] ;
}
}
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("Creating new XML $clone"));
$xml = $lv->config_to_xml($config) ;
file_put_contents("/tmp/xml" ,$xml) ;
foreach($disks as $disk) {
$cmdstr = "ls" ;
$error = execCommand_nchan($cmdstr,$path) ;
if (!$error) {
$arrResponse = ['error' => substr($output[0],6) ] ;
return($arrResponse) ;
} else {
$arrResponse = ['success' => true] ;
}
}
$arrResponse = ['error' => _("Insufficent Storage for Clone")];
return$arrResponse ;
@@ -275,19 +275,16 @@ function VMClone(uuid, name){
//var root = <?= '"'.$domain_cfg["MEDIADIR"].'"';?>;
var match= ".iso";
var box = $("#dialogWindow");
box.html($("#templateblock").html());
var height = 200;
box.html($("#templateClone").html());
box.find('#VMBeingCloned').html(name).change() ;
//document.getElementById("targetsnaprmv").checked = true ;
//document.getElementById("targetsnaprmvmeta").checked = true ;
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)_",
title: "VM Clone",
resizable: false,
width: 600,
height: 500,
@@ -299,7 +296,7 @@ function VMClone(uuid, name){
var target = box.find('#target');
if (target.length) {
target = target.val();
if (!target ) {errorTarget(); return;}
//if (!target ) {errorTarget(); return;}
} else target = '';
var clone = box.find("#target").prop('value') ;
@@ -317,7 +314,7 @@ function VMClone(uuid, name){
openVMAction((scripturl),"VM Clone", "dynamix.vm.manager", "loadlist") ;
box.dialog('close');
},
"_(Cancel)_": function(){
"Cancel": function(){
box.dialog('close');
}
}