long cidrSize = getPodCidr(podId, dataCenterId).second();
int agentId = getNextAgentId(cidrSize);
String ipAddress = getIpAddress(agentId, dataCenterId, podId);
String macAddress = getMacAddress(dataCenterId, podId, clusterId, agentId);
MockHostVO mockHost = new MockHostVO();
mockHost.setDataCenterId(dataCenterId);
mockHost.setPodId(podId);
mockHost.setClusterId(clusterId);
mockHost.setCapabilities("hvm");
mockHost.setCpuCount(cpuCore);
mockHost.setCpuSpeed(cpuSpeed);
mockHost.setMemorySize(memory);
String guid = UUID.randomUUID().toString();
mockHost.setGuid(guid);
mockHost.setName("SimulatedAgent." + guid);
mockHost.setPrivateIpAddress(ipAddress);
mockHost.setPublicIpAddress(ipAddress);
mockHost.setStorageIpAddress(ipAddress);
mockHost.setPrivateMacAddress(macAddress);
mockHost.setPublicMacAddress(macAddress);
mockHost.setStorageMacAddress(macAddress);
mockHost.setVersion(this.getClass().getPackage().getImplementationVersion());
mockHost.setResource("com.cloud.agent.AgentRoutingResource");
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
mockHost = _mockHostDao.persist(mockHost);
txn.commit();
} catch (Exception ex) {
txn.rollback();
s_logger.error("Error while configuring mock agent " + ex.getMessage());
throw new CloudRuntimeException("Error configuring agent", ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
_storageMgr.getLocalStorage(guid, localStorageSize);
agentResource = new AgentRoutingResource();
if (agentResource != null) {
try {
params.put("guid", mockHost.getGuid());
agentResource.start();
agentResource.configure(mockHost.getName(), params);
newResources.put(agentResource, args);
} catch (ConfigurationException e) {
s_logger.error("error while configuring server resource" + e.getMessage());
}