domain_get_name_by_uuid($strUUID); $dom = $lv->domain_get_info($res); $strXML = $lv->domain_get_xml($res); $boolRunning = ($lv->domain_state_translate($dom['state']) == 'running'); } if (array_key_exists('createvm', $_POST)) { $tmp = $lv->domain_define($_POST['xmldesc'], !empty($config['domain']['startnow'])); if (!$tmp){ $arrResponse = ['error' => $lv->get_last_error()]; } else { $lv->domain_set_autostart($tmp, $_POST['domain']['autostart'] == 1); $arrResponse = ['success' => true]; } echo json_encode($arrResponse); exit; } if (array_key_exists('updatevm', $_POST)) { // Backup xml for existing domain in ram $strOldXML = ''; $boolOldAutoStart = false; $dom = $lv->domain_get_domain_by_uuid($_POST['domain']['uuid']); if ($dom) { $strOldXML = $lv->domain_get_xml($dom); $boolOldAutoStart = $lv->domain_get_autostart($dom); } // Remove existing domain $lv->nvram_backup($_POST['domain']['uuid']); $lv->domain_undefine($dom); $lv->nvram_restore($_POST['domain']['uuid']); // Save new domain $tmp = $lv->domain_define($_POST['xmldesc']); if (!$tmp){ $strLastError = $lv->get_last_error(); // Failure -- try to restore existing domain $tmp = $lv->domain_define($strOldXML); if ($tmp) $lv->domain_set_autostart($tmp, $boolOldAutoStart); $arrResponse = ['error' => $strLastError]; } else { $lv->domain_set_autostart($tmp, $_POST['domain']['autostart'] == 1); $arrResponse = ['success' => true]; } echo json_encode($arrResponse); exit; } ?>
Manual XML edits may be lost if you later edit with the GUI editor.