Search in sources :

Example 6 with MockVMVO

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();
    }
}
Also used : MockVMVO(com.cloud.simulator.MockVMVO) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) ScaleVmAnswer(com.cloud.agent.api.ScaleVmAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 7 with MockVMVO

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());
}
Also used : MockVMVO(com.cloud.simulator.MockVMVO) RevertToVMSnapshotAnswer(com.cloud.agent.api.RevertToVMSnapshotAnswer)

Example 8 with MockVMVO

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();
    }
}
Also used : MockVMVO(com.cloud.simulator.MockVMVO) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 9 with MockVMVO

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);
}
Also used : MockVMVO(com.cloud.simulator.MockVMVO) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer) Answer(com.cloud.agent.api.Answer) BackupSnapshotAnswer(com.cloud.agent.api.BackupSnapshotAnswer) ListTemplateAnswer(com.cloud.agent.api.storage.ListTemplateAnswer) ManageSnapshotAnswer(com.cloud.agent.api.ManageSnapshotAnswer) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) AttachVolumeAnswer(com.cloud.agent.api.AttachVolumeAnswer) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) CreateVolumeFromSnapshotAnswer(com.cloud.agent.api.CreateVolumeFromSnapshotAnswer) SecStorageSetupAnswer(com.cloud.agent.api.SecStorageSetupAnswer) MockVolumeVO(com.cloud.simulator.MockVolumeVO)

Example 10 with MockVMVO

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());
}
Also used : MockVMVO(com.cloud.simulator.MockVMVO) AttachVolumeAnswer(com.cloud.agent.api.AttachVolumeAnswer) MockVolumeVO(com.cloud.simulator.MockVolumeVO)

Aggregations

MockVMVO (com.cloud.simulator.MockVMVO)21 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)10 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)10 ConfigurationException (javax.naming.ConfigurationException)10 MockHost (com.cloud.simulator.MockHost)6 HashMap (java.util.HashMap)6 MockVm (com.cloud.simulator.MockVm)5 Answer (com.cloud.agent.api.Answer)4 MockVolumeVO (com.cloud.simulator.MockVolumeVO)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 AttachVolumeAnswer (com.cloud.agent.api.AttachVolumeAnswer)3 BackupSnapshotAnswer (com.cloud.agent.api.BackupSnapshotAnswer)3 CreateVolumeFromSnapshotAnswer (com.cloud.agent.api.CreateVolumeFromSnapshotAnswer)3 GetStorageStatsAnswer (com.cloud.agent.api.GetStorageStatsAnswer)3 ManageSnapshotAnswer (com.cloud.agent.api.ManageSnapshotAnswer)3 MigrateAnswer (com.cloud.agent.api.MigrateAnswer)3 ModifyStoragePoolAnswer (com.cloud.agent.api.ModifyStoragePoolAnswer)3 SecStorageSetupAnswer (com.cloud.agent.api.SecStorageSetupAnswer)3 CheckVirtualMachineAnswer (com.cloud.agent.api.CheckVirtualMachineAnswer)2 GetHostStatsAnswer (com.cloud.agent.api.GetHostStatsAnswer)2