public NicResponse createNicResponse(Nic result) { NicResponse response = new NicResponse(); NetworkVO network = _entityMgr.findById(NetworkVO.class, result.getNetworkId()); VMInstanceVO vm = _entityMgr.findById(VMInstanceVO.class, result.getInstanceId()); UserVmJoinVO userVm = _entityMgr.findById(UserVmJoinVO.class, result.getInstanceId()); List<NicExtraDhcpOptionVO> nicExtraDhcpOptionVOs = _nicExtraDhcpOptionDao.listByNicId(result.getId()); response.setId(result.getUuid()); response.setIpaddress(result.getIPv4Address()); response.setGateway(result.getIPv4Gateway()); response.setNetmask(result.getIPv4Netmask()); response.setMacAddress(result.getMacAddress()); if (result.getIPv6Address() != null) { response.setIp6Address(result.getIPv6Address()); if (result.getIPv6Gateway() != null) { response.setIp6Gateway(result.getIPv6Gateway()); if (result.getIPv6Cidr() != null) { response.setIp6Cidr(result.getIPv6Cidr()); response.setDeviceId(String.valueOf(result.getDeviceId())); if (result.getBroadcastUri() != null) {
public NicProfile(Nic nic, Network network, URI broadcastUri, URI isolationUri, Integer networkRate, boolean isSecurityGroupEnabled, String name) { id = nic.getId(); networkId = network.getId(); mode = network.getMode(); broadcastType = network.getBroadcastDomainType(); trafficType = network.getTrafficType(); format = nic.getAddressFormat(); iPv4Address = nic.getIPv4Address(); iPv4Netmask = nic.getIPv4Netmask(); iPv4Gateway = nic.getIPv4Gateway(); iPv6Address = nic.getIPv6Address(); iPv6Gateway = nic.getIPv6Gateway(); iPv6Cidr = nic.getIPv6Cidr(); macAddress = nic.getMacAddress(); reservationId = nic.getReservationId(); strategy = nic.getReservationStrategy(); deviceId = nic.getDeviceId(); defaultNic = nic.isDefaultNic(); this.broadcastUri = broadcastUri; this.isolationUri = isolationUri; this.isSecurityGroupEnabled = isSecurityGroupEnabled; vmId = nic.getInstanceId(); this.name = name; uuid = nic.getUuid(); if (networkRate != null) { this.networkRate = networkRate; } }
private boolean getDefaultHasDns(Map<Long, Boolean> cache, Nic nic) { Long networkId = nic.isDefaultNic() ? Long.valueOf(nic.getNetworkId()) : getDefaultNetwork(nic.getInstanceId()); Boolean hasDns = cache.computeIfAbsent(networkId, k -> networkHasDns(_networkDao.findById(networkId))); return hasDns; }
@Override public void doInTransactionWithoutResult(TransactionStatus status) { for (Nic nic : nics) { if (nic.getIPv4Address() != null) { s_logger.debug("Releasing ip " + nic.getIPv4Address() + " of placeholder nic " + nic); IPAddressVO ip = _ipAddressDao.findByIpAndSourceNetworkId(nic.getNetworkId(), nic.getIPv4Address()); if (ip != null) { _ipAddrMgr.markIpAsUnavailable(ip.getId()); _ipAddressDao.unassignIpAddress(ip.getId()); s_logger.debug("Removing placeholder nic " + nic); _nicDao.remove(nic.getId()); } } } } });
if (nic.isDefaultNic() && vm.getType() == VirtualMachine.Type.User) { s_logger.warn("Failed to remove nic from " + vm + " in " + network + ", nic is default."); throw new CloudRuntimeException("Failed to remove nic from " + vm + " in " + network + ", nic is default."); final Nic lock = _nicsDao.acquireInLockTable(nic.getId()); if (lock == null) { if (_nicsDao.findById(nic.getId()) == null) { if (s_logger.isDebugEnabled()) { s_logger.debug("Not need to remove the vm " + vm + " from network " + network + " as the vm doesn't have nic in this network"); throw new ConcurrentOperationException("Unable to lock nic " + nic.getId()); s_logger.debug("Lock is acquired for nic id " + lock.getId() + " as a part of remove vm " + vm + " from network " + network); new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), _networkModel.getNetworkRate(network.getId(), vm.getId()), _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vmProfile.getVirtualMachine().getHypervisorType(), network)); } finally { if (lock != null) { _nicsDao.releaseFromLockTable(lock.getId()); if (s_logger.isDebugEnabled()) { s_logger.debug("Lock is released for nic id " + lock.getId() + " as a part of remove vm " + vm + " from network " + network);
@Override public Network getDefaultNetworkForVm(long vmId) { Nic defaultNic = getDefaultNic(vmId); if (defaultNic == null) { return null; } else { return _networksDao.findById(defaultNic.getNetworkId()); } }
@Override public void finalizeStop(final VirtualMachineProfile profile, final Answer answer) { if (answer != null) { final VirtualMachine vm = profile.getVirtualMachine(); final DomainRouterVO domR = _routerDao.findById(vm.getId()); processStopOrRebootAnswer(domR, answer); final List<? extends Nic> routerNics = _nicDao.listByVmId(profile.getId()); for (final Nic nic : routerNics) { final Network network = _networkModel.getNetwork(nic.getNetworkId()); final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId()); if (network.getTrafficType() == TrafficType.Guest && nic.getBroadcastUri() != null && nic.getBroadcastUri().getScheme().equals("pvlan")) { final NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), 0, false, "pvlan-nic"); final NetworkTopology networkTopology = _networkTopologyContext.retrieveNetworkTopology(dcVO); try { networkTopology.setupDhcpForPvlan(false, domR, domR.getHostId(), nicProfile); } catch (final ResourceUnavailableException e) { s_logger.debug("ERROR in finalizeStop: ", e); } } } } }
@Override public List<FirewallRuleVO> listAssociatedRulesForGuestNic(Nic nic) { s_logger.debug("Checking if PF/StaticNat/LoadBalancer rules are configured for nic " + nic.getId()); List<FirewallRuleVO> result = new ArrayList<FirewallRuleVO>(); result.addAll(_portForwardingDao.listByNetworkAndDestIpAddr(nic.getIPv4Address(), nic.getNetworkId())); if(result.size() > 0) { s_logger.debug("Found " + result.size() + " portforwarding rule configured for the nic in the network " + nic.getNetworkId()); List<FirewallRuleVO> staticNatRules = _firewallDao.listStaticNatByVmId(nic.getInstanceId()); for (FirewallRuleVO rule : staticNatRules) { if (rule.getNetworkId() == nic.getNetworkId()) { result.add(rule); s_logger.debug("Found rule " + rule.getId() + " " + rule.getPurpose() + " configured"); List<? extends IpAddress> staticNatIps = _ipAddressDao.listStaticNatPublicIps(nic.getNetworkId()); for (IpAddress ip : staticNatIps) { if (ip.getVmIp() != null && ip.getVmIp().equals(nic.getIPv4Address())) { VMInstanceVO vm = _vmInstanceDao.findById(nic.getInstanceId()); new FirewallRuleVO(null, ip.getId(), 0, 65535, NetUtils.ALL_PROTO.toString(), nic.getNetworkId(), vm.getAccountId(), vm.getDomainId(), Purpose.StaticNat, null, null, null, null, null); result.add(staticNatRule); List<LoadBalancerVMMapVO> lbMapList = _loadBalancerVMMapDao.listByInstanceId(nic.getInstanceId()); for (LoadBalancerVMMapVO lb : lbMapList) { FirewallRuleVO lbRule = _firewallDao.findById(lb.getLoadBalancerId()); if (lbRule.getNetworkId() == nic.getNetworkId()) { result.add(lbRule); s_logger.debug("Found rule " + lbRule.getId() + " " + lbRule.getPurpose() + " configured");
final Network network = _networkModel.getNetwork(routerNic.getNetworkId()); if (network.getTrafficType() == TrafficType.Guest) { final Pair<Nic, Network> guestNic = new Pair<Nic, Network>(routerNic, network); final Pair<Nic, Network> publicNic = new Pair<Nic, Network>(routerNic, network); publicNics.add(publicNic); final String vlanTag = BroadcastDomainType.getValue(routerNic.getBroadcastUri()); vlanMacAddress.put(vlanTag, routerNic.getMacAddress()); final Nic publicNic = nicNtwk.first(); final Network publicNtwk = nicNtwk.second(); final IPAddressVO userIp = _ipAddressDao.findByIpAndSourceNetworkId(publicNtwk.getId(), publicNic.getIPv4Address()); routerVO.setPublicIpAddress(publicNic.getIPv4Address()); routerVO.setPublicNetmask(publicNic.getIPv4Netmask()); routerVO.setPublicMacAddress(publicNic.getMacAddress()); _routerDao.update(routerVO.getId(), routerVO); final PlugNicCommand plugNicCmd = new PlugNicCommand(_nwHelper.getNicTO(domainRouterVO, publicNic.getNetworkId(), publicNic.getBroadcastUri().toString()), domainRouterVO.getInstanceName(), domainRouterVO.getType(), details); cmds.addCommand(plugNicCmd); final VpcVO vpc = _vpcDao.findById(domainRouterVO.getVpcId()); final NetworkUsageCommand netUsageCmd = new NetworkUsageCommand(domainRouterVO.getPrivateIpAddress(), domainRouterVO.getInstanceName(), true, publicNic.getIPv4Address(), vpc.getCidr()); usageCmds.add(netUsageCmd); UserStatisticsVO stats = _userStatsDao.findBy(domainRouterVO.getAccountId(), domainRouterVO.getDataCenterId(), publicNtwk.getId(), publicNic.getIPv4Address(), domainRouterVO.getId(), domainRouterVO.getType().toString()); if (stats == null) { stats = new UserStatisticsVO(domainRouterVO.getAccountId(), domainRouterVO.getDataCenterId(), publicNic.getIPv4Address(), domainRouterVO.getId(), domainRouterVO.getType().toString(), publicNtwk.getId());
if (nic.getIPv4Address() == null) { continue; List<VirtualRouter> routers = _vnaMgr.getRoutersForNetwork(nic.getNetworkId()); if (routers == null || routers.isEmpty()) { if (s_logger.isDebugEnabled()) { s_logger.debug("Unable to find a router in network " + nic.getNetworkId() + " to ping " + vm);
mapping = new InlineLoadBalancerNicMapVO(srcIp, loadBalancingIpNic.getId()); _inlineLoadBalancerNicMapDao.persist(mapping); applyStaticNatRuleForInlineLBRule(zone, network, revoked, srcIp, loadBalancingIpNic.getIPv4Address()); } catch (ResourceUnavailableException ex) { _nicDao.expunge(loadBalancingIpNic.getId()); throw ex; applyStaticNatRuleForInlineLBRule(zone, network, revoked, srcIp, loadBalancingIpNic.getIPv4Address()); _nicDao.expunge(loadBalancingIpNic.getId());
@Override public String getIpInNetworkIncludingRemoved(long vmId, long networkId) { Nic guestNic = getNicInNetworkIncludingRemoved(vmId, networkId); assert (guestNic != null && guestNic.getIPv4Address() != null) : "Vm doesn't belong to network associated with " + "ipAddress or ip4 address is null"; return guestNic.getIPv4Address(); }
List<OvsVpcPhysicalTopologyConfigCommand.Nic> vmNics = new ArrayList<OvsVpcPhysicalTopologyConfigCommand.Nic>(); for (Nic vmNic :_nicDao.listByVmId(vmId)) { Network network = _networkDao.findById(vmNic.getNetworkId()); if (network.getTrafficType() == TrafficType.Guest) { OvsVpcPhysicalTopologyConfigCommand.Nic nic = new OvsVpcPhysicalTopologyConfigCommand.Nic( vmNic.getIPv4Address(), vmNic.getMacAddress(), network.getUuid()); vmNics.add(nic);
protected boolean applyUserData(HypervisorType hyperVisorType, UserVm vm, Nic nic) throws ResourceUnavailableException, InsufficientCapacityException { Network network = _networkDao.findById(nic.getNetworkId()); NicProfile nicProfile = new NicProfile(nic, network, null, null, null, _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag( hyperVisorType, network)); VirtualMachineProfile vmProfile = new VirtualMachineProfileImpl(vm); if (_networkModel.areServicesSupportedByNetworkOffering(network.getNetworkOfferingId(), Service.UserData)) { UserDataServiceProvider element = _networkModel.getUserDataUpdateProvider(network); if (element == null) { throw new CloudRuntimeException("Can't find network element for " + Service.UserData.getName() + " provider needed for UserData update"); } boolean result = element.saveUserData(network, nicProfile, vmProfile); if (!result) { s_logger.error("Failed to update userdata for vm " + vm + " and nic " + nic); } else { return true; } } else { s_logger.debug("Not applying userdata for nic id=" + nic.getId() + " in vm id=" + vmProfile.getId() + " because it is not supported in network id=" + network.getId()); } return false; }
final Nic guestNic = _nicDao.findByNtwkIdAndInstanceId(guestNetwork.getId(), internalLbVm.getId()); final NicProfile guestNicProfile = new NicProfile(guestNic, guestNetwork, guestNic.getBroadcastUri(), guestNic.getIsolationUri(), _ntwkModel.getNetworkRate(guestNetwork.getId(), internalLbVm.getId()), _ntwkModel.isSecurityGroupSupportedInNetwork(guestNetwork), _ntwkModel.getNetworkTag(internalLbVm.getHypervisorType(), guestNetwork)); new LoadBalancerConfigCommand(lbs, guestNic.getIPv4Address(), guestNic.getIPv4Address(), internalLbVm.getPrivateIpAddress(), _itMgr.toNicTO(guestNicProfile, internalLbVm.getHypervisorType()), internalLbVm.getVpcId(), maxconn, offering.isKeepAliveEnabled()); cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, guestNic.getIPv4Address()); cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, internalLbVm.getInstanceName()); final DataCenterVO dcVo = _dcDao.findById(internalLbVm.getDataCenterId());
if (vm.getType() == Type.User) { final Nic nic = _nicDao.findByNtwkIdAndInstanceId(networkId, vmId); if (nic != null && nic.isDefaultNic()) { return _configMgr.getServiceOfferingNetworkRate(vm.getServiceOfferingId(), network.getDataCenterId()); final NetworkVO nw = _networksDao.findById(nic.getNetworkId()); if (nw.getTrafficType() == TrafficType.Guest) { return _configMgr.getNetworkOfferingNetworkRate(nw.getNetworkOfferingId(), network.getDataCenterId());
userVm.setDetails(details); Network network = _networkModel.getNetwork(defaultNic.getNetworkId()); if (_networkModel.isSharedNetworkWithoutServices(network.getId())) { final String serviceOffering = _serviceOfferingDao.findByIdIncludingRemoved(vm.getId(), vm.getServiceOfferingId()).getDisplayText(); vm.getUuid(), defaultNic.getMacAddress(), userVm.getDetail("SSH.PublicKey"), (String) profile.getParameter(VirtualMachineProfile.Param.VmPassword), isWindows); String vmName = vm.getInstanceName(); String configDriveIsoRootFolder = "/tmp";
@DB @Override public void removeDhcpServiceInSubnet(final Nic nic) { final Network network = _networksDao.findById(nic.getNetworkId()); final DhcpServiceProvider dhcpServiceProvider = getDhcpServiceProvider(network); try { final NicIpAliasVO ipAlias = _nicIpAliasDao.findByGatewayAndNetworkIdAndState(nic.getIPv4Gateway(), network.getId(), NicIpAlias.State.active); if (ipAlias != null) { ipAlias.setState(NicIpAlias.State.revoked); Transaction.execute(new TransactionCallbackNoReturn() { @Override public void doInTransactionWithoutResult(final TransactionStatus status) { _nicIpAliasDao.update(ipAlias.getId(), ipAlias); final IPAddressVO aliasIpaddressVo = _publicIpAddressDao.findByIpAndSourceNetworkId(ipAlias.getNetworkId(), ipAlias.getIp4Address()); _publicIpAddressDao.unassignIpAddress(aliasIpaddressVo.getId()); } }); if (!dhcpServiceProvider.removeDhcpSupportForSubnet(network)) { s_logger.warn("Failed to remove the ip alias on the router, marking it as removed in db and freed the allocated ip " + ipAlias.getIp4Address()); } } } catch (final ResourceUnavailableException e) { //failed to remove the dhcpconfig on the router. s_logger.info("Unable to delete the ip alias due to unable to contact the virtualrouter."); } }
private void updateExtraDhcpOptionsForExistingVm(Network network, Nic nic) { _networkOrchestrationService.configureExtraDhcpOptions(network, nic.getId()); }
new NicProfile(privateNic, privateNetwork, privateNic.getBroadcastUri(), privateNic.getIsolationUri(), _networkModel.getNetworkRate( privateNetwork.getId(), router.getId()), _networkModel.isSecurityGroupSupportedInNetwork(privateNetwork), _networkModel.getNetworkTag( router.getHypervisorType(), privateNetwork));