本文整理汇总了Java中com.cloud.storage.Storage.ImageFormat.VHD属性的典型用法代码示例。如果您正苦于以下问题:Java ImageFormat.VHD属性的具体用法?Java ImageFormat.VHD怎么用?Java ImageFormat.VHD使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.cloud.storage.Storage.ImageFormat
的用法示例。
在下文中一共展示了ImageFormat.VHD属性的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: testPrimaryStorageDownloadCommand
@Test
public void testPrimaryStorageDownloadCommand() {
final XsHost xsHost = Mockito.mock(XsHost.class);
final StoragePoolVO poolVO = Mockito.mock(StoragePoolVO.class);
final PrimaryStorageDownloadCommand storageDownloadCommand = new PrimaryStorageDownloadCommand("Test", "http://127.0.0.1", ImageFormat.VHD, 1l, poolVO, 200);
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
when(citrixResourceBase.getHost()).thenReturn(xsHost);
final Answer answer = wrapper.execute(storageDownloadCommand, citrixResourceBase);
verify(citrixResourceBase, times(1)).getConnection();
assertFalse(answer.getResult());
}
示例3: 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;
}
}
示例4: 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;
}
}
示例5: validate
private void validate(final SnapshotInfo snapshotInfo) {
final long volumeId = snapshotInfo.getVolumeId();
final VolumeVO volumeVO = _volumeDao.findByIdIncludingRemoved(volumeId);
if (volumeVO.getFormat() != ImageFormat.VHD) {
throw new CloudRuntimeException("Only the " + ImageFormat.VHD.toString() + " image type is currently supported.");
}
}
示例6: 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;
}
}
示例7: 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 VHD.");
return null;
}
final String vhdPath = templatePath + File.separator + templateName + "." + ImageFormat.VHD.getFileExtension();
if (!_storage.exists(vhdPath)) {
s_logger.debug("Unable to find the vhd file: " + vhdPath);
return null;
}
final File vhdFile = _storage.getFile(vhdPath);
final FormatInfo info = new FormatInfo();
info.format = ImageFormat.VHD;
info.filename = templateName + "." + ImageFormat.VHD.getFileExtension();
info.size = _storage.getSize(vhdPath);
try {
info.virtualSize = getTemplateVirtualSize(vhdFile);
} catch (final IOException e) {
s_logger.error("Unable to get the virtual size for " + vhdPath);
throw new InternalErrorException("unable to get virtual size from vhd file");
}
return info;
}
示例8: 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();
}
}
示例9: 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;
}
}
示例10: testPrimaryStorageDownloadCommandTemplateNoDisk
@Test(expected = NullPointerException.class)
public void testPrimaryStorageDownloadCommandTemplateNoDisk() {
final StoragePool pool = Mockito.mock(StoragePool.class);
final String name = "Test";
final String url = "http://template/template.qcow2";
final ImageFormat format = ImageFormat.VHD;
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.getPhysicalDisk("template.qcow2")).thenReturn(tmplVol);
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);
assertTrue(answer.getResult());
verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
verify(storagePoolMgr, times(1)).getStoragePool(command.getPool().getType(), command.getPoolUuid());
}
示例11: takeSnapshot
@Override
@DB
public SnapshotInfo takeSnapshot(final SnapshotInfo snapshotInfo) {
final VolumeInfo volumeInfo = snapshotInfo.getBaseVolume();
if (volumeInfo.getFormat() != ImageFormat.VHD) {
throw new CloudRuntimeException("Only the " + ImageFormat.VHD.toString() + " image type is currently supported.");
}
final SnapshotVO snapshotVO = _snapshotDao.acquireInLockTable(snapshotInfo.getId());
if (snapshotVO == null) {
throw new CloudRuntimeException("Failed to acquire lock on the following snapshot: " + snapshotInfo.getId());
}
SnapshotResult result = null;
try {
volumeInfo.stateTransit(Volume.Event.SnapshotRequested);
// tell the storage driver to create a back-end volume (eventually used to create a new SR on and to copy the VM snapshot VDI to)
result = snapshotSvr.takeSnapshot(snapshotInfo);
if (result.isFailed()) {
s_logger.debug("Failed to take a snapshot: " + result.getResult());
throw new CloudRuntimeException(result.getResult());
}
// send a command to XenServer to create a VM snapshot on the applicable SR (get back the VDI UUID of the VM snapshot)
performSnapshotAndCopyOnHostSide(volumeInfo, snapshotInfo);
markAsBackedUp((SnapshotObject) result.getSnashot());
} finally {
if (result != null && result.isSuccess()) {
volumeInfo.stateTransit(Volume.Event.OperationSucceeded);
} else {
volumeInfo.stateTransit(Volume.Event.OperationFailed);
}
_snapshotDao.releaseFromLockTable(snapshotInfo.getId());
}
return snapshotInfo;
}