@Override public String getIpOfNetworkElementInVirtualNetwork(long accountId, long dataCenterId) { List<NetworkVO> virtualNetworks = _networksDao.listByZoneAndGuestType(accountId, dataCenterId, GuestType.Isolated, false); if (virtualNetworks.isEmpty()) { s_logger.trace("Unable to find default Virtual network account id=" + accountId); return null; } NetworkVO virtualNetwork = virtualNetworks.get(0); NicVO networkElementNic = _nicDao.findByNetworkIdAndType(virtualNetwork.getId(), Type.DomainRouter); if (networkElementNic != null) { return networkElementNic.getIPv4Address(); } else { s_logger.warn("Unable to set find network element for the network id=" + virtualNetwork.getId()); return null; } }
private void assignRouterNicsToNewNetwork(long srcNetworkId, long dstNetworkId) { final List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(srcNetworkId, VirtualRouter.Role.VIRTUAL_ROUTER); for (DomainRouterVO domainRouter : routers) { NicVO vrNic = _nicDao.findByNetworkIdAndType(srcNetworkId, VirtualMachine.Type.DomainRouter); vrNic.setNetworkId(dstNetworkId); _nicDao.update(vrNic.getId(), vrNic); RouterNetworkVO routerNetwork = _routerNetworkDao.findByRouterAndNetwork(domainRouter.getId(), srcNetworkId); routerNetwork.setNetworkId(dstNetworkId); _routerNetworkDao.persist(routerNetwork); } }
@Override public void deleteCopyOfNetwork(long networkCopyId, long originalNetworkId) { NetworkVO networkCopy = _networksDao.findById(networkCopyId); NicVO userNic = _nicDao.findByNetworkIdAndType(networkCopyId, VirtualMachine.Type.User); if (userNic != null) { s_logger.error("Something went wrong while migrating nics from the old network to the new network. Failed to delete copy of network. There are still user nics present in the network."); throw new CloudRuntimeException("Failed to delete copy of network. There are still user nics present in the network."); } NetworkVO originalNetwork = _networksDao.findById(originalNetworkId); swapUuids(originalNetwork, networkCopy); try { if (!_networkService.deleteNetwork(networkCopy.getId(), true)) { throw new CloudRuntimeException("Failed to delete network. Clean up not successful."); } } finally { swapUuids(networkCopy, originalNetwork); } originalNetwork.setRelated(originalNetworkId); _networksDao.persist(originalNetwork); }
private NicVO findDefaultDnsIp(final long userVmId) { final NicVO defaultNic = _nicDao.findDefaultNicForVM(userVmId); // check if DNS provider is the domR if (!_networkModel.isProviderSupportServiceInNetwork(defaultNic.getNetworkId(), Service.Dns, Provider.VirtualRouter)) { return null; } final NetworkOffering offering = _networkOfferingDao.findById(_networkDao.findById(defaultNic.getNetworkId()).getNetworkOfferingId()); if (offering.isRedundantRouter()) { return findGatewayIp(userVmId); } final DataCenter dc = _dcDao.findById(_networkModel.getNetwork(defaultNic.getNetworkId()).getDataCenterId()); final boolean isZoneBasic = dc.getNetworkType() == NetworkType.Basic; // find domR's nic in the network NicVO domrDefaultNic; if (isZoneBasic) { domrDefaultNic = _nicDao.findByNetworkIdTypeAndGateway(defaultNic.getNetworkId(), VirtualMachine.Type.DomainRouter, defaultNic.getIPv4Gateway()); } else { domrDefaultNic = _nicDao.findByNetworkIdAndType(defaultNic.getNetworkId(), VirtualMachine.Type.DomainRouter); } return domrDefaultNic; }