private void releaseIp(final long ipId, final long userId, final Account caller) { s_logger.info("ELB: Release public IP for loadbalancing " + ipId); final IPAddressVO ipvo = _ipAddressDao.findById(ipId); ipvo.setAssociatedWithNetworkId(null); _ipAddressDao.update(ipvo.getId(), ipvo); _ipAddrMgr.disassociatePublicIpAddress(ipId, userId, caller); _ipAddressDao.unassignIpAddress(ipId); }
@Override public void unassignIPFromVpcNetwork(final long ipId, final long networkId) { final IPAddressVO ip = _ipAddressDao.findById(ipId); if (isIpAllocatedToVpc(ip)) { return; } if (ip == null || ip.getVpcId() == null) { return; } s_logger.debug("Releasing VPC ip address " + ip + " from vpc network id=" + networkId); final long vpcId = ip.getVpcId(); boolean success = false; try { // unassign ip from the VPC router success = _ipAddrMgr.applyIpAssociations(_ntwkModel.getNetwork(networkId), true); } catch (final ResourceUnavailableException ex) { throw new CloudRuntimeException("Failed to apply ip associations for network id=" + networkId + " as a part of unassigning ip " + ipId + " from vpc", ex); } if (success) { ip.setAssociatedWithNetworkId(null); _ipAddressDao.update(ipId, ip); s_logger.debug("IP address " + ip + " is no longer associated with the network inside vpc id=" + vpcId); } else { throw new CloudRuntimeException("Failed to apply ip associations for network id=" + networkId + " as a part of unassigning ip " + ipId + " from vpc"); } s_logger.debug("Successfully released VPC ip address " + ip + " back to VPC pool "); }
@Override public PublicIp doInTransaction(final TransactionStatus status) throws InsufficientAddressCapacityException { final Network frontEndNetwork = _networkModel.getNetwork(guestNetworkId); final PublicIp ip = _ipAddrMgr.assignPublicIpAddress(frontEndNetwork.getDataCenterId(), null, account, VlanType.DirectAttached, frontEndNetwork.getId(), null, true, false); final IPAddressVO ipvo = _ipAddressDao.findById(ip.getId()); ipvo.setAssociatedWithNetworkId(frontEndNetwork.getId()); _ipAddressDao.update(ipvo.getId(), ipvo); s_logger.info("Acquired frontend IP for ELB " + ip); return ip; } });
ipToRelease.setAssociatedWithNetworkId(null); _ipAddressDao.update(ipToRelease.getId(), ipToRelease); s_logger.debug("Portable IP address " + ipToRelease + " is no longer associated with any network");
ipToRelease.setAssociatedWithNetworkId(null); _ipAddressDao.update(ipToRelease.getId(), ipToRelease); s_logger.debug("Portable IP address " + ipToRelease + " is no longer associated with any VPC");
private void reapplyPublicIps(Network networkInOldPhysicalNetwork, Network networkInNewPhysicalNet) { CallContext ctx = CallContext.current(); long callerUserId = ctx.getCallingUserId(); Account caller = ctx.getCallingAccount(); AccountVO networkAccount = _accountDao.findById(networkInNewPhysicalNet.getAccountId()); List<? extends IPAddressVO> staticNatIps = _ipAddressDao.listStaticNatPublicIps(networkInOldPhysicalNetwork.getId()); List<String> providers = _networkOfferingServiceDao.listProvidersForServiceForNetworkOffering(networkInNewPhysicalNet.getNetworkOfferingId(), Network.Service.SourceNat); boolean isSrcNatIpNeeded = providers.stream().anyMatch(provider -> provider.contains(Network.Provider.VirtualRouter.getName())); for (IPAddressVO ipAddress : staticNatIps) { if (!ipAddress.isSourceNat() || isSrcNatIpNeeded) { ipAddress.setAssociatedWithNetworkId(networkInNewPhysicalNet.getId()); _ipAddressDao.persist(ipAddress); } else { _ipAddressManager.disassociatePublicIpAddress(ipAddress.getId(), callerUserId, caller); } } _rulesMgr.applyStaticNatsForNetwork(networkInNewPhysicalNet.getId(), false, networkAccount); }
addr.setSourceNat(false); addr.setAssociatedWithNetworkId(guestNetwork.getId()); addr.setVpcId(guestNetwork.getVpcId()); addr.setAllocatedTime(new Date());
addr.setAssociatedWithNetworkId(guestNetworkId); addr.setVpcId(vpcId);
@Override public boolean applyIpAssociations(Network network, boolean continueOnError) throws ResourceUnavailableException { List<IPAddressVO> userIps = _ipAddressDao.listByAssociatedNetwork(network.getId(), null); boolean success = true; // CloudStack will take a lazy approach to associate an acquired public IP to a network service provider as // it will not know what service an acquired IP will be used for. An IP is actually associated with a provider when first // rule is applied. Similarly when last rule on the acquired IP is revoked, IP is not associated with any provider // but still be associated with the account. At this point just mark IP as allocated or released. for (IPAddressVO addr : userIps) { if (addr.getState() == IpAddress.State.Allocating) { addr.setAssociatedWithNetworkId(network.getId()); markPublicIpAsAllocated(addr); } else if (addr.getState() == IpAddress.State.Releasing) { // Cleanup all the resources for ip address if there are any, and only then un-assign ip in the system if (cleanupIpResources(addr.getId(), Account.ACCOUNT_ID_SYSTEM, _accountMgr.getSystemAccount())) { _ipAddressDao.unassignIpAddress(addr.getId()); } else { success = false; s_logger.warn("Failed to release resources for ip address id=" + addr.getId()); } } } return success; }
/** * reassigns the nics to the new network from the src network. * @param srcNetworkId * @param dstNetworkId */ private void assignUserNicsToNewNetwork(long srcNetworkId, long dstNetworkId) { List<NicVO> nics = _nicDao.listByNetworkId(srcNetworkId); for (NicVO nic : nics) { if (nic.getVmType() == VirtualMachine.Type.User) { nic.setNetworkId(dstNetworkId); _nicDao.persist(nic); //update the number of active nics in both networks after migration. if (nic.getState() == Nic.State.Reserved) { _networksDao.changeActiveNicsBy(srcNetworkId, -1); _networksDao.changeActiveNicsBy(dstNetworkId, 1); } } } List<? extends IPAddressVO> publicIps = _ipAddressDao.listByAssociatedNetwork(srcNetworkId, null); for (IPAddressVO ipAddress : publicIps) { ipAddress.setAssociatedWithNetworkId(dstNetworkId); _ipAddressDao.persist(ipAddress); } }
@Override public void unassignIpAddress(long ipAddressId) { IPAddressVO address = createForUpdate(); address.setAllocatedToAccountId(null); address.setAllocatedInDomainId(null); address.setAllocatedTime(null); address.setSourceNat(false); address.setOneToOneNat(false); address.setAssociatedWithVmId(null); address.setState(State.Free); address.setAssociatedWithNetworkId(null); address.setVpcId(null); address.setSystem(false); address.setVmIp(null); address.setDisplay(true); //remove resource details for the ip _detailsDao.removeDetails(ipAddressId); update(ipAddressId, address); }
ip.setAssociatedWithNetworkId(null); _ipAddressDao.update(ipId, ip);
ip.setAssociatedWithNetworkId(networkId); ip.setSourceNat(isSourceNat); _ipAddressDao.update(ipId, ip);