@Override public boolean postStateTransitionEvent(StateMachine2.Transition<State, Event> transition, VirtualMachine vo, boolean status, Object opaque) { State newState = transition.getToState(); State oldState = transition.getCurrentState(); if (newState != State.Starting && newState != State.Error && newState != State.Expunging) { return true; } if (vo.getHypervisorType() != HypervisorType.BareMetal) { return true; } HostVO host = _hostDao.findById(vo.getHostId()); if (host == null) { s_logger.debug("Skip oldState " + oldState + " to " + "newState " + newState + " transimtion"); return true; } _hostDao.loadDetails(host); if (newState == State.Starting) { host.setDetail("vmName", vo.getInstanceName()); s_logger.debug("Add vmName " + host.getDetail("vmName") + " to host " + host.getId() + " details"); } else { if (host.getDetail("vmName") != null && host.getDetail("vmName").equalsIgnoreCase(vo.getInstanceName())) { s_logger.debug("Remove vmName " + host.getDetail("vmName") + " from host " + host.getId() + " details"); host.getDetails().remove("vmName"); } } _hostDao.saveDetails(host); return true; }
private <R extends InternalIdentity> void send(Command cmd, long physicalNetworkId, Class<R> resourceClass, R resource) throws ResourceUnavailableException { HostVO nuageVspHost = _nuageVspManager.getNuageVspHost(physicalNetworkId); Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd); if (isFailure(answer)) { s_logger.error(cmd.getClass().getName() + " for " + resourceClass.getName() + " " + resource.getId() + " failed on Nuage VSD " + nuageVspHost.getDetail("hostname")); if (hasFailureDetails(answer)) { throw new ResourceUnavailableException(answer.getDetails(), resourceClass, resource.getId()); } } }
private void checkL2GatewayServiceSharedNetwork(HostVO niciraNvpHost) throws Exception { String l2GatewayServiceUuid = niciraNvpHost.getDetail("l2gatewayserviceuuid"); if (l2GatewayServiceUuid == null){ throw new Exception("No L2 Gateway Service found"); } else { final FindL2GatewayServiceCommand cmdL2GWService = new FindL2GatewayServiceCommand(new L2GatewayServiceConfig(l2GatewayServiceUuid)); final FindL2GatewayServiceAnswer answerL2GWService = (FindL2GatewayServiceAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmdL2GWService); if (answerL2GWService == null || !answerL2GWService.getResult()){ throw new Exception("No L2 Gateway Service found with uuid " + l2GatewayServiceUuid); } else { String uuidFound = answerL2GWService.getGatewayServiceUuid(); if (! uuidFound.equals(l2GatewayServiceUuid)){ throw new Exception("Found L2 Gateway Service " + uuidFound + " instead of " + l2GatewayServiceUuid); } } } }
ClusterVO cluster = _clusterDao.findById(host.getClusterId()); if (cluster.getGuid() == null) { guid = host.getDetail("pool"); } else { guid = cluster.getGuid();
private void updateNetworkLabels(HostVO host) { //check if networkLabels need to be updated in details //we send only private and storage network label to the resource. String privateNetworkLabel = _networkMgr.getDefaultManagementTrafficLabel(host.getDataCenterId(), host.getHypervisorType()); String storageNetworkLabel = _networkMgr.getDefaultStorageTrafficLabel(host.getDataCenterId(), host.getHypervisorType()); String privateDevice = host.getDetail("private.network.device"); String storageDevice = host.getDetail("storage.network.device1"); boolean update = false; if (privateNetworkLabel != null && !privateNetworkLabel.equalsIgnoreCase(privateDevice)) { host.setDetail("private.network.device", privateNetworkLabel); update = true; } if (storageNetworkLabel != null && !storageNetworkLabel.equalsIgnoreCase(storageDevice)) { host.setDetail("storage.network.device1", storageNetworkLabel); update = true; } if (update) { _hostDao.saveDetails(host); } }
final ClusterVO cluster = _clusterDao.findById(host.getClusterId()); if (cluster.getGuid() == null) { guid = host.getDetail("pool"); } else { guid = cluster.getGuid();
private int getMaxDataVolumesSupported(UserVmVO vm) { Long hostId = vm.getHostId(); if (hostId == null) { hostId = vm.getLastHostId(); } HostVO host = _hostDao.findById(hostId); Integer maxDataVolumesSupported = null; if (host != null) { _hostDao.loadDetails(host); maxDataVolumesSupported = _hypervisorCapabilitiesDao.getMaxDataVolumesLimit(host.getHypervisorType(), host.getDetail("product_version")); } if (maxDataVolumesSupported == null || maxDataVolumesSupported.intValue() <= 0) { maxDataVolumesSupported = 6; // 6 data disks by default if nothing // is specified in // 'hypervisor_capabilities' table } return maxDataVolumesSupported.intValue(); }
@Override public HostVO createHostVOForConnectedAgent(HostVO host, StartupCommand[] cmd) { StartupCommand firstCmd = cmd[0]; if (!(firstCmd instanceof StartupRoutingCommand)) { return null; } StartupRoutingCommand ssCmd = ((StartupRoutingCommand)firstCmd); if (ssCmd.getHypervisorType() != getHypervisorType()) { return null; } /* KVM requires host are the same in cluster */ ClusterVO clusterVO = _clusterDao.findById(host.getClusterId()); if (clusterVO == null) { s_logger.debug("cannot find cluster: " + host.getClusterId()); throw new IllegalArgumentException("cannot add host, due to can't find cluster: " + host.getClusterId()); } List<HostVO> hostsInCluster = _resourceMgr.listAllHostsInCluster(clusterVO.getId()); if (!hostsInCluster.isEmpty()) { HostVO oneHost = hostsInCluster.get(0); _hostDao.loadDetails(oneHost); String hostOsInCluster = oneHost.getDetail("Host.OS"); String hostOs = ssCmd.getHostDetails().get("Host.OS"); if (!hostOsInCluster.equalsIgnoreCase(hostOs)) { throw new IllegalArgumentException("Can't add host: " + firstCmd.getPrivateIpAddress() + " with hostOS: " + hostOs + " into a cluster," + "in which there are " + hostOsInCluster + " hosts added"); } } _hostDao.loadDetails(host); return _resourceMgr.fillRoutingHostVO(host, ssCmd, getHypervisorType(), host.getDetails(), null); }
@Override public OpenDaylightControllerResponse createResponseFromVO(OpenDaylightControllerVO controller) { OpenDaylightControllerResponse response = new OpenDaylightControllerResponse(); HostVO controllerHost = hostDao.findById(controller.getHostId()); hostDao.loadDetails(controllerHost); PhysicalNetwork pnw = ApiDBUtils.findPhysicalNetworkById(controller.getPhysicalNetworkId()); if (pnw != null) { response.setPhysicalNetworkId(pnw.getUuid()); } response.setObjectName("opendaylightcontroller"); response.setId(controller.getUuid()); response.setUrl(controllerHost.getDetail("url")); response.setName(controllerHost.getDetail("name")); response.setUsername(controllerHost.getDetail("username")); return response; }
@Override public NiciraNvpDeviceResponse createNiciraNvpDeviceResponse(NiciraNvpDeviceVO niciraNvpDeviceVO) { HostVO niciraNvpHost = hostDao.findById(niciraNvpDeviceVO.getHostId()); hostDao.loadDetails(niciraNvpHost); NiciraNvpDeviceResponse response = new NiciraNvpDeviceResponse(); response.setDeviceName(niciraNvpDeviceVO.getDeviceName()); PhysicalNetwork pnw = ApiDBUtils.findPhysicalNetworkById(niciraNvpDeviceVO.getPhysicalNetworkId()); if (pnw != null) { response.setPhysicalNetworkId(pnw.getUuid()); } response.setId(niciraNvpDeviceVO.getUuid()); response.setProviderName(niciraNvpDeviceVO.getProviderName()); response.setHostName(niciraNvpHost.getDetail("ip")); response.setTransportZoneUuid(niciraNvpHost.getDetail("transportzoneuuid")); response.setL3GatewayServiceUuid(niciraNvpHost.getDetail("l3gatewayserviceuuid")); response.setL2GatewayServiceUuid(niciraNvpHost.getDetail("l2gatewayserviceuuid")); response.setObjectName("niciranvpdevice"); return response; }
private boolean sharedNetworkSupportNumericalVlanId(Network network, String lSwitchUuid, String ownerName, HostVO niciraNvpHost) { List<VlanVO> networkVlans = vlanDao.listVlansByNetworkId(network.getId()); if (networkVlans.size() == 1){ for (VlanVO vlanVO : networkVlans) { long vlanId = Long.parseLong(vlanVO.getVlanTag()); String l2GatewayServiceUuid = niciraNvpHost.getDetail("l2gatewayserviceuuid"); if (l2GatewayServiceUuid == null){ throw new CloudRuntimeException("No L2 Gateway Service Uuid found on " + niciraNvpHost.getName()); } ConfigureSharedNetworkVlanIdCommand cmd = new ConfigureSharedNetworkVlanIdCommand(lSwitchUuid, l2GatewayServiceUuid , vlanId, ownerName, network.getId()); ConfigureSharedNetworkVlanIdAnswer answer = (ConfigureSharedNetworkVlanIdAnswer)agentMgr.easySend(niciraNvpHost.getId(), cmd); if (answer.getResult() == false) { s_logger.error("Failed to configure Shared network " + network.getDisplayText()); return false; } } } return true; }
new ConfigurePublicIpsOnLogicalRouterCommand(routermapping.getLogicalRouterUuid(), niciraNvpHost.getDetail("l3gatewayserviceuuid"), cidrs); ConfigurePublicIpsOnLogicalRouterAnswer answer = (ConfigurePublicIpsOnLogicalRouterAnswer)agentMgr.easySend(niciraNvpHost.getId(), cmd);
private boolean implement(Long vpcId, long physicalNetworkId, VspNetwork vspNetwork, NetworkVO implemented, VspDhcpDomainOption vspDhcpDomainOption) { HostVO nuageVspHost = _nuageVspManager.getNuageVspHost(physicalNetworkId); final boolean isVsdManaged = vspNetwork.getNetworkRelatedVsdIds() .getVsdSubnetId() .isPresent(); if (isVsdManaged) { //Implement cmd was already send in design step. _dcDetailsDao.persist(implemented.getDataCenterId(), vspNetwork.getNetworkRelatedVsdIds().getVsdSubnetId().orElseThrow(() -> new CloudRuntimeException("Managed but no subnetId. How can this happen?")), implemented.getUuid()); return true; } ImplementNetworkVspCommand cmd = new ImplementNetworkVspCommand(vspNetwork, vspDhcpDomainOption, false); Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd); if (answer == null || !answer.getResult()) { s_logger.error("ImplementNetworkVspCommand for network " + vspNetwork.getUuid() + " failed on Nuage VSD " + nuageVspHost.getDetail("hostname")); if ((null != answer) && (null != answer.getDetails())) { s_logger.error(answer.getDetails()); } return false; } ImplementNetworkVspAnswer implementAnswer = (ImplementNetworkVspAnswer) answer; saveNetworkAndVpcDetails(vspNetwork, implementAnswer.getNetworkRelatedVsdIds(), vpcId); return true; }
String vmName = host.getDetail("vmName"); if (vmName == null) { throw new CloudRuntimeException(String.format("cannot find any baremetal instance running on host[mac:%s]", cmd.getMac()));
Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd); if (answer == null || !answer.getResult()) { s_logger.error("ImplementNetworkVspCommand for network " + vspNetwork.getUuid() + " failed on Nuage VSD " + nuageVspHost.getDetail("hostname")); if ((null != answer) && (null != answer.getDetails())) { s_logger.error(answer.getDetails()); throw new CloudRuntimeException("ImplementNetworkVspCommand for network " + vspNetwork.getUuid() + " failed on Nuage VSD " + nuageVspHost.getDetail("hostname"));
@Override public BrocadeVcsDeviceResponse createBrocadeVcsDeviceResponse(BrocadeVcsDeviceVO brocadeVcsDeviceVO) { HostVO brocadeVcsHost = _hostDao.findById(brocadeVcsDeviceVO.getHostId()); _hostDao.loadDetails(brocadeVcsHost); BrocadeVcsDeviceResponse response = new BrocadeVcsDeviceResponse(); response.setDeviceName(brocadeVcsDeviceVO.getDeviceName()); PhysicalNetwork pnw = ApiDBUtils.findPhysicalNetworkById(brocadeVcsDeviceVO.getPhysicalNetworkId()); if (pnw != null) { response.setPhysicalNetworkId(pnw.getUuid()); } response.setId(brocadeVcsDeviceVO.getUuid()); response.setProviderName(brocadeVcsDeviceVO.getProviderName()); response.setHostName(brocadeVcsHost.getDetail("ip")); response.setObjectName("brocadevcsdevice"); return response; }
@Override public BigSwitchBcfDeviceResponse createBigSwitchBcfDeviceResponse(BigSwitchBcfDeviceVO bigswitchBcfDeviceVO) { HostVO bigswitchBcfHost = _hostDao.findById(bigswitchBcfDeviceVO.getHostId()); _hostDao.loadDetails(bigswitchBcfHost); BigSwitchBcfDeviceResponse response = new BigSwitchBcfDeviceResponse(); response.setDeviceName(bigswitchBcfDeviceVO.getDeviceName()); PhysicalNetwork pnw = ApiDBUtils.findPhysicalNetworkById(bigswitchBcfDeviceVO.getPhysicalNetworkId()); if (pnw != null) { response.setPhysicalNetworkId(pnw.getUuid()); } response.setId(bigswitchBcfDeviceVO.getUuid()); response.setProviderName(bigswitchBcfDeviceVO.getProviderName()); response.setHostName(bigswitchBcfHost.getDetail("hostname")); response.setObjectName("bigswitchbcfdevice"); return response; }