本文整理汇总了Java中com.cloud.storage.Storage.ImageFormat.QCOW2属性的典型用法代码示例。如果您正苦于以下问题:Java ImageFormat.QCOW2属性的具体用法?Java ImageFormat.QCOW2怎么用?Java ImageFormat.QCOW2使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.cloud.storage.Storage.ImageFormat
的用法示例。
在下文中一共展示了ImageFormat.QCOW2属性的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTemplateFormat
private ImageFormat getTemplateFormat(final String filePath) {
String ext = null;
final int extensionPos = filePath.lastIndexOf('.');
final int lastSeparator = Math.max(filePath.lastIndexOf('/'), filePath.lastIndexOf('\\'));
final int i = lastSeparator > extensionPos ? -1 : extensionPos;
if (i > 0) {
ext = filePath.substring(i + 1);
}
if (ext != null) {
if (ext.equalsIgnoreCase("vhd")) {
return ImageFormat.VHD;
} else if (ext.equalsIgnoreCase("qcow2")) {
return ImageFormat.QCOW2;
} else if (ext.equalsIgnoreCase("tar")) {
return ImageFormat.TAR;
} else if (ext.equalsIgnoreCase("img") || ext.equalsIgnoreCase("raw")) {
return ImageFormat.RAW;
} else if (ext.equalsIgnoreCase("vdi")) {
return ImageFormat.VDI;
}
}
return null;
}
示例2: getSupportedImageFormat
/**
* This method really needs to be part of the properties of the hypervisor type itself.
*
* @param hyperType
* @return
*/
public static ImageFormat getSupportedImageFormat(final HypervisorType hyperType) {
if (hyperType == HypervisorType.XenServer) {
return ImageFormat.VHD;
} else if (hyperType == HypervisorType.KVM) {
return ImageFormat.QCOW2;
} else {
return null;
}
}
示例3: getSupportedImageFormatForCluster
private ImageFormat getSupportedImageFormatForCluster(final HypervisorType hyperType) {
if (hyperType == HypervisorType.XenServer) {
return ImageFormat.VHD;
} else if (hyperType == HypervisorType.KVM) {
return ImageFormat.QCOW2;
} else {
return null;
}
}
示例4: getImageFormat
@Override
public ImageFormat getImageFormat(final Long volumeId) {
final HypervisorType type = getHypervisorType(volumeId);
if (type.equals(HypervisorType.KVM)) {
return ImageFormat.QCOW2;
} else if (type.equals(HypervisorType.XenServer)) {
return ImageFormat.VHD;
} else {
s_logger.warn("Do not support hypervisor " + type.toString());
return null;
}
}
示例5: process
@Override
public FormatInfo process(final String templatePath, final ImageFormat format, final String templateName) throws InternalErrorException {
if (format != null) {
s_logger.debug("We currently don't handle conversion from " + format + " to QCOW2.");
return null;
}
final String qcow2Path = templatePath + File.separator + templateName + "." + ImageFormat.QCOW2.getFileExtension();
if (!_storage.exists(qcow2Path)) {
s_logger.debug("Unable to find the qcow2 file: " + qcow2Path);
return null;
}
final FormatInfo info = new FormatInfo();
info.format = ImageFormat.QCOW2;
info.filename = templateName + "." + ImageFormat.QCOW2.getFileExtension();
final File qcow2File = _storage.getFile(qcow2Path);
info.size = _storage.getSize(qcow2Path);
try {
info.virtualSize = getTemplateVirtualSize(qcow2File);
} catch (final IOException e) {
s_logger.error("Unable to get virtual size from " + qcow2File.getName());
throw new InternalErrorException("unable to get virtual size from qcow2 file");
}
return info;
}
示例6: getVirtualSize
protected long getVirtualSize(final File file, final ImageFormat format) {
Processor processor = null;
try {
if (format == null) {
return file.length();
} else if (format == ImageFormat.QCOW2) {
processor = new QCOW2Processor();
} else if (format == ImageFormat.VHD) {
processor = new VhdProcessor();
} else if (format == ImageFormat.RAW) {
processor = new RawImageProcessor();
}
if (format == ImageFormat.TAR) {
processor = new TARProcessor();
}
if (processor == null) {
return file.length();
}
final Map<String, Object> params = new HashMap<>();
params.put(StorageLayer.InstanceConfigKey, _storage);
processor.configure("template processor", params);
return processor.getVirtualSize(file);
} catch (final Exception e) {
s_logger.warn("Failed to get virtual size of file " + file.getPath() + ", returning file size instead: ", e);
return file.length();
}
}
示例7: getHypervisorTypeFromFormat
@Override
public HypervisorType getHypervisorTypeFromFormat(final ImageFormat format) {
if (format == null) {
return HypervisorType.None;
}
if (format == ImageFormat.VHD) {
return HypervisorType.XenServer;
} else if (format == ImageFormat.QCOW2) {
return HypervisorType.KVM;
} else {
return HypervisorType.None;
}
}
示例8: testPrimaryStorageDownloadCommandNOTemplateDisk
@Test(expected = NullPointerException.class)
public void testPrimaryStorageDownloadCommandNOTemplateDisk() {
final StoragePool pool = Mockito.mock(StoragePool.class);
final List<KvmPhysicalDisk> disks = new ArrayList<>();
final String name = "Test";
final String url = "http://template/";
final ImageFormat format = ImageFormat.QCOW2;
final long accountId = 1l;
final int wait = 0;
final PrimaryStorageDownloadCommand command = new PrimaryStorageDownloadCommand(name, url, format, accountId, pool,
wait);
final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
final KvmStoragePool primaryPool = Mockito.mock(KvmStoragePool.class);
final KvmStoragePool secondaryPool = Mockito.mock(KvmStoragePool.class);
final KvmPhysicalDisk tmplVol = Mockito.mock(KvmPhysicalDisk.class);
final KvmPhysicalDisk primaryVol = Mockito.mock(KvmPhysicalDisk.class);
final KvmPhysicalDisk disk = new KvmPhysicalDisk("/path", "disk.qcow2", primaryPool);
disks.add(disk);
final int index = url.lastIndexOf("/");
final String mountpoint = url.substring(0, index);
when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(storagePoolMgr.getStoragePoolByUri(mountpoint)).thenReturn(secondaryPool);
when(secondaryPool.listPhysicalDisks()).thenReturn(disks);
when(storagePoolMgr.getStoragePool(command.getPool().getType(), command.getPoolUuid())).thenReturn(primaryPool);
when(storagePoolMgr.copyPhysicalDisk(tmplVol, UUID.randomUUID().toString(), primaryPool, 0)).thenReturn(primaryVol);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, libvirtComputingResource);
assertFalse(answer.getResult());
verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
}
示例9: testPrimaryStorageDownloadCommandNOTemplateNODisk
@Test
public void testPrimaryStorageDownloadCommandNOTemplateNODisk() {
final StoragePool pool = Mockito.mock(StoragePool.class);
final List<KvmPhysicalDisk> disks = new ArrayList<>();
final String name = "Test";
final String url = "http://template/";
final ImageFormat format = ImageFormat.QCOW2;
final long accountId = 1l;
final int wait = 0;
final PrimaryStorageDownloadCommand command = new PrimaryStorageDownloadCommand(name, url, format, accountId, pool,
wait);
final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
final KvmStoragePool primaryPool = Mockito.mock(KvmStoragePool.class);
final KvmStoragePool secondaryPool = Mockito.mock(KvmStoragePool.class);
final KvmPhysicalDisk tmplVol = Mockito.mock(KvmPhysicalDisk.class);
final KvmPhysicalDisk primaryVol = Mockito.mock(KvmPhysicalDisk.class);
final int index = url.lastIndexOf("/");
final String mountpoint = url.substring(0, index);
when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(storagePoolMgr.getStoragePoolByUri(mountpoint)).thenReturn(secondaryPool);
when(secondaryPool.listPhysicalDisks()).thenReturn(disks);
when(storagePoolMgr.getStoragePool(command.getPool().getType(), command.getPoolUuid())).thenReturn(primaryPool);
when(storagePoolMgr.copyPhysicalDisk(tmplVol, UUID.randomUUID().toString(), primaryPool, 0)).thenReturn(primaryVol);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, libvirtComputingResource);
assertFalse(answer.getResult());
verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
}
示例10: testPrimaryStorageDownloadCommandNOTemplateNOQcow2
@Test
public void testPrimaryStorageDownloadCommandNOTemplateNOQcow2() {
final StoragePool pool = Mockito.mock(StoragePool.class);
final List<KvmPhysicalDisk> disks = new ArrayList<>();
final List<KvmPhysicalDisk> spiedDisks = Mockito.spy(disks);
final String name = "Test";
final String url = "http://template/";
final ImageFormat format = ImageFormat.QCOW2;
final long accountId = 1l;
final int wait = 0;
final PrimaryStorageDownloadCommand command = new PrimaryStorageDownloadCommand(name, url, format, accountId, pool,
wait);
final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
final KvmStoragePool primaryPool = Mockito.mock(KvmStoragePool.class);
final KvmStoragePool secondaryPool = Mockito.mock(KvmStoragePool.class);
final KvmPhysicalDisk tmplVol = Mockito.mock(KvmPhysicalDisk.class);
final KvmPhysicalDisk primaryVol = Mockito.mock(KvmPhysicalDisk.class);
final int index = url.lastIndexOf("/");
final String mountpoint = url.substring(0, index);
when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(storagePoolMgr.getStoragePoolByUri(mountpoint)).thenReturn(secondaryPool);
when(secondaryPool.listPhysicalDisks()).thenReturn(spiedDisks);
when(spiedDisks.isEmpty()).thenReturn(false);
when(storagePoolMgr.getStoragePool(command.getPool().getType(), command.getPoolUuid())).thenReturn(primaryPool);
when(storagePoolMgr.copyPhysicalDisk(tmplVol, UUID.randomUUID().toString(), primaryPool, 0)).thenReturn(primaryVol);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, libvirtComputingResource);
assertFalse(answer.getResult());
verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
}
示例11: createVolumeFromSnapshot
@Override
public Answer createVolumeFromSnapshot(final CopyCommand cmd) {
try {
final DataTO srcData = cmd.getSrcTO();
final SnapshotObjectTO snapshot = (SnapshotObjectTO) srcData;
final DataTO destData = cmd.getDestTO();
final PrimaryDataStoreTO pool = (PrimaryDataStoreTO) destData.getDataStore();
final DataStoreTO imageStore = srcData.getDataStore();
final VolumeObjectTO volume = snapshot.getVolume();
if (!(imageStore instanceof NfsTO)) {
return new CopyCmdAnswer("unsupported protocol");
}
final NfsTO nfsImageStore = (NfsTO) imageStore;
final String snapshotFullPath = snapshot.getPath();
final int index = snapshotFullPath.lastIndexOf("/");
final String snapshotPath = snapshotFullPath.substring(0, index);
final String snapshotName = snapshotFullPath.substring(index + 1);
final KvmStoragePool secondaryPool = storagePoolMgr.getStoragePoolByUri(
nfsImageStore.getUrl() + File.separator + snapshotPath);
final KvmPhysicalDisk snapshotDisk = secondaryPool.getPhysicalDisk(snapshotName);
if (volume.getFormat() == ImageFormat.RAW) {
snapshotDisk.setFormat(PhysicalDiskFormat.RAW);
} else if (volume.getFormat() == ImageFormat.QCOW2) {
snapshotDisk.setFormat(PhysicalDiskFormat.QCOW2);
}
final String primaryUuid = pool.getUuid();
final KvmStoragePool primaryPool = storagePoolMgr.getStoragePool(pool.getPoolType(), primaryUuid);
final String volUuid = UUID.randomUUID().toString();
final KvmPhysicalDisk disk = storagePoolMgr.copyPhysicalDisk(snapshotDisk, volUuid, primaryPool,
cmd.getWaitInMillSeconds());
final VolumeObjectTO newVol = new VolumeObjectTO();
newVol.setPath(disk.getName());
newVol.setSize(disk.getVirtualSize());
newVol.setFormat(ImageFormat.valueOf(disk.getFormat().toString().toUpperCase()));
return new CopyCmdAnswer(newVol);
} catch (final CloudRuntimeException e) {
logger.debug("Failed to createVolumeFromSnapshot: ", e);
return new CopyCmdAnswer(e.toString());
}
}