use of com.cloud.simulator.MockVMVO in project cloudstack by apache.
the class MockVmManagerImpl method migrate.
@Override
public MigrateAnswer migrate(final MigrateCommand cmd, final SimulatorInfo info) {
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
final String vmName = cmd.getVmName();
final String destGuid = cmd.getHostGuid();
final MockVMVO vm = _mockVmDao.findByVmNameAndHost(vmName, info.getHostUuid());
if (vm == null) {
return new MigrateAnswer(cmd, false, "can't find vm:" + vmName + " on host:" + info.getHostUuid(), null);
}
final MockHost destHost = _mockHostDao.findByGuid(destGuid);
if (destHost == null) {
return new MigrateAnswer(cmd, false, "can't find destination host:" + destGuid, null);
}
vm.setHostId(destHost.getId());
_mockVmDao.update(vm.getId(), vm);
txn.commit();
return new MigrateAnswer(cmd, true, null, 0);
} catch (final Exception ex) {
txn.rollback();
throw new CloudRuntimeException("unable to migrate vm " + cmd.getVmName(), 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 AgentRoutingResource method initialize.
@Override
public StartupCommand[] initialize() {
Map<String, MockVMVO> vmsMaps = _simMgr.getVms(this.hostGuid);
totalCpu = agentHost.getCpuCount() * agentHost.getCpuSpeed();
totalMem = agentHost.getMemorySize();
for (Map.Entry<String, MockVMVO> entry : vmsMaps.entrySet()) {
MockVMVO vm = entry.getValue();
usedCpu += vm.getCpu();
usedMem += vm.getMemory();
_runningVms.put(entry.getKey(), new Pair<Long, Long>(Long.valueOf(vm.getCpu()), vm.getMemory()));
}
List<Object> info = getHostInfo();
StartupRoutingCommand cmd = new StartupRoutingCommand((Integer) info.get(0), (Long) info.get(1), (Long) info.get(2), (Long) info.get(4), (String) info.get(3), HypervisorType.Simulator, RouterPrivateIpStrategy.HostLocal);
Map<String, String> hostDetails = new HashMap<String, String>();
hostDetails.put(RouterPrivateIpStrategy.class.getCanonicalName(), RouterPrivateIpStrategy.DcGlobal.toString());
cmd.setHostDetails(hostDetails);
cmd.setAgentTag("agent-simulator");
cmd.setPrivateIpAddress(agentHost.getPrivateIpAddress());
cmd.setPrivateNetmask(agentHost.getPrivateNetMask());
cmd.setPrivateMacAddress(agentHost.getPrivateMacAddress());
cmd.setStorageIpAddress(agentHost.getStorageIpAddress());
cmd.setStorageNetmask(agentHost.getStorageNetMask());
cmd.setStorageMacAddress(agentHost.getStorageMacAddress());
cmd.setStorageIpAddressDeux(agentHost.getStorageIpAddress());
cmd.setStorageNetmaskDeux(agentHost.getStorageNetMask());
cmd.setStorageMacAddressDeux(agentHost.getStorageIpAddress());
cmd.setName(agentHost.getName());
cmd.setGuid(agentHost.getGuid());
cmd.setVersion(agentHost.getVersion());
cmd.setAgentTag("agent-simulator");
cmd.setDataCenter(String.valueOf(agentHost.getDataCenterId()));
cmd.setPod(String.valueOf(agentHost.getPodId()));
cmd.setCluster(String.valueOf(agentHost.getClusterId()));
StartupStorageCommand ssCmd = initializeLocalSR();
return new StartupCommand[] { cmd, ssCmd };
}
use of com.cloud.simulator.MockVMVO in project cloudstack by apache.
the class MockVmManagerImpl method checkVmState.
@Override
public CheckVirtualMachineAnswer checkVmState(final CheckVirtualMachineCommand cmd) {
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
final MockVMVO vm = _mockVmDao.findByVmName(cmd.getVmName());
if (vm == null) {
return new CheckVirtualMachineAnswer(cmd, "can't find vm:" + cmd.getVmName());
}
txn.commit();
return new CheckVirtualMachineAnswer(cmd, vm.getPowerState(), vm.getVncPort());
} catch (final Exception ex) {
txn.rollback();
throw new CloudRuntimeException("unable to fetch vm state " + cmd.getVmName(), 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 startVM.
public String startVM(final String vmName, final NicTO[] nics, final int cpuHz, final long ramSize, final String bootArgs, final String hostGuid) {
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
MockHost host = null;
MockVm vm = null;
try {
txn.start();
host = _mockHostDao.findByGuid(hostGuid);
if (host == null) {
return "can't find host";
}
vm = _mockVmDao.findByVmName(vmName);
txn.commit();
} catch (final Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Unable to start VM " + vmName, ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
if (vm == null) {
final int vncPort = 0;
if (vncPort < 0) {
return "Unable to allocate VNC port";
}
vm = new MockVMVO();
vm.setCpu(cpuHz);
vm.setMemory(ramSize);
vm.setPowerState(PowerState.PowerOn);
vm.setName(vmName);
vm.setVncPort(vncPort);
vm.setHostId(host.getId());
vm.setBootargs(bootArgs);
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");
}
txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
vm = _mockVmDao.persist((MockVMVO) vm);
txn.commit();
} catch (final Exception ex) {
txn.rollback();
throw new CloudRuntimeException("unable to save vm to db " + vm.getName(), ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
} else {
if (vm.getPowerState() == PowerState.PowerOff) {
vm.setPowerState(PowerState.PowerOn);
txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
_mockVmDao.update(vm.getId(), (MockVMVO) vm);
txn.commit();
} catch (final Exception ex) {
txn.rollback();
throw new CloudRuntimeException("unable to update vm " + vm.getName(), ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
}
}
if (vm.getPowerState() == PowerState.PowerOn && vmName.startsWith("s-")) {
String prvIp = null;
String prvMac = null;
String prvNetMask = null;
for (final 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;
final String[] args = bootArgs.trim().split(" ");
for (final String arg : args) {
final 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 by apache.
the class MockVmManagerImpl method prepareForMigrate.
@Override
public PrepareForMigrationAnswer prepareForMigrate(final PrepareForMigrationCommand cmd) {
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
final VirtualMachineTO vmTo = cmd.getVirtualMachine();
try {
txn.start();
final MockVMVO vm = _mockVmDao.findById(vmTo.getId());
_mockVmDao.update(vm.getId(), vm);
txn.commit();
} catch (final Exception ex) {
txn.rollback();
throw new CloudRuntimeException("unable to find vm " + vmTo.getName(), ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
return new PrepareForMigrationAnswer(cmd);
}
}
Aggregations