diff --git a/api/src/com/cloud/api/ApiConstants.java b/api/src/com/cloud/api/ApiConstants.java index 3647b76a159..3fc03552318 100755 --- a/api/src/com/cloud/api/ApiConstants.java +++ b/api/src/com/cloud/api/ApiConstants.java @@ -323,6 +323,7 @@ public class ApiConstants { public static final String TRAFFIC_TYPE_IMPLEMENTOR = "traffictypeimplementor"; public static final String KEYWORD = "keyword"; public static final String LIST_ALL = "listall"; + public static final String IS_ELASTIC = "iselastic"; public enum HostDetails { all, capacity, events, stats, min; diff --git a/api/src/com/cloud/api/commands/AssociateIPAddrCmd.java b/api/src/com/cloud/api/commands/AssociateIPAddrCmd.java index 5817fb836af..438488864a1 100644 --- a/api/src/com/cloud/api/commands/AssociateIPAddrCmd.java +++ b/api/src/com/cloud/api/commands/AssociateIPAddrCmd.java @@ -42,7 +42,6 @@ import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.IpAddress; import com.cloud.network.Network; -import com.cloud.network.IpAddress.AllocatedBy; import com.cloud.user.Account; import com.cloud.user.UserContext; @@ -174,7 +173,7 @@ public class AssociateIPAddrCmd extends BaseAsyncCreateCmd { @Override public void create() throws ResourceAllocationException{ try { - IpAddress ip = _networkService.allocateIP(getNetworkId(), _accountService.getAccount(getEntityOwnerId()), AllocatedBy.ipassoc); + IpAddress ip = _networkService.allocateIP(getNetworkId(), _accountService.getAccount(getEntityOwnerId()), false); if (ip != null) { this.setEntityId(ip.getId()); } else { diff --git a/api/src/com/cloud/api/commands/DisableStaticNatCmd.java b/api/src/com/cloud/api/commands/DisableStaticNatCmd.java index d408177dab9..3835001aa98 100644 --- a/api/src/com/cloud/api/commands/DisableStaticNatCmd.java +++ b/api/src/com/cloud/api/commands/DisableStaticNatCmd.java @@ -31,7 +31,6 @@ import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.IpAddress; -import com.cloud.network.IpAddress.AllocatedBy; @Implementation(description="Disables static rule for given ip address", responseObject=SuccessResponse.class) public class DisableStaticNatCmd extends BaseAsyncCmd { diff --git a/api/src/com/cloud/api/response/IPAddressResponse.java b/api/src/com/cloud/api/response/IPAddressResponse.java index 995a8c5307f..40def18c650 100644 --- a/api/src/com/cloud/api/response/IPAddressResponse.java +++ b/api/src/com/cloud/api/response/IPAddressResponse.java @@ -71,6 +71,9 @@ public class IPAddressResponse extends BaseResponse implements ControlledEntityR @SerializedName("isstaticnat") @Param(description="true if this ip is for static nat, false otherwise") private Boolean staticNat; + @SerializedName(ApiConstants.IS_ELASTIC) @Param(description="true if this ip is elastic ip (was allocated as a part of deployVm or createLbRule)") + private Boolean isElastic; + @SerializedName(ApiConstants.VIRTUAL_MACHINE_ID) @Param(description="virutal machine id the ip address is assigned to (not null only for static nat Ip)") private IdentityProxy virtualMachineId = new IdentityProxy("vm_instance"); @@ -206,5 +209,9 @@ public class IPAddressResponse extends BaseResponse implements ControlledEntityR public long getphysicalNetworkId() { return physicalNetworkId.getValue(); - } + } + + public void setIsElastic(Boolean isElastic) { + this.isElastic = isElastic; + } } diff --git a/api/src/com/cloud/network/IpAddress.java b/api/src/com/cloud/network/IpAddress.java index 3a2d4578b15..66837e5bca0 100644 --- a/api/src/com/cloud/network/IpAddress.java +++ b/api/src/com/cloud/network/IpAddress.java @@ -45,11 +45,6 @@ public interface IpAddress extends ControlledEntity{ Free // The IP address is ready to be allocated. } - enum AllocatedBy { - ipassoc, - elasticip - } - long getDataCenterId(); Ip getAddress(); @@ -83,6 +78,6 @@ public interface IpAddress extends ControlledEntity{ Long getAllocatedInDomainId(); - AllocatedBy getAllocatedBy(); + boolean getElastic(); } diff --git a/api/src/com/cloud/network/NetworkService.java b/api/src/com/cloud/network/NetworkService.java index c6a985df650..1f26b358ffa 100755 --- a/api/src/com/cloud/network/NetworkService.java +++ b/api/src/com/cloud/network/NetworkService.java @@ -30,7 +30,6 @@ import com.cloud.exception.InsufficientAddressCapacityException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceUnavailableException; -import com.cloud.network.IpAddress.AllocatedBy; import com.cloud.network.Network.Capability; import com.cloud.network.Network.Provider; import com.cloud.network.Network.Service; @@ -43,7 +42,7 @@ public interface NetworkService { List getIsolatedNetworksOwnedByAccountInZone(long zoneId, Account owner); - IpAddress allocateIP(long networkId, Account ipOwner, AllocatedBy allocatedBy) throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException; + IpAddress allocateIP(long networkId, Account ipOwner, boolean isElastic) throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException; /** * Associates a public IP address for a router. diff --git a/api/src/com/cloud/network/rules/RulesService.java b/api/src/com/cloud/network/rules/RulesService.java index 859f9e8eff4..c41b1e85f15 100644 --- a/api/src/com/cloud/network/rules/RulesService.java +++ b/api/src/com/cloud/network/rules/RulesService.java @@ -22,7 +22,6 @@ import java.util.List; import com.cloud.api.commands.ListPortForwardingRulesCmd; import com.cloud.exception.NetworkRuleConflictException; import com.cloud.exception.ResourceUnavailableException; -import com.cloud.network.IpAddress.AllocatedBy; import com.cloud.user.Account; public interface RulesService { diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index 0c6193d81c7..7f823b4ba8e 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -713,6 +713,7 @@ public class ApiResponseHelper implements ResponseGenerator { ipResponse.setZoneId(zoneId); ipResponse.setZoneName(ApiDBUtils.findZoneById(ipAddress.getDataCenterId()).getName()); ipResponse.setSourceNat(ipAddress.isSourceNat()); + ipResponse.setIsElastic(ipAddress.getElastic()); // get account information populateOwner(ipResponse, ipAddress); diff --git a/server/src/com/cloud/network/ExternalLoadBalancerDeviceManagerImpl.java b/server/src/com/cloud/network/ExternalLoadBalancerDeviceManagerImpl.java index 615e8dc97ef..e092ec5bdf0 100644 --- a/server/src/com/cloud/network/ExternalLoadBalancerDeviceManagerImpl.java +++ b/server/src/com/cloud/network/ExternalLoadBalancerDeviceManagerImpl.java @@ -69,11 +69,9 @@ import com.cloud.host.Host; import com.cloud.host.HostVO; import com.cloud.host.dao.HostDao; import com.cloud.host.dao.HostDetailsDao; -import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.network.ExternalLoadBalancerDeviceVO.LBDeviceAllocationState; import com.cloud.network.ExternalLoadBalancerDeviceVO.LBDeviceState; import com.cloud.network.ExternalNetworkDeviceManager.NetworkDevice; -import com.cloud.network.IpAddress.AllocatedBy; import com.cloud.network.Network.Service; import com.cloud.network.Networks.TrafficType; import com.cloud.network.addr.PublicIp; @@ -106,7 +104,6 @@ import com.cloud.resource.ResourceState; import com.cloud.resource.ResourceStateAdapter; import com.cloud.resource.ServerResource; import com.cloud.resource.UnableDeleteHostException; -import com.cloud.resource.ResourceStateAdapter.DeleteHostAnswer; import com.cloud.server.api.response.ExternalLoadBalancerResponse; import com.cloud.user.Account; import com.cloud.user.AccountManager; @@ -477,7 +474,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase String dedicatedLb = offering.getDedicatedLB()?"true":"false"; //acquire a public IP to associate with lb appliance (used as subnet IP to make the appliance part of private network) - PublicIp publicIp = _networkMgr.assignPublicIpAddress(guestConfig.getDataCenterId(), null, _accountMgr.getSystemAccount(), VlanType.VirtualNetwork, null, null, AllocatedBy.ipassoc); + PublicIp publicIp = _networkMgr.assignPublicIpAddress(guestConfig.getDataCenterId(), null, _accountMgr.getSystemAccount(), VlanType.VirtualNetwork, null, null, false); String publicIPNetmask = publicIp.getVlanNetmask(); String publicIPgateway = publicIp.getVlanGateway(); String publicIPVlanTag = publicIp.getVlanTag(); diff --git a/server/src/com/cloud/network/IPAddressVO.java b/server/src/com/cloud/network/IPAddressVO.java index 4d2c64fc49c..db0aa8b8060 100644 --- a/server/src/com/cloud/network/IPAddressVO.java +++ b/server/src/com/cloud/network/IPAddressVO.java @@ -96,9 +96,8 @@ public class IPAddressVO implements IpAddress, Identity { @Column(name="physical_network_id") private Long physicalNetworkId; - @Column(name="allocated_by") - @Enumerated(value=EnumType.STRING) - private AllocatedBy allocatedBy; + @Column(name="is_elastic") + private boolean elastic; @Column(name="account_id") @Transient @@ -269,13 +268,15 @@ public class IPAddressVO implements IpAddress, Identity { public void setPhysicalNetworkId(Long physicalNetworkId) { this.physicalNetworkId = physicalNetworkId; } + + @Override - public AllocatedBy getAllocatedBy() { - return allocatedBy; + public boolean getElastic() { + return elastic; } - public void setAllocatedBy(AllocatedBy allocatedBy) { - this.allocatedBy = allocatedBy; + public void setElastic(boolean isElastic) { + this.elastic = isElastic; } } diff --git a/server/src/com/cloud/network/NetworkManager.java b/server/src/com/cloud/network/NetworkManager.java index be345f3a9f7..c75e53c9ff3 100755 --- a/server/src/com/cloud/network/NetworkManager.java +++ b/server/src/com/cloud/network/NetworkManager.java @@ -35,7 +35,6 @@ import com.cloud.exception.InsufficientAddressCapacityException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.hypervisor.Hypervisor.HypervisorType; -import com.cloud.network.IpAddress.AllocatedBy; import com.cloud.network.Network.Capability; import com.cloud.network.Network.Provider; import com.cloud.network.Network.Service; @@ -76,7 +75,7 @@ public interface NetworkManager extends NetworkService { * @return * @throws InsufficientAddressCapacityException */ - PublicIp assignPublicIpAddress(long dcId, Long podId, Account owner, VlanType type, Long networkId, String requestedIp, AllocatedBy allocatedBy) throws InsufficientAddressCapacityException; + PublicIp assignPublicIpAddress(long dcId, Long podId, Account owner, VlanType type, Long networkId, String requestedIp, boolean isElastic) throws InsufficientAddressCapacityException; /** * assigns a source nat ip address to an account within a network. diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 68cfd3d4461..eb176f7f49f 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -103,7 +103,6 @@ import com.cloud.host.HostVO; import com.cloud.host.Status; import com.cloud.host.dao.HostDao; import com.cloud.hypervisor.Hypervisor.HypervisorType; -import com.cloud.network.IpAddress.AllocatedBy; import com.cloud.network.IpAddress.State; import com.cloud.network.Network.Capability; import com.cloud.network.Network.GuestType; @@ -341,12 +340,12 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } @Override - public PublicIp assignPublicIpAddress(long dcId, Long podId, Account owner, VlanType type, Long networkId, String requestedIp, AllocatedBy allocatedBy) throws InsufficientAddressCapacityException { - return fetchNewPublicIp(dcId, podId, null, owner, type, networkId, false, true, requestedIp, allocatedBy); + public PublicIp assignPublicIpAddress(long dcId, Long podId, Account owner, VlanType type, Long networkId, String requestedIp, boolean isElastic) throws InsufficientAddressCapacityException { + return fetchNewPublicIp(dcId, podId, null, owner, type, networkId, false, true, requestedIp, isElastic); } @DB - public PublicIp fetchNewPublicIp(long dcId, Long podId, Long vlanDbId, Account owner, VlanType vlanUse, Long networkId, boolean sourceNat, boolean assign, String requestedIp, AllocatedBy allocatedBy) + public PublicIp fetchNewPublicIp(long dcId, Long podId, Long vlanDbId, Account owner, VlanType vlanUse, Long networkId, boolean sourceNat, boolean assign, String requestedIp, boolean isElastic) throws InsufficientAddressCapacityException { StringBuilder errorMessage = new StringBuilder("Unable to get ip adress in "); Transaction txn = Transaction.currentTxn(); @@ -402,7 +401,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag addr.setAllocatedTime(new Date()); addr.setAllocatedInDomainId(owner.getDomainId()); addr.setAllocatedToAccountId(owner.getId()); - addr.setAllocatedBy(allocatedBy); + addr.setElastic(isElastic); if (assign) { markPublicIpAsAllocated(addr); @@ -507,7 +506,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag vlanId = maps.get(0).getVlanDbId(); } - ip = fetchNewPublicIp(dcId, null, vlanId, owner, VlanType.VirtualNetwork, network.getId(), true, false, null, AllocatedBy.ipassoc); + ip = fetchNewPublicIp(dcId, null, vlanId, owner, VlanType.VirtualNetwork, network.getId(), true, false, null, false); sourceNat = ip.ip(); markPublicIpAsAllocated(sourceNat); @@ -922,7 +921,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag @Override @DB @ActionEvent(eventType = EventTypes.EVENT_NET_IP_ASSIGN, eventDescription = "allocating Ip", create = true) - public IpAddress allocateIP(long networkId, Account ipOwner, AllocatedBy allocatedBy) throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException { + public IpAddress allocateIP(long networkId, Account ipOwner, boolean isElastic) throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException { Account caller = UserContext.current().getCaller(); long userId = UserContext.current().getCallerUserId(); @@ -1009,7 +1008,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } } - ip = fetchNewPublicIp(zone.getId(), null, null, ipOwner, vlanType, network.getId(), isSourceNat, assign, null, allocatedBy); + ip = fetchNewPublicIp(zone.getId(), null, null, ipOwner, vlanType, network.getId(), isSourceNat, assign, null, isElastic); if (ip == null) { throw new InsufficientAddressCapacityException("Unable to find available public IP addresses", DataCenter.class, zone.getId()); @@ -3463,7 +3462,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag addr.setAllocatedTime(new Date()); addr.setAllocatedInDomainId(owner.getDomainId()); addr.setAllocatedToAccountId(owner.getId()); - addr.setAllocatedBy(AllocatedBy.ipassoc); + addr.setElastic(false); addr.setState(IpAddress.State.Allocating); markPublicIpAsAllocated(addr); } @@ -5864,7 +5863,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag try { s_logger.debug("Allocating elastic IP address for load balancer rule..."); //allocate ip - ip = allocateIP(networkId, owner, AllocatedBy.elasticip); + ip = allocateIP(networkId, owner, true); //apply ip associations ip = associateIP(ip.getId()); } catch (ResourceAllocationException ex) { @@ -5890,7 +5889,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (networkId != null) { Network guestNetwork = getNetwork(networkId); NetworkOffering offering = _configMgr.getNetworkOffering(guestNetwork.getNetworkOfferingId()); - if (offering.getElasticIp() && ip.getAllocatedBy() == AllocatedBy.elasticip) { + if (offering.getElasticIp() && ip.getElastic() == true) { UserContext ctx = UserContext.current(); if (!releasePublicIpAddress(ip.getId(), ctx.getCallerUserId(), ctx.getCaller())) { s_logger.warn("Unable to release elastic ip address id=" + ip.getId()); diff --git a/server/src/com/cloud/network/addr/PublicIp.java b/server/src/com/cloud/network/addr/PublicIp.java index 03c77af18c1..91e1eea453f 100644 --- a/server/src/com/cloud/network/addr/PublicIp.java +++ b/server/src/com/cloud/network/addr/PublicIp.java @@ -183,7 +183,7 @@ public class PublicIp implements PublicIpAddress { } @Override - public AllocatedBy getAllocatedBy() { - return _addr.getAllocatedBy(); + public boolean getElastic() { + return _addr.getElastic(); } } diff --git a/server/src/com/cloud/network/dao/IPAddressDaoImpl.java b/server/src/com/cloud/network/dao/IPAddressDaoImpl.java index 3e9134b620b..eb897ca632a 100755 --- a/server/src/com/cloud/network/dao/IPAddressDaoImpl.java +++ b/server/src/com/cloud/network/dao/IPAddressDaoImpl.java @@ -146,7 +146,7 @@ public class IPAddressDaoImpl extends GenericDaoBase implemen address.setAssociatedWithVmId(null); address.setState(State.Free); address.setAssociatedWithNetworkId(null); - address.setAllocatedBy(null); + address.setElastic(false); update(ipAddressId, address); } diff --git a/server/src/com/cloud/network/guru/DirectNetworkGuru.java b/server/src/com/cloud/network/guru/DirectNetworkGuru.java index 8ce566c9bf1..19c18494354 100755 --- a/server/src/com/cloud/network/guru/DirectNetworkGuru.java +++ b/server/src/com/cloud/network/guru/DirectNetworkGuru.java @@ -34,7 +34,6 @@ import com.cloud.exception.InsufficientVirtualNetworkCapcityException; import com.cloud.exception.InvalidParameterValueException; import com.cloud.network.IPAddressVO; import com.cloud.network.Network; -import com.cloud.network.IpAddress.AllocatedBy; import com.cloud.network.Network.Service; import com.cloud.network.Network.State; import com.cloud.network.NetworkManager; @@ -155,7 +154,7 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru { protected void getIp(NicProfile nic, DataCenter dc, VirtualMachineProfile vm, Network network, String requestedIp) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException { if (nic.getIp4Address() == null) { - PublicIp ip = _networkMgr.assignPublicIpAddress(dc.getId(), null, vm.getOwner(), VlanType.DirectAttached, network.getId(), requestedIp, AllocatedBy.ipassoc); + PublicIp ip = _networkMgr.assignPublicIpAddress(dc.getId(), null, vm.getOwner(), VlanType.DirectAttached, network.getId(), requestedIp, false); nic.setIp4Address(ip.getAddress().toString()); nic.setGateway(ip.getGateway()); nic.setNetmask(ip.getNetmask()); diff --git a/server/src/com/cloud/network/guru/DirectPodBasedNetworkGuru.java b/server/src/com/cloud/network/guru/DirectPodBasedNetworkGuru.java index d438d6351c4..fac93f8297f 100755 --- a/server/src/com/cloud/network/guru/DirectPodBasedNetworkGuru.java +++ b/server/src/com/cloud/network/guru/DirectPodBasedNetworkGuru.java @@ -42,10 +42,8 @@ import com.cloud.exception.InsufficientVirtualNetworkCapcityException; import com.cloud.network.IPAddressVO; import com.cloud.network.Network; import com.cloud.network.NetworkManager; -import com.cloud.network.IpAddress.AllocatedBy; import com.cloud.network.Networks.AddressFormat; import com.cloud.network.Networks.BroadcastDomainType; -import com.cloud.network.Networks.TrafficType; import com.cloud.network.addr.PublicIp; import com.cloud.network.dao.IPAddressDao; import com.cloud.offering.NetworkOffering; @@ -163,7 +161,7 @@ public class DirectPodBasedNetworkGuru extends DirectNetworkGuru { InsufficientAddressCapacityException, ConcurrentOperationException { DataCenter dc = _dcDao.findById(pod.getDataCenterId()); if (nic.getIp4Address() == null) { - PublicIp ip = _networkMgr.assignPublicIpAddress(dc.getId(), pod.getId(), vm.getOwner(), VlanType.DirectAttached, network.getId(), null, AllocatedBy.ipassoc); + PublicIp ip = _networkMgr.assignPublicIpAddress(dc.getId(), pod.getId(), vm.getOwner(), VlanType.DirectAttached, network.getId(), null, false); nic.setIp4Address(ip.getAddress().toString()); nic.setFormat(AddressFormat.Ip4); nic.setGateway(ip.getGateway()); diff --git a/server/src/com/cloud/network/guru/PublicNetworkGuru.java b/server/src/com/cloud/network/guru/PublicNetworkGuru.java index fc290e88ada..87f102c2213 100755 --- a/server/src/com/cloud/network/guru/PublicNetworkGuru.java +++ b/server/src/com/cloud/network/guru/PublicNetworkGuru.java @@ -36,7 +36,6 @@ import com.cloud.exception.InsufficientAddressCapacityException; import com.cloud.exception.InsufficientVirtualNetworkCapcityException; import com.cloud.network.IPAddressVO; import com.cloud.network.Network; -import com.cloud.network.IpAddress.AllocatedBy; import com.cloud.network.Network.State; import com.cloud.network.NetworkManager; import com.cloud.network.NetworkProfile; @@ -117,7 +116,7 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru { protected void getIp(NicProfile nic, DataCenter dc, VirtualMachineProfile vm, Network network) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException { if (nic.getIp4Address() == null) { - PublicIp ip = _networkMgr.assignPublicIpAddress(dc.getId(), null, vm.getOwner(), VlanType.VirtualNetwork, null, null, AllocatedBy.ipassoc); + PublicIp ip = _networkMgr.assignPublicIpAddress(dc.getId(), null, vm.getOwner(), VlanType.VirtualNetwork, null, null, false); nic.setIp4Address(ip.getAddress().toString()); nic.setGateway(ip.getGateway()); nic.setNetmask(ip.getNetmask()); diff --git a/server/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java b/server/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java index 05df6829c44..c67810978f6 100644 --- a/server/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java +++ b/server/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java @@ -75,7 +75,6 @@ import com.cloud.network.ElasticLbVmMapVO; import com.cloud.network.IPAddressVO; import com.cloud.network.LoadBalancerVO; import com.cloud.network.Network; -import com.cloud.network.IpAddress.AllocatedBy; import com.cloud.network.Network.Provider; import com.cloud.network.Network.Service; import com.cloud.network.NetworkManager; @@ -597,7 +596,7 @@ public class ElasticLoadBalancerManagerImpl implements Transaction txn = Transaction.currentTxn(); txn.start(); - PublicIp ip = _networkMgr.assignPublicIpAddress(frontEndNetwork.getDataCenterId(), null, account, VlanType.DirectAttached, frontEndNetwork.getId(), null, AllocatedBy.elasticip); + PublicIp ip = _networkMgr.assignPublicIpAddress(frontEndNetwork.getDataCenterId(), null, account, VlanType.DirectAttached, frontEndNetwork.getId(), null, true); IPAddressVO ipvo = _ipAddressDao.findById(ip.getId()); ipvo.setAssociatedWithNetworkId(frontEndNetwork.getId()); _ipAddressDao.update(ipvo.getId(), ipvo); diff --git a/server/src/com/cloud/network/rules/RulesManager.java b/server/src/com/cloud/network/rules/RulesManager.java index 1f0be0727d7..e86a3b2694a 100644 --- a/server/src/com/cloud/network/rules/RulesManager.java +++ b/server/src/com/cloud/network/rules/RulesManager.java @@ -22,7 +22,6 @@ import java.util.List; import com.cloud.exception.NetworkRuleConflictException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.IpAddress; -import com.cloud.network.IpAddress.AllocatedBy; import com.cloud.user.Account; import com.cloud.uservm.UserVm; @@ -74,6 +73,6 @@ public interface RulesManager extends RulesService { boolean enableElasticIpAndStaticNatForVm(UserVm vm, boolean stopOnError); - boolean disableStaticNat(long ipAddressId, AllocatedBy allocatedBy) throws ResourceUnavailableException; + boolean disableStaticNat(long ipAddressId, Account caller, long callerUserId) throws ResourceUnavailableException; } diff --git a/server/src/com/cloud/network/rules/RulesManagerImpl.java b/server/src/com/cloud/network/rules/RulesManagerImpl.java index 1335ba95953..22440e23f81 100755 --- a/server/src/com/cloud/network/rules/RulesManagerImpl.java +++ b/server/src/com/cloud/network/rules/RulesManagerImpl.java @@ -41,7 +41,6 @@ import com.cloud.exception.NetworkRuleConflictException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.IPAddressVO; import com.cloud.network.IpAddress; -import com.cloud.network.IpAddress.AllocatedBy; import com.cloud.network.Network; import com.cloud.network.Network.Service; import com.cloud.network.NetworkManager; @@ -322,8 +321,8 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { @Override public boolean enableStaticNat(long ipId, long vmId) throws NetworkRuleConflictException, ResourceUnavailableException { - - Account caller = UserContext.current().getCaller(); + UserContext ctx = UserContext.current(); + Account caller = ctx.getCaller(); // Verify input parameters UserVmVO vm = _vmDao.findById(vmId); @@ -357,7 +356,7 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { } // Verify ip address parameter - isIpReadyForStaticNat(vmId, ipAddress); + isIpReadyForStaticNat(vmId, ipAddress, caller, ctx.getCallerUserId()); _networkMgr.checkIpForService(ipAddress, Service.StaticNat); @@ -382,7 +381,7 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { } } - protected void isIpReadyForStaticNat(long vmId, IPAddressVO ipAddress) throws NetworkRuleConflictException, ResourceUnavailableException { + protected void isIpReadyForStaticNat(long vmId, IPAddressVO ipAddress, Account caller, long callerUserId) throws NetworkRuleConflictException, ResourceUnavailableException { if (ipAddress.isSourceNat()) { throw new InvalidParameterValueException("Can't enable static, ip address " + ipAddress + " is a sourceNat ip address"); } @@ -420,7 +419,7 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { } //unassign old static nat rule s_logger.debug("Disassociating static nat for ip " + oldIP); - if (!disableStaticNat(oldIP.getId(), AllocatedBy.ipassoc)) { + if (!disableStaticNat(oldIP.getId(), caller, callerUserId)) { throw new CloudRuntimeException("Failed to disable old static nat rule for vm id=" + vmId + " and ip " + oldIP); } } @@ -1019,13 +1018,14 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { @Override public boolean disableStaticNat(long ipId) throws ResourceUnavailableException{ - Account caller = UserContext.current().getCaller(); + UserContext ctx = UserContext.current(); + Account caller = ctx.getCaller(); IPAddressVO ipAddress = _ipAddressDao.findById(ipId); checkIpAndUserVm(ipAddress, null, caller); Long vmId = ipAddress.getAssociatedWithVmId(); - boolean success = disableStaticNat(ipId, AllocatedBy.ipassoc); + boolean success = disableStaticNat(ipId, caller, ctx.getCallerUserId()); if (success && vmId != null) { s_logger.debug("Allocating ip and enabling static nat for vm id=" + vmId + " as a part of disassociateIp command"); UserVm vm = _vmDao.findById(vmId); @@ -1041,12 +1041,9 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { } @Override - public boolean disableStaticNat(long ipId, AllocatedBy allocatedBy) throws ResourceUnavailableException { + public boolean disableStaticNat(long ipId, Account caller, long callerUserId) throws ResourceUnavailableException { boolean success = true; - UserContext ctx = UserContext.current(); - Account caller = ctx.getCaller(); - IPAddressVO ipAddress = _ipAddressDao.findById(ipId); checkIpAndUserVm(ipAddress, null, caller); @@ -1057,7 +1054,7 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { //Revoke all firewall rules for the ip try { s_logger.debug("Revoking all " + Purpose.Firewall + "rules as a part of disabling static nat for public IP id=" + ipId); - if (!_firewallMgr.revokeFirewallRulesForIp(ipId, ctx.getCallerUserId(), caller)) { + if (!_firewallMgr.revokeFirewallRulesForIp(ipId, callerUserId, caller)) { s_logger.warn("Unable to revoke all the firewall rules for ip id=" + ipId + " as a part of disable statis nat"); success = false; } @@ -1066,7 +1063,7 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { success = false; } - if (!revokeAllPFAndStaticNatRulesForIp(ipId, UserContext.current().getCallerUserId(), caller)) { + if (!revokeAllPFAndStaticNatRulesForIp(ipId, callerUserId, caller)) { s_logger.warn("Unable to revoke all static nat rules for ip " + ipAddress); success = false; } @@ -1074,9 +1071,6 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { if (success) { ipAddress.setOneToOneNat(false); ipAddress.setAssociatedWithVmId(null); - if (allocatedBy != null) { - ipAddress.setAllocatedBy(allocatedBy); - } _ipAddressDao.update(ipAddress.getId(), ipAddress); diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 416d52fc0b0..8667f8d74e2 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -1264,7 +1264,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager IPAddressVO ip = _ipAddressDao.findByAssociatedVmId(vmId); try { if (ip != null) { - if (_rulesMgr.disableStaticNat(ip.getId(), null)) { + if (_rulesMgr.disableStaticNat(ip.getId(), _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM), User.UID_SYSTEM)) { s_logger.debug("Disabled 1-1 nat for ip address " + ip + " as a part of vm id=" + vmId + " expunge"); } else { s_logger.warn("Failed to disable static nat for ip address " + ip + " as a part of vm id=" + vmId + " expunge"); diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index cfa12852318..1f169abdbd8 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -918,7 +918,7 @@ CREATE TABLE `cloud`.`user_ip_address` ( `source_network_id` bigint unsigned NOT NULL COMMENT 'network id ip belongs to', `network_id` bigint unsigned COMMENT 'network this public ip address is associated with', `physical_network_id` bigint unsigned NOT NULL COMMENT 'physical network id that this configuration is based on', - `allocated_by` char (32) COMMENT 'the way ip address was allocated; can be by ipassoc or vmdeploy', + `is_elastic` int(1) unsigned NOT NULL default '0', PRIMARY KEY (`id`), UNIQUE (`public_ip_address`, `source_network_id`), CONSTRAINT `fk_user_ip_address__source_network_id` FOREIGN KEY (`source_network_id`) REFERENCES `networks`(`id`),