/** * Get vitual machine data * * return object ONAPP_VirtualMachine */ function get_vm($service_id) { $user = get_onapp_client($service_id); $vm = new ONAPP_VirtualMachine(); if (isset($user['error'])) { $vm->setErrors($user['error']); return $vm; } $service = get_service($service_id); $onapp_config = get_onapp_config($service['serverid']); if (isset($service["vmid"]) && !is_null($service["vmid"])) { $vm->auth($onapp_config["adress"], $user["email"], $user["password"]); $vms = $vm->getList(); $vm_ids = array(); if ($vms) { foreach ($vms as $vm_fromlist) { array_push($vm_ids, $vm_fromlist->_id); } } if (in_array($service["vmid"], $vm_ids)) { $vm->_id = $service["vmid"]; $vm->load(); } } else { $vm->error = "Cant load Virtual machine"; } return $vm; }
function storagedisksizes() { global $user_id; $select_services = "SELECT\n tblhosting.id as id,\n\n tblonappclients.onapp_user_id,\n tblonappclients.email,\n tblonappclients.password,\n\n tblproducts.name as product,\n LOWER(domainstatus) as domainstatus,\n tblproducts.configoption1 as serverid,\n tblproducts.configoption2 basespace,\n tblproducts.configoption3,\n\n CASE optiontype\n WHEN 1 THEN optionssub.sortorder\n WHEN 2 THEN optionssub.sortorder\n WHEN 4 THEN options.qty * optionssub.sortorder\n ELSE 0\n END AS additionalspace,\n\n tblservers.name as servername,\n tblservers.ipaddress as serveripaddres,\n tblservers.hostname as serverhostname,\n tblservers.username as serverusername,\n tblservers.password as serverpassword,\n\n optionssub.id as subid,\n optionssub.optionname,\n options.configid,\n tblproductconfigoptions.optionname as configoptionname,\n tblproductconfigoptions.optiontype,\n tblproductconfigoptions.qtymaximum AS max,\n tblproductconfigoptions.qtyminimum AS min,\n options.qty,\n optionssub.sortorder,\n options.optionid as active\n FROM\n tblhosting\n LEFT JOIN tblproducts ON\n tblproducts.id = packageid\n LEFT JOIN tblonappservices ON\n service_id = tblhosting.id\n LEFT JOIN tblonappclients ON\n tblproducts.configoption1 = tblonappclients.server_id AND\n tblhosting.userid = tblonappclients.client_id\n LEFT JOIN tblhostingconfigoptions AS options ON\n relid = tblhosting.id\n LEFT JOIN tblproductconfigoptionssub AS sub\n ON options.configid = sub.configid\n AND options.configid = tblproducts.configoption3\n AND optionid = sub.id\n LEFT JOIN tblproductconfigoptions\n ON tblproductconfigoptions.id = options.configid\n LEFT JOIN tblproductconfigoptionssub AS optionssub\n ON optionssub.configid = tblproductconfigoptions.id AND\n options.configid = tblproducts.configoption3\n LEFT JOIN tblservers ON tblproducts.configoption1 = tblservers.id\n WHERE\n servertype = 'onappbackupspace'\n AND options.optionid = optionssub.id\n AND userid = '{$user_id}'\n ORDER BY servername, tblhosting.id ASC"; $services_rows = full_query($select_services); while ($service = mysql_fetch_assoc($services_rows)) { $rows[] = $service; } $servers = array(); if (count($rows)) { foreach ($rows as $key => $value) { if (!isset($servers[$value['serverid']])) { $servers[$value['serverid']] = array('services' => array(), 'name' => $rows[$key]['servername'], 'adress' => $rows[$key]["serveripaddres"] != "" ? 'http://' . $rows[$key]["serveripaddres"] : $rows[$key]['serverhostname'], 'username' => $rows[$key]['serverusername'], 'password' => decrypt($rows[$key]['serverpassword']), 'onapp_user_id' => $rows[$key]['onapp_user_id']); } $servers[$value['serverid']]['services'][] = $value; } } foreach ($servers as $key => $server) { $limit = new ONAPP_ResourceLimit(); $limit->auth($server['adress'], $server['username'], $server['password']); $limit->load($server['onapp_user_id']); $servers[$key]['storage_disk_size'] = $limit->_obj->_storage_disk_size ? $limit->_obj->_storage_disk_size : 0; $vms = new ONAPP_VirtualMachine(); $vms->auth($server['adress'], $server['username'], $server['password']); $backups_size = 0; foreach ($vms->getList($server['onapp_user_id']) as $vm) { $backups = new ONAPP_VirtualMachine_Backup(); $backups->_virtual_machine_id = $vm->_id; $backups->auth($server['adress'], $server['username'], $server['password']); foreach ($backups->getList() as $backup) { $backups_size += $backup->_backup_size; } } if ($backups_size > 0) { $backups_size = sprintf("%01.2f", $backups_size / 1024 / 1024); } $servers[$value['serverid']]['backups_size'] = $backups_size; } show_template("onapp/clientareastoragedisksizes", array('rows' => $servers)); }