private function singlevm($host, $vm) { global $config; $hostobj = $this->database->gethost($host); $this->title = sprintf(_('Virtual machine %s'), $vm); if (!isset($_SESSION['hosts'][$host]['vm'][$vm])) { return $this->vmlist(); } $ipaddresses = array(); if (isset($_SESSION['hosts'][$host]['vm'][$vm]['guest']->net) && isset($_SESSION['hosts'][$host]['vm'][$vm]['guest']->net->ipConfig)) { foreach ($_SESSION['hosts'][$host]['vm'][$vm]['guest']->net->ipConfig as $ipconfig) { if (isset($ipconfig->ipAddress)) { $ipaddresses[] = $ipconfig->ipAddress; } } } if (isset($guest->ipAddress)) { $ipaddresses[] = $guest->ipAddress; } $tpl = new Template('page_vms_singlevm.html'); /* Summary */ $tpl->setVars(array('label_summary' => _('Summary'), 'label_guestos' => _('Guest OS'), 'guestos' => $_SESSION['hosts'][$host]['vm'][$vm]['config']->guestFullName, 'label_vmversion' => _('VM version'), 'vmversion' => $_SESSION['hosts'][$host]['vm'][$vm]['config']->version, 'label_cpu' => _('CPU'), 'cpu' => sprintf(_('%d vCPU'), $_SESSION['hosts'][$host]['vm'][$vm]['config']->hardware->numCPU), 'label_memory' => _('Memory'), 'memory' => readable_bytes($_SESSION['hosts'][$host]['vm'][$vm]['config']->hardware->memoryMB . 'MB'), 'label_tools' => _('VMware tools'), 'tools' => VirtualMachineToolsRunningStatus($_SESSION['hosts'][$host]['vm'][$vm]['guest']->toolsRunningStatus), 'label_ipaddresses' => _('IP addresses'), 'ipaddresses' => implode(', ', $ipaddresses), 'label_dnsname' => _('DNS name'), 'dnsname' => isset($_SESSION['hosts'][$host]['vm'][$vm]['guest']->hostName) ? $_SESSION['hosts'][$host]['vm'][$vm]['guest']->hostName : '', 'label_state' => _('State'), 'state' => VirtualMachinePowerState($_SESSION['hosts'][$host]['vm'][$vm]['runtime']->powerState), 'label_host' => _('Host'), 'host' => $host, 'label_vm' => sprintf(_('Virtual Machine %s'), $vm), 'name' => $vm)); /* Actions */ $tpl->setVar('label_actions', _('Actions')); if ($_SESSION['hosts'][$host]['vm'][$vm]['runtime']->powerState == 'poweredOn') { $tpl->setVar('label_poweroff', _('Power off')); $tpl->parse('poweroff'); $tpl->setVar('label_suspend', _('Suspend')); $tpl->parse('suspend'); $tpl->setVar('label_reset', _('Reset')); $tpl->parse('reset'); if ($_SESSION['hosts'][$host]['vm'][$vm]['guest']->toolsRunningStatus == 'guestToolsRunning') { $tpl->setVar('label_shutdown', _('Shutdown guest')); $tpl->parse('shutdown'); } else { $tpl->hideBlock('shutdown'); } if ($GLOBALS['config']['console'] && $hostobj['console'] && preg_match('/(Linux|Windows)/', $_SERVER['HTTP_USER_AGENT']) && preg_match('/(Chrome|Firefox|MSIE)/', $_SERVER['HTTP_USER_AGENT'])) { if (preg_match('/Windows/', $_SERVER['HTTP_USER_AGENT'])) { $tpl->setVar('downloadlink', '?download=windows'); } else { if (preg_match('/x86_64/', $_SERVER['HTTP_USER_AGENT'])) { $tpl->setVar('downloadlink', '?download=linux64'); } else { $tpl->setVar('downloadlink', '?download=linux32'); } } $tpl->setVar('label_openconsole', _('Open console')); $tpl->setVar('label_plugindownload', _('Download console plugin')); $tpl->parse('openconsole'); $this->commands[] = '$(\'span#consolebutton\').css(\'display\', has_plugin() ? \'block\' : \'none\');'; $this->commands[] = '$(\'span#plugindownload\').css(\'display\', has_plugin() ? \'none\' : \'block\');'; } else { $tpl->hideBlock('openconsole'); } $tpl->hideBlock('poweron'); } else { $tpl->setVar('label_poweron', _('Power on')); $tpl->parse('poweron'); $tpl->hideBlock('poweroff'); $tpl->hideBlock('suspend'); $tpl->hideBlock('reset'); $tpl->hideBlock('shutdown'); $tpl->hideBlock('openconsole'); } $tpl->setVar('label_editsettings', _('Edit settings')); $tpl->parse('editsettings'); $tpl->setVar('label_deletevm', _('Delete virtual machine')); /* Resources */ $tpl->setVar('label_resources', _('Resources')); /* Performance */ $tpl->setVar('label_performance', _('Performance')); /* Tabs */ $tpl->setVar('tabcontent_gettingstarted', 'Getting started!!'); $tpl->setVar('tabcontent_summary', 'Summary!'); $tpl->setVar('tabcontent_performance', 'Performance!'); $this->html['content'] = $tpl->get(); }
private function hostlist($hosts) { $tpl = new Template('page_hosts_hostlist.html'); foreach ($hosts as $host) { $tpl->setVar('hostname', $host['hostname']); if ($_SESSION['hosts'][$host['hostname']]['connected']) { $nics = 0; foreach ($_SESSION['hosts'][$host['hostname']]['hardware']->pciDevice as $device) { if ($device->classId == 512) { $nics++; } } $tpl->setVars(array('software' => $_SESSION['hosts'][$host['hostname']]['about']->name . ' ' . $_SESSION['hosts'][$host['hostname']]['about']->version, 'memory' => readable_bytes($_SESSION['hosts'][$host['hostname']]['hardware']->memorySize), 'cpucount' => $_SESSION['hosts'][$host['hostname']]['hardware']->cpuInfo->numCpuPackages, 'niccount' => $nics, 'uptime' => time_passed(strtotime($_SESSION['hosts'][$host['hostname']]['runtime']->bootTime)))); $tpl->parse('hostrow'); } else { $tpl->setVar('software', _('Not connected...')); $tpl->parse('hostrow'); } } $tpl->setVars(array('label_hosts' => _('Hosts'), 'label_hostname' => _('Hostname'), 'label_software' => _('Software'), 'label_memory' => _('Memory'), 'label_cpucount' => _('CPU count'), 'label_niccount' => _('NIC count'), 'label_uptime' => _('Uptime'), 'label_addhost' => _('Add host'))); $this->html['content'] = $tpl->get(); }
function readable_bits($bits, $base = 1024) { return preg_replace('/B$/', 'b', readable_bytes($bits, $base)); }