Ejemplo n.º 1
0
		function volume_create($name, $capacity, $allocation, $format) {
			$capacity = $this->parse_size($capacity);
			$allocation = $this->parse_size($allocation);
			($format != 'raw' ) ? $ext = $format : $ext = 'img';
			($ext == pathinfo($name, PATHINFO_EXTENSION)) ? $ext = '': $name .= '.';

			$xml = "<volume>\n".
					"   <name>$name$ext</name>\n".
					"   <capacity>$capacity</capacity>\n".
					"   <allocation>$allocation</allocation>\n".
					"   <target>\n".
					"      <format type='$format'/>\n".
					"   </target>\n".
					"</volume>";

			$tmp = libvirt_storagevolume_create_xml($pool, $xml);
			return ($tmp) ? $tmp : $this->_set_last_error();
		}
 function storagevolume_create($pool, $name, $capacity, $allocation)
 {
     $pool = $this->get_storagepool_res($pool);
     $capacity = $this->parse_size($capacity);
     $allocation = $this->parse_size($allocation);
     $xml = "<volume>\n" . "  <name>{$name}</name>\n" . "  <capacity>{$capacity}</capacity>\n" . "  <allocation>{$allocation}</allocation>\n" . "</volume>";
     $tmp = libvirt_storagevolume_create_xml($pool, $xml);
     return $tmp ? $tmp : $this->_set_last_error();
 }
Ejemplo n.º 3
0
/**
 * create a volume in _IMAGE_POOL_ on the virt host
 *
 * @global  resource $host_conn           libvirt connection
 *
 * @param   string   $volume_virt_id      virt_id to be used for the volume
 * @param   int      $size                size of volume measured in units
 * @param   string   $unit                "MB" | "GB"
 * @param   string   $volume_base_virt_id virt_id of base volume
 *
 * @return  bool                TRUE on success | FALSE on error
 */
function ace_kvm_volume_create($volume_virt_id, $size, $unit, $volume_base_virt_id)
{
    global $host_conn;
    if ($volume_base_virt_id) {
        $xml = '
<volume>
	<name></name>
	<allocation>0</allocation>
	<capacity unit=""></capacity>
	<target>
		<format type="qcow2"/>
		<permissions>
			<mode>0744</mode>
		</permissions>
	</target>
	<backingStore>
		<path></path>
		<format type="qcow2"/>
		<permissions>
			<mode>0744</mode>
			<label>virt_image_t</label>
		</permissions>
	</backingStore>
</volume>';
    } else {
        $xml = '
<volume>
	<name></name>
	<allocation>0</allocation>
	<capacity unit=""></capacity>
	<target>
		<format type="qcow2"/>
		<permissions>
			<mode>0744</mode>
		</permissions>
	</target>
</volume>';
    }
    $volumeXML = new SimpleXMLElement($xml);
    $volumeXML->name = $volume_virt_id;
    $volumeXML->capacity['unit'] = $unit;
    $volumeXML->capacity = $size;
    if ($volume_base_virt_id) {
        $volumeXML->backingStore->path = '/storage/vol02/images/' . $volume_base_virt_id;
    }
    $xml = $volumeXML->asXML();
    $volume_pool_res = libvirt_storagepool_lookup_by_name($host_conn, _IMAGE_POOL_);
    ace_kvm_log_last_error();
    $return = $volume_res = libvirt_storagevolume_create_xml($volume_pool_res, $xml) ? TRUE : FALSE;
    ace_kvm_log_last_error();
    return $return;
}