\n"; // XML encoding declaration // create new VM if (isset($_POST['createvm'])) { $new = $lv->domain_define($_POST['xmldesc'], $_POST['domain']['startnow']==1); if ($new){ $lv->domain_set_autostart($new, $_POST['domain']['autostart']==1); $reply = ['success' => true]; } else { $reply = ['error' => $lv->get_last_error()]; } echo json_encode($reply); exit; } // update existing VM if (isset($_POST['updatevm'])) { $uuid = $_POST['domain']['uuid']; $dom = $lv->domain_get_domain_by_uuid($uuid); $oldAutoStart = $lv->domain_get_autostart($dom)==1; $newAutoStart = $_POST['domain']['autostart']==1; $strXML = $lv->domain_get_xml($dom); // delete and create the VM $lv->nvram_backup($uuid); $lv->domain_undefine($dom); $lv->nvram_restore($uuid); $new = $lv->domain_define($_POST['xmldesc']); if ($new) { $lv->domain_set_autostart($new, $newAutoStart); $reply = ['success' => true]; } else { // Failure -- try to restore existing VM $reply = ['error' => $lv->get_last_error()]; $old = $lv->domain_define($strXML); if ($old) $lv->domain_set_autostart($old, $oldAutoStart); } echo json_encode($reply); exit; } if (isset($_GET['uuid'])) { // edit an existing VM $uuid = unscript($_GET['uuid']); $dom = $lv->domain_get_domain_by_uuid($uuid); $boolRunning = $lv->domain_get_state($dom)=='running'; $strXML = $lv->domain_get_xml($dom); } else { // edit new VM $uuid = ''; $boolRunning = false; $strXML = ''; } ?>