/** * Action delete backup */ function _action_backup_delete($id, $backupid) { if (is_null($backupid)) { return array('error' => 'Backup ID not set'); } $vm = get_vm($id); $service = get_service($id); $onapp_config = get_onapp_config($service['serverid']); $backup = new ONAPP_VirtualMachine_Backup(); $backup->_id = $backupid; $user = get_onapp_client($id); $backup->auth($onapp_config["adress"], $user["email"], $user["password"]); $backup->delete(); if (!is_null($backup->error)) { return array('error' => is_array($backup->error) ? "Can't create Backup<br/>\n " . implode('.<br>', $backup->error) : "Can't create Backup'" . $backup->error); } else { return true; } }
function create_vm($service_id, $hostname, $template_id) { $service = get_service($service_id); if ($service['serverid'] != $service['productserverid']) { $service['serverid'] = $service['productserverid']; } $user = get_onapp_client($service_id); $onapp_config = get_onapp_config($service['serverid']); if (isset($user['error'])) { $vm = new OnApp_VirtualMachine(); $vm->setErrors($user['error']); return $vm; } $instance = new OnApp_Factory($onapp_config["adress"], $user["email"], $user["password"]); if (!$instance->_is_auth) { return $instance; } $vm = $instance->factory('VirtualMachine'); $tpl = $instance->factory('Template'); $option = explode(",", $service['configoption4']); if (count($option) > 1) { $vm->_hypervisor_group_id = $option[1]; } else { $vm->_hypervisor_id = $option[0]; } $option = explode(",", $service['configoption11']); if (count($option) > 1) { $vm->_data_store_group_primary_id = $option[1]; } $option = explode(",", $service['configoption9']); if (count($option) > 1) { $vm->_data_store_group_swap_id = $option[1]; } $option10 = explode(",", $service['configoption10']); if (!$option10[1]) { $option10[1] = '0'; } $memory = $service['configoption3'] + $service['additionalram']; $cpus = $service['configoption5'] + $service['additionalcpus']; $cpu_shares = $service['configoption7'] + $service['additionalcpushares']; $primary_disk_size = $service['configoption11'] + $service['additionaldisksize']; $rate_limit = $service['configoption8'] + $service['additionalportspead']; $vm->_template_id = isset($service['os']) ? $service['os'] : $template_id; $vm->_primary_network_id = $service['configoption6']; $vm->_required_virtual_machine_build = $option10[0] == 'on' ? '1' : '0'; $vm->_required_automatic_backup = $option10[1] == 'on' ? '1' : '0'; $vm->_hostname = $hostname; $vm->_memory = $memory; $vm->_cpus = $cpus; $vm->_cpu_shares = $cpu_shares; $vm->_primary_disk_size = round($primary_disk_size); $vm->_swap_disk_size = round($service['configoption9']); $vm->_label = $hostname; $vm->_remote_access_password = decrypt($service['password']); $vm->_initial_root_password = decrypt($service['password']); $vm->_required_ip_address_assignment = '1'; $vm->_rate_limit = $rate_limit; $tpl->load($vm->_template_id); if ($tpl->_obj->_operating_system == 'windows') { $vm->_swap_disk_size = NULL; } $vm->save(); if (!is_null($vm->_obj->error)) { $vm->error = $vm->_obj->error; return $vm; } elseif (is_null($vm->_obj->_id)) { $vm->error = "Can't create virtual machine for service #" . $service_id; return $vm; } else { $sql_replace = "REPLACE tblonappservices SET\n service_id = '{$service_id}',\n vm_id = '" . $vm->_obj->_id . "',\n memory = '{$memory}',\n cpus = '{$cpus}',\n cpu_shares = '{$cpu_shares}',\n disk_size = '{$primary_disk_size}';"; switch ($vm->_obj->_operating_system) { case 'linux': $username = "******"; break; case 'windows': $username = "******"; break; } $sql_username_update = "UPDATE tblhosting SET\n username = '******',\n server = '" . $service['serverid'] . "'\n WHERE\n id = '" . $service['id'] . "';"; if ($username != "") { full_query($sql_username_update); } if (full_query($sql_replace)) { sendmessage('Virtual Machine Created', $service_id); // action_resolveall_ips(); // action_resolve all_backups(); } else { $vm->error = "Can't add virtual machine in DB"; return $vm; } } update_service_ips($service_id); return $vm; }
$user_id = $_SESSION["uid"]; $vm_id = $_GET["id"]; // Check VM access $sql = sprintf("SELECT \n service_id \n FROM \n tblonappservices \n LEFT JOIN tblhosting ON tblhosting.id = service_id \n WHERE \n userid = '%s' \n AND vm_id = '%s';", stripcslashes($user_id), stripcslashes($vm_id)); $sql_result = getSQLResult($sql); if (!isset($sql_result["service_id"])) { die("Access denied to this Console"); } else { $service_id = $sql_result["service_id"]; } unset($sql); unset($sql_result); // Load VM server id $service = get_service($service_id); $onapp_config = get_onapp_config($service['serverid']); $user = get_onapp_client($service_id); if (!$onapp_config) { die("Can't found active OnApp server #" . addslashes($server_id) . " in Data Base"); } // Load VM $vm = new OnApp_VirtualMachine(); $vm->auth($onapp_config["adress"], $user["email"], $user["password"]); $vm->_id = $vm_id; $vm->load(); // Load console $console = new ONAPP_Console(); $console->auth($onapp_config["adress"], $user["email"], $user["password"]); $console->load($vm_id); $url = ($onapp_config["hostname"] ? $onapp_config["hostname"] : $onapp_config["adress"]) . "/console_remote/" . $console->_obj->_remote_key; if (strpos($url, 'http') === false && strpos($url, 'http') === false) { $url = 'http://' . $url;