use of org.apache.cloudstack.storage.to.VolumeObjectTO in project cloudstack by apache.
the class HypervisorHelperImpl method quiesceVm.
@Override
public VMSnapshotTO quiesceVm(VirtualMachine virtualMachine) {
String value = configurationDao.getValue("vmsnapshot.create.wait");
int wait = NumbersUtil.parseInt(value, 1800);
Long hostId = vmSnapshotHelper.pickRunningHost(virtualMachine.getId());
VMSnapshotTO vmSnapshotTO = new VMSnapshotTO(1L, UUID.randomUUID().toString(), VMSnapshot.Type.Disk, null, null, false, null, true);
GuestOSVO guestOS = guestOSDao.findById(virtualMachine.getGuestOSId());
List<VolumeObjectTO> volumeTOs = vmSnapshotHelper.getVolumeTOList(virtualMachine.getId());
CreateVMSnapshotCommand ccmd = new CreateVMSnapshotCommand(virtualMachine.getInstanceName(), virtualMachine.getUuid(), vmSnapshotTO, volumeTOs, guestOS.getDisplayName());
HostVO host = hostDao.findById(hostId);
GuestOSHypervisorVO guestOsMapping = guestOsHypervisorDao.findByOsIdAndHypervisor(guestOS.getId(), host.getHypervisorType().toString(), host.getHypervisorVersion());
ccmd.setPlatformEmulator(guestOsMapping.getGuestOsName());
ccmd.setWait(wait);
try {
Answer answer = agentMgr.send(hostId, ccmd);
if (answer != null && answer.getResult()) {
CreateVMSnapshotAnswer snapshotAnswer = (CreateVMSnapshotAnswer) answer;
vmSnapshotTO.setVolumes(snapshotAnswer.getVolumeTOs());
} else {
String errMsg = (answer != null) ? answer.getDetails() : null;
throw new CloudRuntimeException("Failed to quiesce vm, due to " + errMsg);
}
} catch (AgentUnavailableException e) {
throw new CloudRuntimeException("Failed to quiesce vm", e);
} catch (OperationTimedoutException e) {
throw new CloudRuntimeException("Failed to quiesce vm", e);
}
return vmSnapshotTO;
}
use of org.apache.cloudstack.storage.to.VolumeObjectTO in project cloudstack by apache.
the class HypervisorHelperImpl method unquiesceVM.
@Override
public boolean unquiesceVM(VirtualMachine virtualMachine, VMSnapshotTO vmSnapshotTO) {
Long hostId = vmSnapshotHelper.pickRunningHost(virtualMachine.getId());
List<VolumeObjectTO> volumeTOs = vmSnapshotHelper.getVolumeTOList(virtualMachine.getId());
GuestOSVO guestOS = guestOSDao.findById(virtualMachine.getGuestOSId());
DeleteVMSnapshotCommand deleteSnapshotCommand = new DeleteVMSnapshotCommand(virtualMachine.getInstanceName(), vmSnapshotTO, volumeTOs, guestOS.getDisplayName());
try {
Answer answer = agentMgr.send(hostId, deleteSnapshotCommand);
if (answer != null && answer.getResult()) {
return true;
} else {
String errMsg = (answer != null) ? answer.getDetails() : null;
throw new CloudRuntimeException("Failed to unquiesce vm, due to " + errMsg);
}
} catch (AgentUnavailableException e) {
throw new CloudRuntimeException("Failed to unquiesce vm", e);
} catch (OperationTimedoutException e) {
throw new CloudRuntimeException("Failed to unquiesce vm", e);
}
}
use of org.apache.cloudstack.storage.to.VolumeObjectTO in project cloudstack by apache.
the class VMSnapshotHelperImpl method getVolumeTOList.
@Override
public List<VolumeObjectTO> getVolumeTOList(Long vmId) {
List<VolumeObjectTO> volumeTOs = new ArrayList<VolumeObjectTO>();
List<VolumeVO> volumeVos = volumeDao.findByInstance(vmId);
VolumeInfo volumeInfo = null;
for (VolumeVO volume : volumeVos) {
volumeInfo = volumeDataFactory.getVolume(volume.getId());
volumeTOs.add((VolumeObjectTO) volumeInfo.getTO());
}
return volumeTOs;
}
use of org.apache.cloudstack.storage.to.VolumeObjectTO in project cloudstack by apache.
the class DefaultVMSnapshotStrategy method updateVolumePath.
private void updateVolumePath(List<VolumeObjectTO> volumeTOs) {
for (VolumeObjectTO volume : volumeTOs) {
if (volume.getPath() != null) {
VolumeVO volumeVO = volumeDao.findById(volume.getId());
volumeVO.setPath(volume.getPath());
volumeVO.setVmSnapshotChainSize(volume.getSize());
volumeDao.persist(volumeVO);
}
}
}
use of org.apache.cloudstack.storage.to.VolumeObjectTO in project cloudstack by apache.
the class KVMStorageProcessor method cloneVolumeFromBaseTemplate.
@Override
public Answer cloneVolumeFromBaseTemplate(final CopyCommand cmd) {
final DataTO srcData = cmd.getSrcTO();
final DataTO destData = cmd.getDestTO();
final TemplateObjectTO template = (TemplateObjectTO) srcData;
final DataStoreTO imageStore = template.getDataStore();
final VolumeObjectTO volume = (VolumeObjectTO) destData;
final PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) volume.getDataStore();
KVMPhysicalDisk BaseVol = null;
KVMStoragePool primaryPool = null;
KVMPhysicalDisk vol = null;
try {
primaryPool = storagePoolMgr.getStoragePool(primaryStore.getPoolType(), primaryStore.getUuid());
String templatePath = template.getPath();
if (primaryPool.getType() == StoragePoolType.CLVM) {
templatePath = ((NfsTO) imageStore).getUrl() + File.separator + templatePath;
vol = templateToPrimaryDownload(templatePath, primaryPool, volume.getUuid(), volume.getSize(), cmd.getWaitInMillSeconds());
} else {
if (templatePath.contains("/mnt")) {
//upgrade issue, if the path contains path, need to extract the volume uuid from path
templatePath = templatePath.substring(templatePath.lastIndexOf(File.separator) + 1);
}
BaseVol = storagePoolMgr.getPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), templatePath);
vol = storagePoolMgr.createDiskFromTemplate(BaseVol, volume.getUuid(), volume.getProvisioningType(), BaseVol.getPool(), volume.getSize(), cmd.getWaitInMillSeconds());
}
if (vol == null) {
return new CopyCmdAnswer(" Can't create storage volume on storage pool");
}
final VolumeObjectTO newVol = new VolumeObjectTO();
newVol.setPath(vol.getName());
newVol.setSize(volume.getSize());
if (vol.getFormat() == PhysicalDiskFormat.RAW) {
newVol.setFormat(ImageFormat.RAW);
} else if (vol.getFormat() == PhysicalDiskFormat.QCOW2) {
newVol.setFormat(ImageFormat.QCOW2);
} else if (vol.getFormat() == PhysicalDiskFormat.DIR) {
newVol.setFormat(ImageFormat.DIR);
}
return new CopyCmdAnswer(newVol);
} catch (final CloudRuntimeException e) {
s_logger.debug("Failed to create volume: ", e);
return new CopyCmdAnswer(e.toString());
}
}
Aggregations