use of com.cloud.simulator.MockVolumeVO in project CloudStack-archive by CloudStack-extras.
the class MockStorageManagerImpl method CreateVolumeFromSnapshot.
@Override
public CreateVolumeFromSnapshotAnswer CreateVolumeFromSnapshot(CreateVolumeFromSnapshotCommand cmd) {
MockVolumeVO backSnapshot = _mockVolumeDao.findByName(cmd.getSnapshotUuid());
if (backSnapshot == null) {
return new CreateVolumeFromSnapshotAnswer(cmd, false, "can't find the backupsnapshot: " + cmd.getSnapshotUuid(), null);
}
MockStoragePoolVO primary = _mockStoragePoolDao.findByUuid(cmd.getPrimaryStoragePoolNameLabel());
if (primary == null) {
return new CreateVolumeFromSnapshotAnswer(cmd, false, "can't find the primary storage: " + cmd.getPrimaryStoragePoolNameLabel(), null);
}
String uuid = UUID.randomUUID().toString();
MockVolumeVO volume = new MockVolumeVO();
volume.setName(uuid);
volume.setPath(primary.getMountPoint() + uuid);
volume.setPoolId(primary.getId());
volume.setSize(backSnapshot.getSize());
volume.setStatus(Status.DOWNLOADED);
volume.setType(MockVolumeType.VOLUME);
_mockVolumeDao.persist(volume);
return new CreateVolumeFromSnapshotAnswer(cmd, true, null, volume.getPath());
}
use of com.cloud.simulator.MockVolumeVO in project CloudStack-archive by CloudStack-extras.
the class MockStorageManagerImpl method DeleteTemplate.
@Override
public Answer DeleteTemplate(DeleteTemplateCommand cmd) {
MockVolumeVO template = _mockVolumeDao.findByStoragePathAndType(cmd.getTemplatePath());
if (template == null) {
return new Answer(cmd, false, "can't find template:" + cmd.getTemplatePath());
}
_mockVolumeDao.remove(template.getId());
return new Answer(cmd);
}
use of com.cloud.simulator.MockVolumeVO in project CloudStack-archive by CloudStack-extras.
the class MockStorageManagerImpl method AttachIso.
@Override
public Answer AttachIso(AttachIsoCommand cmd) {
MockVolumeVO iso = findVolumeFromSecondary(cmd.getIsoPath(), cmd.getStoreUrl(), MockVolumeType.ISO);
if (iso == null) {
return new Answer(cmd, false, "Failed to find the iso: " + cmd.getIsoPath() + "on secondary storage " + cmd.getStoreUrl());
}
String vmName = cmd.getVmName();
MockVMVO vm = _mockVMDao.findByVmName(vmName);
if (vm == null) {
return new Answer(cmd, false, "can't vm :" + vmName);
}
return new Answer(cmd);
}
use of com.cloud.simulator.MockVolumeVO in project CloudStack-archive by CloudStack-extras.
the class MockStorageManagerImpl method DownloadProcess.
@Override
public DownloadAnswer DownloadProcess(DownloadProgressCommand cmd) {
String volumeId = cmd.getJobId();
MockVolumeVO volume = _mockVolumeDao.findById(Long.parseLong(volumeId));
if (volume == null) {
return new DownloadAnswer("Can't find the downloading volume", Status.ABANDONED);
}
long size = Math.min(volume.getSize() + DEFAULT_TEMPLATE_SIZE / 5, DEFAULT_TEMPLATE_SIZE);
volume.setSize(size);
double volumeSize = volume.getSize();
double pct = volumeSize / DEFAULT_TEMPLATE_SIZE;
if (pct >= 1.0) {
volume.setStatus(Status.DOWNLOADED);
_mockVolumeDao.update(volume.getId(), volume);
return new DownloadAnswer(cmd.getJobId(), 100, cmd, com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOADED, volume.getPath(), volume.getName());
} else {
_mockVolumeDao.update(volume.getId(), volume);
return new DownloadAnswer(cmd.getJobId(), (int) (pct * 100.0), cmd, com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOAD_IN_PROGRESS, volume.getPath(), volume.getName());
}
}
use of com.cloud.simulator.MockVolumeVO in project CloudStack-archive by CloudStack-extras.
the class MockStorageManagerImpl method AttachVolume.
@Override
public AttachVolumeAnswer AttachVolume(AttachVolumeCommand cmd) {
String poolid = cmd.getPoolUuid();
String volumeName = cmd.getVolumeName();
MockVolumeVO volume = _mockVolumeDao.findByStoragePathAndType(cmd.getVolumePath());
if (volume == null) {
return new AttachVolumeAnswer(cmd, "Can't find volume:" + volumeName + "on pool:" + poolid);
}
String vmName = cmd.getVmName();
MockVMVO vm = _mockVMDao.findByVmName(vmName);
if (vm == null) {
return new AttachVolumeAnswer(cmd, "can't vm :" + vmName);
}
return new AttachVolumeAnswer(cmd, cmd.getDeviceId());
}
Aggregations