use of com.cloud.simulator.MockStoragePoolVO 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.MockStoragePoolVO in project CloudStack-archive by CloudStack-extras.
the class MockStorageManagerImpl method getLocalStorage.
@Override
public StoragePoolInfo getLocalStorage(String hostGuid, Long storageSize) {
MockHost host = _mockHostDao.findByGuid(hostGuid);
if (storageSize == null) {
storageSize = DEFAULT_HOST_STORAGE_SIZE;
}
MockStoragePoolVO storagePool = _mockStoragePoolDao.findByHost(hostGuid);
if (storagePool == null) {
String uuid = UUID.randomUUID().toString();
storagePool = new MockStoragePoolVO();
storagePool.setUuid(uuid);
storagePool.setMountPoint("/mnt/" + uuid + File.separator);
storagePool.setCapacity(storageSize);
storagePool.setHostGuid(hostGuid);
storagePool.setStorageType(StoragePoolType.Filesystem);
storagePool = _mockStoragePoolDao.persist(storagePool);
}
return new StoragePoolInfo(storagePool.getUuid(), host.getPrivateIpAddress(), storagePool.getMountPoint(), storagePool.getMountPoint(), storagePool.getPoolType(), storagePool.getCapacity(), 0);
}
use of com.cloud.simulator.MockStoragePoolVO in project CloudStack-archive by CloudStack-extras.
the class MockStorageManagerImpl method ModifyStoragePool.
@Override
public ModifyStoragePoolAnswer ModifyStoragePool(ModifyStoragePoolCommand cmd) {
StorageFilerTO sf = cmd.getPool();
MockStoragePoolVO storagePool = _mockStoragePoolDao.findByUuid(sf.getUuid());
if (storagePool == null) {
storagePool = new MockStoragePoolVO();
storagePool.setUuid(sf.getUuid());
storagePool.setMountPoint("/mnt/" + sf.getUuid() + File.separator);
Long size = DEFAULT_HOST_STORAGE_SIZE;
String path = sf.getPath();
int index = path.lastIndexOf("/");
if (index != -1) {
path = path.substring(index + 1);
if (path != null) {
String[] values = path.split("=");
if (values.length > 1 && values[0].equalsIgnoreCase("size")) {
size = Long.parseLong(values[1]);
}
}
}
storagePool.setCapacity(size);
storagePool.setStorageType(sf.getType());
storagePool = _mockStoragePoolDao.persist(storagePool);
}
return new ModifyStoragePoolAnswer(cmd, storagePool.getCapacity(), 0, new HashMap<String, TemplateInfo>());
}
use of com.cloud.simulator.MockStoragePoolVO in project CloudStack-archive by CloudStack-extras.
the class MockStorageManagerImpl method CreateStoragePool.
@Override
public Answer CreateStoragePool(CreateStoragePoolCommand cmd) {
StorageFilerTO sf = cmd.getPool();
MockStoragePoolVO storagePool = _mockStoragePoolDao.findByUuid(sf.getUuid());
if (storagePool == null) {
storagePool = new MockStoragePoolVO();
storagePool.setUuid(sf.getUuid());
storagePool.setMountPoint("/mnt/" + sf.getUuid() + File.separator);
Long size = DEFAULT_HOST_STORAGE_SIZE;
String path = sf.getPath();
int index = path.lastIndexOf("/");
if (index != -1) {
path = path.substring(index + 1);
if (path != null) {
String[] values = path.split("=");
if (values.length > 1 && values[0].equalsIgnoreCase("size")) {
size = Long.parseLong(values[1]);
}
}
}
storagePool.setCapacity(size);
storagePool.setStorageType(sf.getType());
storagePool = _mockStoragePoolDao.persist(storagePool);
}
return new ModifyStoragePoolAnswer(cmd, storagePool.getCapacity(), 0, new HashMap<String, TemplateInfo>());
}
use of com.cloud.simulator.MockStoragePoolVO in project CloudStack-archive by CloudStack-extras.
the class MockStorageManagerImpl method primaryStorageDownload.
@Override
public PrimaryStorageDownloadAnswer primaryStorageDownload(PrimaryStorageDownloadCommand cmd) {
MockVolumeVO template = findVolumeFromSecondary(cmd.getUrl(), cmd.getSecondaryStorageUrl(), MockVolumeType.TEMPLATE);
if (template == null) {
return new PrimaryStorageDownloadAnswer("Can't find primary storage");
}
MockStoragePoolVO primaryStorage = _mockStoragePoolDao.findByUuid(cmd.getPoolUuid());
if (primaryStorage == null) {
return new PrimaryStorageDownloadAnswer("Can't find primary storage");
}
String volumeName = UUID.randomUUID().toString();
MockVolumeVO newVolume = new MockVolumeVO();
newVolume.setName(volumeName);
newVolume.setPath(primaryStorage.getMountPoint() + volumeName);
newVolume.setPoolId(primaryStorage.getId());
newVolume.setSize(template.getSize());
newVolume.setType(MockVolumeType.VOLUME);
_mockVolumeDao.persist(newVolume);
return new PrimaryStorageDownloadAnswer(newVolume.getPath(), newVolume.getSize());
}
Aggregations