103103import com .cloud .host .Status ;
104104import com .cloud .host .dao .HostDao ;
105105import com .cloud .hypervisor .Hypervisor .HypervisorType ;
106+ import com .cloud .network .IpAddress .AllocatedBy ;
106107import com .cloud .network .IpAddress .State ;
107108import com .cloud .network .Network .Capability ;
108109import com .cloud .network .Network .GuestType ;
@@ -340,12 +341,12 @@ public boolean canElementEnableIndividualServices(Provider provider){
340341 }
341342
342343 @ Override
343- public PublicIp assignPublicIpAddress (long dcId , Long podId , Account owner , VlanType type , Long networkId , String requestedIp ) throws InsufficientAddressCapacityException {
344- return fetchNewPublicIp (dcId , podId , null , owner , type , networkId , false , true , requestedIp );
344+ public PublicIp assignPublicIpAddress (long dcId , Long podId , Account owner , VlanType type , Long networkId , String requestedIp , AllocatedBy allocatedBy ) throws InsufficientAddressCapacityException {
345+ return fetchNewPublicIp (dcId , podId , null , owner , type , networkId , false , true , requestedIp , allocatedBy );
345346 }
346347
347348 @ DB
348- public PublicIp fetchNewPublicIp (long dcId , Long podId , Long vlanDbId , Account owner , VlanType vlanUse , Long networkId , boolean sourceNat , boolean assign , String requestedIp )
349+ public PublicIp fetchNewPublicIp (long dcId , Long podId , Long vlanDbId , Account owner , VlanType vlanUse , Long networkId , boolean sourceNat , boolean assign , String requestedIp , AllocatedBy allocatedBy )
349350 throws InsufficientAddressCapacityException {
350351 StringBuilder errorMessage = new StringBuilder ("Unable to get ip adress in " );
351352 Transaction txn = Transaction .currentTxn ();
@@ -401,6 +402,7 @@ public PublicIp fetchNewPublicIp(long dcId, Long podId, Long vlanDbId, Account o
401402 addr .setAllocatedTime (new Date ());
402403 addr .setAllocatedInDomainId (owner .getDomainId ());
403404 addr .setAllocatedToAccountId (owner .getId ());
405+ addr .setAllocatedBy (allocatedBy );
404406
405407 if (assign ) {
406408 markPublicIpAsAllocated (addr );
@@ -505,7 +507,7 @@ public PublicIp assignSourceNatIpAddress(Account owner, Network network, long ca
505507 vlanId = maps .get (0 ).getVlanDbId ();
506508 }
507509
508- ip = fetchNewPublicIp (dcId , null , vlanId , owner , VlanType .VirtualNetwork , network .getId (), true , false , null );
510+ ip = fetchNewPublicIp (dcId , null , vlanId , owner , VlanType .VirtualNetwork , network .getId (), true , false , null , AllocatedBy . ipassoc );
509511 sourceNat = ip .ip ();
510512
511513 markPublicIpAsAllocated (sourceNat );
@@ -920,7 +922,7 @@ public List<? extends Network> getIsolatedNetworksOwnedByAccountInZone(long zone
920922 @ Override
921923 @ DB
922924 @ ActionEvent (eventType = EventTypes .EVENT_NET_IP_ASSIGN , eventDescription = "allocating Ip" , create = true )
923- public IpAddress allocateIP (long networkId , Account ipOwner ) throws ResourceAllocationException , InsufficientAddressCapacityException , ConcurrentOperationException {
925+ public IpAddress allocateIP (long networkId , Account ipOwner , AllocatedBy allocatedBy ) throws ResourceAllocationException , InsufficientAddressCapacityException , ConcurrentOperationException {
924926 Account caller = UserContext .current ().getCaller ();
925927 long userId = UserContext .current ().getCallerUserId ();
926928
@@ -1007,7 +1009,7 @@ public IpAddress allocateIP(long networkId, Account ipOwner) throws ResourceAllo
10071009 }
10081010 }
10091011
1010- ip = fetchNewPublicIp (zone .getId (), null , null , ipOwner , vlanType , network .getId (), isSourceNat , assign , null );
1012+ ip = fetchNewPublicIp (zone .getId (), null , null , ipOwner , vlanType , network .getId (), isSourceNat , assign , null , allocatedBy );
10111013
10121014 if (ip == null ) {
10131015 throw new InsufficientAddressCapacityException ("Unable to find available public IP addresses" , DataCenter .class , zone .getId ());
@@ -3461,6 +3463,7 @@ public boolean associateIpAddressListToAccount(long userId, long accountId, long
34613463 addr .setAllocatedTime (new Date ());
34623464 addr .setAllocatedInDomainId (owner .getDomainId ());
34633465 addr .setAllocatedToAccountId (owner .getId ());
3466+ addr .setAllocatedBy (AllocatedBy .ipassoc );
34643467 addr .setState (IpAddress .State .Allocating );
34653468 markPublicIpAsAllocated (addr );
34663469 }
@@ -5861,7 +5864,7 @@ public IpAddress assignElasticIp(long networkId, Account owner, boolean forElast
58615864 try {
58625865 s_logger .debug ("Allocating elastic IP address for load balancer rule..." );
58635866 //allocate ip
5864- ip = allocateIP (networkId , owner );
5867+ ip = allocateIP (networkId , owner , AllocatedBy . elasticip );
58655868 //apply ip associations
58665869 ip = associateIP (ip .getId ());
58675870 } catch (ResourceAllocationException ex ) {
@@ -5887,7 +5890,7 @@ public boolean handleElasticIpRelease(IpAddress ip) {
58875890 if (networkId != null ) {
58885891 Network guestNetwork = getNetwork (networkId );
58895892 NetworkOffering offering = _configMgr .getNetworkOffering (guestNetwork .getNetworkOfferingId ());
5890- if (offering .getElasticIp ()) {
5893+ if (offering .getElasticIp () && ip . getAllocatedBy () == AllocatedBy . elasticip ) {
58915894 UserContext ctx = UserContext .current ();
58925895 if (!releasePublicIpAddress (ip .getId (), ctx .getCallerUserId (), ctx .getCaller ())) {
58935896 s_logger .warn ("Unable to release elastic ip address id=" + ip .getId ());
0 commit comments