Search in sources :

Example 1 with MockVMVO

use of com.cloud.simulator.MockVMVO in project CloudStack-archive by CloudStack-extras.

the class MockStorageManagerImpl method Destroy.

@Override
public Answer Destroy(DestroyCommand cmd) {
    MockVolumeVO volume = _mockVolumeDao.findByStoragePathAndType(cmd.getVolume().getPath());
    if (volume != null) {
        _mockVolumeDao.remove(volume.getId());
    }
    if (cmd.getVmName() != null) {
        MockVm vm = _mockVMDao.findByVmName(cmd.getVmName());
        vm.setState(State.Expunging);
        if (vm != null) {
            MockVMVO vmVo = _mockVMDao.createForUpdate(vm.getId());
            _mockVMDao.update(vm.getId(), vmVo);
        }
    }
    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) MockVm(com.cloud.simulator.MockVm)

Example 2 with MockVMVO

use of com.cloud.simulator.MockVMVO in project CloudStack-archive by CloudStack-extras.

the class MockVmManagerImpl method startVM.

public String startVM(String vmName, NicTO[] nics, int cpuHz, long ramSize, String bootArgs, String hostGuid) {
    MockHost host = _mockHostDao.findByGuid(hostGuid);
    if (host == null) {
        return "can't find host";
    }
    MockVm vm = _mockVmDao.findByVmName(vmName);
    if (vm == null) {
        int vncPort = 0;
        if (vncPort < 0)
            return "Unable to allocate VNC port";
        vm = new MockVMVO();
        vm.setCpu(cpuHz);
        vm.setMemory(ramSize);
        vm.setState(State.Running);
        vm.setName(vmName);
        vm.setVncPort(vncPort);
        vm.setHostId(host.getId());
        if (vmName.startsWith("s-")) {
            vm.setType("SecondaryStorageVm");
        } else if (vmName.startsWith("v-")) {
            vm.setType("ConsoleProxy");
        } else if (vmName.startsWith("r-")) {
            vm.setType("DomainRouter");
        } else if (vmName.startsWith("i-")) {
            vm.setType("User");
        }
        vm = _mockVmDao.persist((MockVMVO) vm);
    } else {
        if (vm.getState() == State.Stopped) {
            vm.setState(State.Running);
            _mockVmDao.update(vm.getId(), (MockVMVO) vm);
        }
    }
    if (vm.getState() == State.Running && vmName.startsWith("s-")) {
        String prvIp = null;
        String prvMac = null;
        String prvNetMask = null;
        for (NicTO nic : nics) {
            if (nic.getType() == TrafficType.Management) {
                prvIp = nic.getIp();
                prvMac = nic.getMac();
                prvNetMask = nic.getNetmask();
            }
        }
        long dcId = 0;
        long podId = 0;
        String name = null;
        String vmType = null;
        String url = null;
        String[] args = bootArgs.trim().split(" ");
        for (String arg : args) {
            String[] params = arg.split("=");
            if (params.length < 1) {
                continue;
            }
            if (params[0].equalsIgnoreCase("zone")) {
                dcId = Long.parseLong(params[1]);
            } else if (params[0].equalsIgnoreCase("name")) {
                name = params[1];
            } else if (params[0].equalsIgnoreCase("type")) {
                vmType = params[1];
            } else if (params[0].equalsIgnoreCase("url")) {
                url = params[1];
            } else if (params[0].equalsIgnoreCase("pod")) {
                podId = Long.parseLong(params[1]);
            }
        }
        _mockAgentMgr.handleSystemVMStart(vm.getId(), prvIp, prvMac, prvNetMask, dcId, podId, name, vmType, url);
    }
    return null;
}
Also used : MockVMVO(com.cloud.simulator.MockVMVO) MockHost(com.cloud.simulator.MockHost) MockVm(com.cloud.simulator.MockVm) NicTO(com.cloud.agent.api.to.NicTO)

Example 3 with MockVMVO

use of com.cloud.simulator.MockVMVO in project CloudStack-archive by CloudStack-extras.

the class MockAgentManagerImpl method getHostStatistic.

@Override
public GetHostStatsAnswer getHostStatistic(GetHostStatsCommand cmd) {
    String hostGuid = cmd.getHostGuid();
    MockHost host = _mockHostDao.findByGuid(hostGuid);
    if (host == null) {
        return null;
    }
    List<MockVMVO> vms = _mockVmDao.findByHostId(host.getId());
    double usedMem = 0.0;
    double usedCpu = 0.0;
    for (MockVMVO vm : vms) {
        usedMem += vm.getMemory();
        usedCpu += vm.getCpu();
    }
    HostStatsEntry hostStats = new HostStatsEntry();
    hostStats.setTotalMemoryKBs(host.getMemorySize());
    hostStats.setFreeMemoryKBs(host.getMemorySize() - usedMem);
    hostStats.setNetworkReadKBs(32768);
    hostStats.setNetworkWriteKBs(16384);
    hostStats.setCpuUtilization(usedCpu / (host.getCpuCount() * host.getCpuSpeed()));
    hostStats.setEntityType("simulator-host");
    hostStats.setHostId(cmd.getHostId());
    return new GetHostStatsAnswer(cmd, hostStats);
}
Also used : MockVMVO(com.cloud.simulator.MockVMVO) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) MockHost(com.cloud.simulator.MockHost) HostStatsEntry(com.cloud.agent.api.HostStatsEntry)

Example 4 with MockVMVO

use of com.cloud.simulator.MockVMVO in project cloudstack by apache.

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();
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    MockVMVO vm = null;
    try {
        txn.start();
        vm = _mockVMDao.findByVmName(vmName);
        txn.commit();
        if (vm == null) {
            return new Answer(cmd, false, "can't find vm :" + vmName);
        }
    } catch (Exception ex) {
        txn.rollback();
        throw new CloudRuntimeException("Error when attaching iso to vm " + vmName, ex);
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
    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) 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) UploadStatusAnswer(org.apache.cloudstack.storage.command.UploadStatusAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) CreateVolumeFromSnapshotAnswer(com.cloud.agent.api.CreateVolumeFromSnapshotAnswer) ListVolumeAnswer(com.cloud.agent.api.storage.ListVolumeAnswer) SecStorageSetupAnswer(com.cloud.agent.api.SecStorageSetupAnswer) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) MockVolumeVO(com.cloud.simulator.MockVolumeVO) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 5 with MockVMVO

use of com.cloud.simulator.MockVMVO in project cloudstack by apache.

the class MockVmManagerImpl method getVmStates.

@Override
public Map<String, PowerState> getVmStates(final String hostGuid) {
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    try {
        txn.start();
        final Map<String, PowerState> states = new HashMap<String, PowerState>();
        final List<MockVMVO> vms = _mockVmDao.findByHostGuid(hostGuid);
        if (vms.isEmpty()) {
            txn.commit();
            return states;
        }
        for (final MockVm vm : vms) {
            states.put(vm.getName(), vm.getPowerState());
        }
        txn.commit();
        return states;
    } 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) PowerState(com.cloud.vm.VirtualMachine.PowerState) MockVm(com.cloud.simulator.MockVm) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

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