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 doInTransactionWithoutResult(final TransactionStatus status) { final IPAddressVO ip = _ipAddressDao.findById(ipId); // update ip address with networkId ip.setVpcId(vpcId); ip.setSourceNat(isSourceNatFinal); _ipAddressDao.update(ipId, ip); // mark ip as allocated _ipAddrMgr.markPublicIpAsAllocated(ip); } });
@Override public void doInTransactionWithoutResult(TransactionStatus status) { if (dstNetwork.getVpcId() != null) { ip.setVpcId(dstNetwork.getVpcId()); } else { ip.setVpcId(null); } _ipAddressDao.update(ipAddrId, ip); }
@Override public void doInTransactionWithoutResult(TransactionStatus status) { List<IPAddressVO> ips = _ipAddressDao.listByAssociatedNetwork(network.getId(),true); //removing static nat configured on ips. for (IPAddressVO ip : ips) { ip.setSourceNat(false); _ipAddressDao.update(ip.getId(),ip); } } });
@Override public void doInTransactionWithoutResult(TransactionStatus status) { List<IPAddressVO> ips = _ipAddressDao.listStaticNatPublicIps(network.getId()); for (IPAddressVO ip : ips) { ip.setOneToOneNat(false); ip.setAssociatedWithVmId(null); ip.setVmIp(null); _ipAddressDao.update(ip.getId(),ip); } } });
@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; } });
_ipAddressDao.update(ipToRelease.getId(), ipToRelease); s_logger.debug("Portable IP address " + ipToRelease + " is no longer associated with any network");
_ipAddressDao.update(ipAddress.getId(), ipAddress); ipAddress = _ipAddressDao.findById(ipId); ipAddress.setSystem(false); _ipAddressDao.update(ipAddress.getId(), ipAddress); _vpcMgr.unassignIPFromVpcNetwork(ipAddress.getId(), networkId); ipAddress = _ipAddressDao.findById(ipId); ipAddress.setRuleState(null); _ipAddressDao.update(ipAddress.getId(), ipAddress); return false;
_ipAddressDao.update(ipToRelease.getId(), ipToRelease); s_logger.debug("Portable IP address " + ipToRelease + " is no longer associated with any VPC"); } else {
/** * Acquires lock in "user_ip_address" and checks if the requested IPv4 address is Free. */ protected void acquireLockAndCheckIfIpv4IsFree(Network network, String requestedIpv4Address) { IPAddressVO ipVO = _ipAddressDao.findByIpAndSourceNetworkId(network.getId(), requestedIpv4Address); if (ipVO == null) { throw new InvalidParameterValueException( String.format("Cannot find IPAddressVO for guest [IPv4 address='%s'] and [network id='%s']", requestedIpv4Address, network.getId())); } try { IPAddressVO lockedIpVO = _ipAddressDao.acquireInLockTable(ipVO.getId()); validateLockedRequestedIp(ipVO, lockedIpVO); lockedIpVO.setState(IPAddressVO.State.Allocated); _ipAddressDao.update(lockedIpVO.getId(), lockedIpVO); } finally { _ipAddressDao.releaseFromLockTable(ipVO.getId()); } }
if (userIp.getState() == IpAddress.State.Free) { addr.setState(IpAddress.State.Allocating); if (_ipAddressDao.update(addr.getId(), addr)) { finalAddr = addr; break;
ip.setVpcId(network.getVpcId()); _ipAddressDao.acquireInLockTable(ip.getId()); _ipAddressDao.update(ip.getId(), ip); _ipAddressDao.releaseFromLockTable(ip.getId()); } catch (Exception e) {
@Override @ActionEvent(eventType = EventTypes.EVENT_NET_IP_UPDATE, eventDescription = "updating public ip address", async = true) public IpAddress updateIP(Long id, String customId, Boolean displayIp) { Account caller = CallContext.current().getCallingAccount(); IPAddressVO ipVO = _ipAddressDao.findById(id); if (ipVO == null) { throw new InvalidParameterValueException("Unable to find ip address by id"); } // verify permissions if (ipVO.getAllocatedToAccountId() != null) { _accountMgr.checkAccess(caller, null, true, ipVO); } else if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN) { throw new PermissionDeniedException("Only Root admin can update non-allocated ip addresses"); } if (customId != null) { ipVO.setUuid(customId); } if (displayIp != null) { ipVO.setDisplay(displayIp); } _ipAddressDao.update(id, ipVO); return _ipAddressDao.findById(id); }
@Override public void doInTransactionWithoutResult(TransactionStatus status) { Account owner = _accountMgr.getAccount(addr.getAllocatedToAccountId()); if (_ipAddressDao.lockRow(addr.getId(), true) != null) { final IPAddressVO userIp = _ipAddressDao.findById(addr.getId()); if (userIp.getState() == IpAddress.State.Allocating || addr.getState() == IpAddress.State.Free) { addr.setState(IpAddress.State.Allocated); if (_ipAddressDao.update(addr.getId(), addr)) { // Save usage event if (owner.getAccountId() != Account.ACCOUNT_ID_SYSTEM) { VlanVO vlan = _vlanDao.findById(addr.getVlanId()); String guestType = vlan.getVlanType().toString(); if (!isIpDedicated(addr)) { UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NET_IP_ASSIGN, owner.getId(), addr.getDataCenterId(), addr.getId(), addr.getAddress().toString(), addr.isSourceNat(), guestType, addr.getSystem(), addr.getClass().getName(), addr.getUuid()); } if (updateIpResourceCount(addr)) { _resourceLimitMgr.incrementResourceCount(owner.getId(), ResourceType.public_ip); } } } else { s_logger.error("Failed to mark public IP as allocated with id=" + addr.getId() + " address=" + addr.getAddress()); } } } else { s_logger.error("Failed to acquire row lock to mark public IP as allocated with id=" + addr.getId() + " address=" + addr.getAddress()); } } });
_ipAddressDao.update(ipId, ip);
@Override public void doInTransactionWithoutResult(TransactionStatus status) { long physicalNetworkId = _networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(dstNetwork.getDataCenterId(), TrafficType.Public).getId(); long publicNetworkId = _networkModel.getSystemNetworkByZoneAndTrafficType(dstNetwork.getDataCenterId(), TrafficType.Public).getId(); ip.setDataCenterId(dstNetwork.getDataCenterId()); ip.setPhysicalNetworkId(physicalNetworkId); ip.setSourceNetworkId(publicNetworkId); _ipAddressDao.update(ipAddrId, ip); VlanVO vlan = _vlanDao.findById(ip.getVlanId()); vlan.setPhysicalNetworkId(physicalNetworkId); vlan.setNetworkId(publicNetworkId); vlan.setDataCenterId(dstNetwork.getDataCenterId()); _vlanDao.update(ip.getVlanId(), vlan); } });
_ipAddressDao.update(ipId, ip);
String maskedVmIp = NetUtils.long2Ip(newCidrAddress | ipMask); ip.setVmIp(maskedVmIp); _ipAddressDao.update(ip.getId(), ip);