use of com.cloud.simulator.MockStoragePoolVO in project CloudStack-archive by CloudStack-extras.
the class MockStorageManagerImpl method CopyVolume.
@Override
public CopyVolumeAnswer CopyVolume(CopyVolumeCommand cmd) {
boolean toSecondaryStorage = cmd.toSecondaryStorage();
MockSecStorageVO sec = _mockSecStorageDao.findByUrl(cmd.getSecondaryStorageURL());
if (sec == null) {
return new CopyVolumeAnswer(cmd, false, "can't find secondary storage", null, null);
}
MockStoragePoolVO primaryStorage = _mockStoragePoolDao.findByUuid(cmd.getPool().getUuid());
if (primaryStorage == null) {
return new CopyVolumeAnswer(cmd, false, "Can't find primary storage", null, null);
}
MockVolumeVO volume = _mockVolumeDao.findByStoragePathAndType(cmd.getVolumePath());
if (volume == null) {
return new CopyVolumeAnswer(cmd, false, "cant' find volume" + cmd.getVolumePath(), null, null);
}
String name = UUID.randomUUID().toString();
if (toSecondaryStorage) {
MockVolumeVO vol = new MockVolumeVO();
vol.setName(name);
vol.setPath(sec.getMountPoint() + name);
vol.setPoolId(sec.getId());
vol.setSize(volume.getSize());
vol.setStatus(Status.DOWNLOADED);
vol.setType(MockVolumeType.VOLUME);
vol = _mockVolumeDao.persist(vol);
return new CopyVolumeAnswer(cmd, true, null, sec.getMountPoint(), vol.getPath());
} else {
MockVolumeVO vol = new MockVolumeVO();
vol.setName(name);
vol.setPath(primaryStorage.getMountPoint() + name);
vol.setPoolId(primaryStorage.getId());
vol.setSize(volume.getSize());
vol.setStatus(Status.DOWNLOADED);
vol.setType(MockVolumeType.VOLUME);
vol = _mockVolumeDao.persist(vol);
return new CopyVolumeAnswer(cmd, true, null, primaryStorage.getMountPoint(), vol.getPath());
}
}
use of com.cloud.simulator.MockStoragePoolVO in project CloudStack-archive by CloudStack-extras.
the class MockStorageManagerImpl method ManageSnapshot.
@Override
public ManageSnapshotAnswer ManageSnapshot(ManageSnapshotCommand cmd) {
String volPath = cmd.getVolumePath();
MockVolumeVO volume = _mockVolumeDao.findByStoragePathAndType(volPath);
if (volume == null) {
return new ManageSnapshotAnswer(cmd, false, "Can't find the volume");
}
MockStoragePoolVO storagePool = _mockStoragePoolDao.findById(volume.getPoolId());
if (storagePool == null) {
return new ManageSnapshotAnswer(cmd, false, "Can't find the storage pooll");
}
String mountPoint = storagePool.getMountPoint();
MockVolumeVO snapshot = new MockVolumeVO();
snapshot.setName(cmd.getSnapshotName());
snapshot.setPath(mountPoint + cmd.getSnapshotName());
snapshot.setSize(volume.getSize());
snapshot.setPoolId(storagePool.getId());
snapshot.setType(MockVolumeType.SNAPSHOT);
snapshot.setStatus(Status.DOWNLOADED);
snapshot = _mockVolumeDao.persist(snapshot);
return new ManageSnapshotAnswer(cmd, snapshot.getId(), snapshot.getPath(), true, "");
}
use of com.cloud.simulator.MockStoragePoolVO in project CloudStack-archive by CloudStack-extras.
the class MockStorageManagerImpl method GetStorageStats.
@Override
public GetStorageStatsAnswer GetStorageStats(GetStorageStatsCommand cmd) {
String uuid = cmd.getStorageId();
if (uuid == null) {
String secUrl = cmd.getSecUrl();
MockSecStorageVO secondary = _mockSecStorageDao.findByUrl(secUrl);
if (secondary == null) {
return new GetStorageStatsAnswer(cmd, "Can't find the secondary storage:" + secUrl);
}
Long totalUsed = _mockVolumeDao.findTotalStorageId(secondary.getId());
return new GetStorageStatsAnswer(cmd, secondary.getCapacity(), totalUsed);
} else {
MockStoragePoolVO pool = _mockStoragePoolDao.findByUuid(uuid);
if (pool == null) {
return new GetStorageStatsAnswer(cmd, "Can't find the pool");
}
Long totalUsed = _mockVolumeDao.findTotalStorageId(pool.getId());
if (totalUsed == null) {
totalUsed = 0L;
}
return new GetStorageStatsAnswer(cmd, pool.getCapacity(), totalUsed);
}
}
use of com.cloud.simulator.MockStoragePoolVO in project CloudStack-archive by CloudStack-extras.
the class MockStorageManagerImpl method DeleteStoragePool.
@Override
public Answer DeleteStoragePool(DeleteStoragePoolCommand cmd) {
MockStoragePoolVO storage = _mockStoragePoolDao.findByUuid(cmd.getPool().getUuid());
if (storage == null) {
return new Answer(cmd, false, "can't find storage pool:" + cmd.getPool().getUuid());
}
_mockStoragePoolDao.remove(storage.getId());
return new Answer(cmd);
}
use of com.cloud.simulator.MockStoragePoolVO in project CloudStack-archive by CloudStack-extras.
the class MockStorageManagerImpl method getLocalStorage.
@Override
public StoragePoolInfo getLocalStorage(String hostGuid) {
MockHost host = _mockHostDao.findByGuid(hostGuid);
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(DEFAULT_HOST_STORAGE_SIZE);
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);
}
Aggregations