Example #1
0
 public function work()
 {
     $t = new Timer('libvirt extension');
     if (!extension_loaded('libvirt')) {
         Errors::add('libvirt extension', 'Libvirt PHP extension not installed');
         $this->res = false;
         return;
     }
     if (!$this->connect()) {
         Errors::add('libvirt extension', 'Failed connecting');
         return;
     }
     if (!($doms = libvirt_list_domains($this->connection))) {
         Errors::add('libvirt extension', 'Failed getting domain list');
         $this->res = false;
         return;
     }
     foreach ($doms as $name) {
         if (!($domain = libvirt_domain_lookup_by_name($this->connection, $name))) {
             continue;
         }
         if (!($info = libvirt_domain_get_info($domain)) || !is_array($info)) {
             continue;
         }
         $info['autostart'] = libvirt_domain_get_autostart($domain);
         if ($info['autostart'] == 1) {
             $info['autostart'] = 'Yes';
         } elseif ($info['autostart'] == 0) {
             $info['autostart'] = 'No';
         } else {
             $info['autostart'] = 'N/A';
         }
         $info['nets'] = array();
         $nets = @libvirt_domain_get_interface_devices($domain);
         foreach ($nets as $key => $net) {
             if (!is_numeric($key)) {
                 continue;
             }
             $info['nets'][] = $net;
         }
         $info['storage'] = array();
         foreach ((array) @libvirt_domain_get_disk_devices($domain) as $blockName) {
             if (!is_string($blockName)) {
                 continue;
             }
             // Sometime device exists but libvirt fails to get more docs. just settle for device name
             if (!($blockInfo = @libvirt_domain_get_block_info($domain, $blockName)) || !is_array($blockInfo)) {
                 $info['storage'][] = array('device' => $blockName);
                 continue;
             }
             if (isset($blockInfo['partition']) && !isset($blockInfo['file'])) {
                 $blockInfo['file'] = $blockInfo['partition'];
             }
             $info['storage'][] = $blockInfo;
         }
         $this->VMs[$name] = $info;
     }
     $this->res = true;
 }
Example #2
0
		function domain_get_autostart($domain) {
			$domain = $this->get_domain_object($domain);
			$tmp = libvirt_domain_get_autostart($domain);
			return ($tmp) ? $tmp : $this->_set_last_error();
		}