@Override public State getState() { return _addr.getState(); }
@Override public boolean readyToUse() { return _addr.getAllocatedTime() != null && _addr.getState() == State.Allocated; }
/** * Validates the locked IP, throwing an exeption if the locked IP is null or the locked IP is not in 'Free' state. */ protected void validateLockedRequestedIp(IPAddressVO ipVO, IPAddressVO lockedIpVO) { if (lockedIpVO == null) { throw new InvalidParameterValueException(String.format("Cannot acquire guest [IPv4 address='%s'] as it was removed while acquiring lock", ipVO.getAddress())); } if (lockedIpVO.getState() != IPAddressVO.State.Free) { throw new InvalidParameterValueException( String.format("Cannot acquire guest [IPv4 address='%s']; The Ip address is in [state='%s']", ipVO.getAddress(), lockedIpVO.getState().toString())); } }
public void createFloatingIp(IPAddressVO dbIp, StringBuffer syncLogMesg) throws Exception { if (dbIp.getState() == IpAddress.State.Releasing) { /* Don't need to push releasing ip */ syncLogMesg.append("fip# DB: " + dbIp.getUuid() + ", state releasing, don't create in vnc\n"); return; } syncLogMesg.append("fip# DB: " + dbIp.getAddress().addr() + "; VNC: none; action: create\n"); if (!_manager.createFloatingIp(PublicIp.createFromAddrAndVlan(dbIp, _vlanDao.findById(dbIp.getVlanId())))) { syncLogMesg.append("fip# VNC: " + dbIp.getAddress().addr() + " unable to create\n"); return; } syncLogMesg.append("fip# VNC: " + dbIp.getUuid() + " created\n"); }
if (ip.getState() != State.Releasing) { return Transaction.execute(new TransactionCallback<IPAddressVO>() { @Override
@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; }
if (ip.getState() == IpAddress.State.Releasing) { _ipAddressDao.unassignIpAddress(ip.getId());
if (vpcIsStaticNatProvider || !ip.isOneToOneNat()) { final PublicIp publicIp = PublicIp.createFromAddrAndVlan(ip, _vlanDao.findById(ip.getVlanId())); if ((ip.getState() == IpAddress.State.Allocated || ip.getState() == IpAddress.State.Allocating) && vpcMgr.isIpAllocatedToVpc(ip) && !publicVlans.contains(publicIp.getVlanTag())) {
if (possibleAddr.getState() != IpAddress.State.Free) { continue; if (userIp.getState() == IpAddress.State.Free) { addr.setState(IpAddress.State.Allocating); if (_ipAddressDao.update(addr.getId(), addr)) { if (finalAddr.getState() != expectedAddressState) { s_logger.error("Failed to fetch new public IP and get in expected state=" + expectedAddressState); throw new CloudRuntimeException("Failed to fetch new public IP with expected state " + expectedAddressState);
boolean isSourceNatAllocated = false; for (IPAddressVO addr : ips) { if (addr.getState() != State.Allocated) { if (!isSourceNatAllocated && allocateSourceNat) { addr.setSourceNat(true);
State ipState = ip.getState(); if (ipState != State.Free) { throw new InsufficientAddressCapacityException(String.format("Requested ip address [%s] is not free [ip state=%]", requestedIpv6, ipState), DataCenter.class,
@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()); } } });
public VspStaticNat buildVspStaticNat(Boolean forRevoke, IPAddressVO staticNatIp, VlanVO staticNatVlan, VspNic vspNic) { VspStaticNat.Builder vspStaticNatBuilder = new VspStaticNat.Builder() .ipUuid(staticNatIp.getUuid()) .ipAddress(staticNatIp.getAddress().addr()) .revoke(forRevoke) .oneToOneNat(staticNatIp.isOneToOneNat()) .state(getEnumValue(staticNatIp.getState(), VspStaticNat.State.class)) .vlanUuid(staticNatVlan.getUuid()) .vlanGateway(staticNatVlan.getVlanGateway()) .vlanNetmask(staticNatVlan.getVlanNetmask()) .vlanUnderlay(NuageVspUtil.isUnderlayEnabledForVlan(_vlanDetailsDao, staticNatVlan)); if (staticNatIp.getVmIp() != null) { vspStaticNatBuilder.destinationIp(staticNatIp.getVmIp() + "/32"); } if (vspNic != null) { vspStaticNatBuilder.nic(vspNic); } return vspStaticNatBuilder.build(); }
sb.and("isStaticNat", sb.entity().isOneToOneNat(), SearchCriteria.Op.EQ); sb.and("vpcId", sb.entity().getVpcId(), SearchCriteria.Op.EQ); sb.and("state", sb.entity().getState(), SearchCriteria.Op.EQ); sb.and("display", sb.entity().isDisplay(), SearchCriteria.Op.EQ);
AllIpCountForDashboard.select(null, Func.COUNT, AllIpCountForDashboard.entity().getAddress()); AllIpCountForDashboard.and("dc", AllIpCountForDashboard.entity().getDataCenterId(), Op.EQ); AllIpCountForDashboard.and("state", AllIpCountForDashboard.entity().getState(), SearchCriteria.Op.NEQ); CountFreePublicIps.and("state", CountFreePublicIps.entity().getState(), SearchCriteria.Op.EQ); CountFreePublicIps.and("networkId", CountFreePublicIps.entity().getSourceNetworkId(), SearchCriteria.Op.EQ); SearchBuilder<VlanVO> join = _vlanDao.createSearchBuilder();