protected LinkedHashMap<Network, List<? extends NicProfile>> configurePublicNic( final RouterDeploymentDefinition routerDeploymentDefinition, final boolean hasGuestNic) { final LinkedHashMap<Network, List<? extends NicProfile>> publicConfig = new LinkedHashMap<Network, List<? extends NicProfile>>(3); if (routerDeploymentDefinition.isPublicNetwork()) { s_logger.debug("Adding nic for Virtual Router in Public network "); // if source nat service is supported by the network, get the source // nat ip address final NicProfile defaultNic = new NicProfile(); defaultNic.setDefaultNic(true); final PublicIp sourceNatIp = routerDeploymentDefinition.getSourceNatIP(); defaultNic.setIPv4Address(sourceNatIp.getAddress().addr()); defaultNic.setIPv4Gateway(sourceNatIp.getGateway()); defaultNic.setIPv4Netmask(sourceNatIp.getNetmask()); defaultNic.setMacAddress(sourceNatIp.getMacAddress()); // get broadcast from public network final Network pubNet = _networkDao.findById(sourceNatIp.getNetworkId()); if (pubNet.getBroadcastDomainType() == BroadcastDomainType.Vxlan) { defaultNic.setBroadcastType(BroadcastDomainType.Vxlan); defaultNic.setBroadcastUri(BroadcastDomainType.Vxlan.toUri(sourceNatIp.getVlanTag())); defaultNic.setIsolationUri(BroadcastDomainType.Vxlan.toUri(sourceNatIp.getVlanTag())); } else { defaultNic.setBroadcastType(BroadcastDomainType.Vlan); defaultNic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(sourceNatIp.getVlanTag())); defaultNic.setIsolationUri(IsolationType.Vlan.toUri(sourceNatIp.getVlanTag())); } // If guest nic has already been added we will have 2 devices in the list. if (hasGuestNic) { defaultNic.setDeviceId(2); } final NetworkOffering publicOffering = _networkModel .getSystemAccountNetworkOfferings(NetworkOffering.SystemPublicNetwork) .get(0); final List<? extends Network> publicNetworks = _networkMgr.setupNetwork( s_systemAccount, publicOffering, routerDeploymentDefinition.getPlan(), null, null, false); final String publicIp = defaultNic.getIPv4Address(); // We want to use the identical MAC address for RvR on public // interface if possible final NicVO peerNic = _nicDao.findByIp4AddressAndNetworkId(publicIp, publicNetworks.get(0).getId()); if (peerNic != null) { s_logger.info("Use same MAC as previous RvR, the MAC is " + peerNic.getMacAddress()); defaultNic.setMacAddress(peerNic.getMacAddress()); } publicConfig.put(publicNetworks.get(0), new ArrayList<NicProfile>(Arrays.asList(defaultNic))); } return publicConfig; }
protected Map<String, Object> createSecStorageVmInstance( long dataCenterId, SecondaryStorageVm.Role role) { HostVO secHost = _hostDao.findSecondaryStorageHost(dataCenterId); if (secHost == null) { String msg = "No secondary storage available in zone " + dataCenterId + ", cannot create secondary storage vm"; s_logger.warn(msg); throw new CloudRuntimeException(msg); } long id = _secStorageVmDao.getNextInSequence(Long.class, "id"); String name = VirtualMachineName.getSystemVmName(id, _instance, "s").intern(); Account systemAcct = _accountMgr.getSystemAccount(); DataCenterDeployment plan = new DataCenterDeployment(dataCenterId); DataCenter dc = _dcDao.findById(plan.getDataCenterId()); List<NetworkOfferingVO> defaultOffering = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemPublicNetwork); if (dc.getNetworkType() == NetworkType.Basic || dc.isSecurityGroupEnabled()) { defaultOffering = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemGuestNetwork); } List<NetworkOfferingVO> offerings = _networkMgr.getSystemAccountNetworkOfferings( NetworkOfferingVO.SystemControlNetwork, NetworkOfferingVO.SystemManagementNetwork); List<Pair<NetworkVO, NicProfile>> networks = new ArrayList<Pair<NetworkVO, NicProfile>>(offerings.size() + 1); NicProfile defaultNic = new NicProfile(); defaultNic.setDefaultNic(true); defaultNic.setDeviceId(2); try { networks.add( new Pair<NetworkVO, NicProfile>( _networkMgr .setupNetwork(systemAcct, defaultOffering.get(0), plan, null, null, false, false) .get(0), defaultNic)); for (NetworkOfferingVO offering : offerings) { networks.add( new Pair<NetworkVO, NicProfile>( _networkMgr .setupNetwork(systemAcct, offering, plan, null, null, false, false) .get(0), null)); } } catch (ConcurrentOperationException e) { s_logger.info("Unable to setup due to concurrent operation. " + e); return new HashMap<String, Object>(); } VMTemplateVO template = _templateDao.findSystemVMTemplate(dataCenterId); if (template == null) { s_logger.debug("Can't find a template to start"); throw new CloudRuntimeException("Insufficient capacity exception"); } SecondaryStorageVmVO secStorageVm = new SecondaryStorageVmVO( id, _serviceOffering.getId(), name, template.getId(), template.getHypervisorType(), template.getGuestOSId(), dataCenterId, systemAcct.getDomainId(), systemAcct.getId(), role, _serviceOffering.getOfferHA()); try { secStorageVm = _itMgr.allocate( secStorageVm, template, _serviceOffering, networks, plan, null, systemAcct); } catch (InsufficientCapacityException e) { s_logger.warn("InsufficientCapacity", e); throw new CloudRuntimeException("Insufficient capacity exception", e); } Map<String, Object> context = new HashMap<String, Object>(); context.put("secStorageVmId", secStorageVm.getId()); return context; }