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);
}
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;
}
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);
}
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);
}
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();
}
}
Aggregations