Example #1
0
		function domain_define($xml) {
			if (strpos($xml,'<qemu:commandline>')) {
				$tmp = explode("\n", $xml);
				for ($i = 0; $i < sizeof($tmp); $i++)
					if (strpos('.'.$tmp[$i], "<domain type='kvm'"))
						$tmp[$i] = "<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>";
				$xml = join("\n", $tmp);
			}
			$tmp = libvirt_domain_define_xml($this->conn, $xml);
			return ($tmp) ? $tmp : $this->_set_last_error();
		}
 function domain_define($xml)
 {
     $tmp = libvirt_domain_define_xml($this->conn, $xml);
     return $tmp ? $tmp : $this->_set_last_error();
 }
Example #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;
}