Пример #1
0
		function domain_delete($domain) {
			$dom = $this->get_domain_object($domain);
			if (!$dom)
				return false;
			$disks = $this->get_disk_stats($dom);
			$tmp = libvirt_domain_undefine($dom);
			if (!$tmp)
				return $this->_set_last_error();

			// remove the first disk only
			if (array_key_exists('file', $disks[0])) {
				$disk = $disks[0]['file'];
				$pathinfo = pathinfo($disk);
				$dir = $pathinfo['dirname'];

				// remove the vm config
				$cfg_vm = $dir.'/'.$domain.'.cfg';
				if (file_exists($cfg_vm));
					unlink($cfg_vm);

				$cfg = $dir.'/'.$pathinfo['filename'].'.cfg';
				$xml = $dir.'/'.$pathinfo['filename'].'.xml';
					if (file_exists($disk));
						unlink($disk);
					if (file_exists($cfg));
						unlink($cfg);
					if (file_exists($xml));
						unlink($xml);
					if (is_dir($dir) && $this->is_dir_empty($dir))
						rmdir($dir);
			}

			return true;
		}
 function domain_undefine($domain)
 {
     $dom = $this->get_domain_object($domain);
     if (!$dom) {
         return false;
     }
     $tmp = libvirt_domain_undefine($dom);
     return $tmp ? $tmp : $this->_set_last_error();
 }
Пример #3
0
/**
 * attach a disk device with associated volume, to a virtual machine on the virt host
 *
 * @global  resource $host_conn        libvirt connection
 *
 * @param   string   $vm_virt_id       virt_id of the vm
 * @param   int      $vm_disk_instance instance of device (used to determine device name)
 * @param   string   $volume_virt_id   virt_id of volume
 *
 * @return  bool                on success
 */
function ace_kvm_vm_attach_disk($vm_virt_id, $vm_disk_instance, $volume_virt_id)
{
    global $host_conn;
    $vm_res = libvirt_domain_lookup_by_name($host_conn, $vm_virt_id);
    ace_kvm_log_last_error();
    $valid_disk_devs = array('', 'vda', 'vdb', 'vdc', 'vdd', 'vde', 'vdf', 'vdg', 'vdh');
    $virt_target_dev = $valid_disk_devs[$vm_disk_instance];
    $domain_xml = ace_kvm_get_vm_config($vm_virt_id);
    $sxe_domain = new SimpleXMLElement($domain_xml);
    $arr_of_sxe_devices_fragments = $sxe_domain->xpath('/domain/devices');
    $sxe_devices = $arr_of_sxe_devices_fragments[0];
    $sxe_disk = $sxe_devices->addChild('disk');
    $sxe_disk->addAttribute('type', 'volume');
    $sxe_disk->addAttribute('device', 'disk');
    $sxe_disk_driver = $sxe_disk->addChild('driver');
    $sxe_disk_driver->addAttribute('name', 'qemu');
    $sxe_disk_driver->addAttribute('type', 'qcow2');
    $sxe_disk_driver->addAttribute('cache', 'none');
    $sxe_disk_source = $sxe_disk->addChild('source');
    $sxe_disk_source->addAttribute('pool', _IMAGE_POOL_);
    $sxe_disk_source->addAttribute('volume', $volume_virt_id);
    $sxe_disk_target = $sxe_disk->addChild('target');
    $sxe_disk_target->addAttribute('dev', $virt_target_dev);
    $sxe_disk_target->addAttribute('bus', 'virtio');
    $xml = $sxe_domain->asXML();
    $success = libvirt_domain_undefine($vm_res);
    ace_kvm_log_last_error();
    $vm_res = libvirt_domain_define_xml($host_conn, $xml);
    ace_kvm_log_last_error();
    return is_resource($vm_res) ? TRUE : FALSE;
}