use of com.cloud.simulator.MockVMVO in project cloudstack by apache.
the class MockVmManagerImpl method scaleVm.
@Override
public Answer scaleVm(final ScaleVmCommand cmd) {
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
final String vmName = cmd.getVmName();
final MockVMVO vm = _mockVmDao.findByVmName(vmName);
if (vm == null) {
return new ScaleVmAnswer(cmd, false, "Can't find VM " + vmName);
}
vm.setCpu(cmd.getCpus() * cmd.getMaxSpeed());
vm.setMemory(cmd.getMaxRam());
_mockVmDao.update(vm.getId(), vm);
s_logger.debug("Scaled up VM " + vmName);
txn.commit();
return new ScaleVmAnswer(cmd, true, null);
} catch (final Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Unable to scale up VM", ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
}
use of com.cloud.simulator.MockVMVO in project cloudstack by apache.
the class MockVmManagerImpl method revertVmSnapshot.
@Override
public Answer revertVmSnapshot(final RevertToVMSnapshotCommand cmd) {
final String vm = cmd.getVmName();
final String snapshot = cmd.getTarget().getSnapshotName();
final MockVMVO vmVo = _mockVmDao.findByVmName(cmd.getVmName());
if (vmVo == null) {
return new RevertToVMSnapshotAnswer(cmd, false, "No VM by name " + cmd.getVmName());
}
s_logger.debug("Reverted to snapshot " + snapshot + " of VM " + vm);
return new RevertToVMSnapshotAnswer(cmd, cmd.getVolumeTOs(), vmVo.getPowerState());
}
use of com.cloud.simulator.MockVMVO in project cloudstack by apache.
the class MockVmManagerImpl method getVms.
@Override
public Map<String, MockVMVO> getVms(final String hostGuid) {
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
final List<MockVMVO> vms = _mockVmDao.findByHostGuid(hostGuid);
final Map<String, MockVMVO> vmMap = new HashMap<String, MockVMVO>();
for (final MockVMVO vm : vms) {
vmMap.put(vm.getName(), vm);
}
txn.commit();
return vmMap;
} catch (final Exception ex) {
txn.rollback();
throw new CloudRuntimeException("unable to fetch vms from host " + hostGuid, ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
}
use of com.cloud.simulator.MockVMVO 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.MockVMVO 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