Skip to content

Commit

Permalink
Fixes EUCA-2327 Duplicate address assignments to the same instance
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Munn committed Jul 26, 2012
1 parent c406ffc commit 9f21aa5
Showing 1 changed file with 6 additions and 2 deletions.
Expand Up @@ -166,9 +166,9 @@ public AssociateAddressResponseType associate( final AssociateAddressType reques
reply.set_return( false ); reply.set_return( false );
final Address address = RestrictedTypes.doPrivileged( request.getPublicIp( ), Address.class ); final Address address = RestrictedTypes.doPrivileged( request.getPublicIp( ), Address.class );
if ( !address.isAllocated( ) ) { if ( !address.isAllocated( ) ) {
throw new EucalyptusCloudException( "Cannot associated an address which is not allocated: " + request.getPublicIp( ) ); throw new EucalyptusCloudException( "Cannot associate an address which is not allocated: " + request.getPublicIp( ) );
} else if ( !Contexts.lookup( ).hasAdministrativePrivileges( ) && !Contexts.lookup( ).getUserFullName( ).asAccountFullName( ).getAccountNumber( ).equals( address.getOwner( ).getAccountNumber( ) ) ) { } else if ( !Contexts.lookup( ).hasAdministrativePrivileges( ) && !Contexts.lookup( ).getUserFullName( ).asAccountFullName( ).getAccountNumber( ).equals( address.getOwner( ).getAccountNumber( ) ) ) {
throw new EucalyptusCloudException( "Cannot associated an address which is not allocated to your account: " + request.getPublicIp( ) ); throw new EucalyptusCloudException( "Cannot associate an address which is not allocated to your account: " + request.getPublicIp( ) );
} }
final VmInstance vm = RestrictedTypes.doPrivileged( request.getInstanceId( ), VmInstance.class ); final VmInstance vm = RestrictedTypes.doPrivileged( request.getInstanceId( ), VmInstance.class );
final VmInstance oldVm = findCurrentAssignedVm( address ); final VmInstance oldVm = findCurrentAssignedVm( address );
Expand All @@ -178,6 +178,10 @@ public AssociateAddressResponseType associate( final AssociateAddressType reques
: false; : false;
reply.set_return( true ); reply.set_return( true );


if ( oldAddr != null && address.equals( oldAddr ) ) {
return reply;
}

final UnconditionalCallback assignTarget = new UnconditionalCallback( ) { final UnconditionalCallback assignTarget = new UnconditionalCallback( ) {
public void fire( ) { public void fire( ) {
AsyncRequests.newRequest( address.assign( vm ).getCallback( ) ).then( new Callback.Success<BaseMessage>( ) { AsyncRequests.newRequest( address.assign( vm ).getCallback( ) ).then( new Callback.Success<BaseMessage>( ) {
Expand Down

0 comments on commit 9f21aa5

Please sign in to comment.