mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-11-04 00:02:37 +01:00 
			
		
		
		
	Destroy VPC if it fails to start during the deployment
This commit is contained in:
		
							parent
							
								
									9ec8526281
								
							
						
					
					
						commit
						1189e92708
					
				@ -121,7 +121,6 @@ public class CreateVPCCmd extends BaseAsyncCreateCmd{
 | 
			
		||||
    
 | 
			
		||||
    @Override
 | 
			
		||||
    public void execute() {
 | 
			
		||||
        //TODO - prepare vpc here (call start() method, it should start the VR, associate source nat ip address, etc)
 | 
			
		||||
        Vpc vpc = null;
 | 
			
		||||
        try {
 | 
			
		||||
             if (_vpcService.startVpc(this.getEntityId())) {
 | 
			
		||||
 | 
			
		||||
@ -351,3 +351,9 @@ createVPCOffering=com.cloud.api.commands.CreateVPCOfferingCmd;1
 | 
			
		||||
updateVPCOffering=com.cloud.api.commands.UpdateVPCOfferingCmd;1
 | 
			
		||||
deleteVPCOffering=com.cloud.api.commands.DeleteVPCOfferingCmd;1
 | 
			
		||||
listVPCOfferings=com.cloud.api.commands.ListVPCOfferingsCmd;15
 | 
			
		||||
 | 
			
		||||
#### VPC gateway commands
 | 
			
		||||
createVPCGateway=com.cloud.api.commands.CreateVPCGatewayCmd;15
 | 
			
		||||
listVPCGateways=com.cloud.api.commands.ListVPCGatewaysCmd;15
 | 
			
		||||
deleteVPCGateway=com.cloud.api.commands.DeleteVPCGatewayCmd;15
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1334,7 +1334,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
 | 
			
		||||
            offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworks,
 | 
			
		||||
                    "Offering for Isolated VPC networks with Source Nat service enabled", TrafficType.Guest,
 | 
			
		||||
                    null, false, Availability.Required, null, defaultIsolatedSourceNatEnabledNetworkOfferingProviders,
 | 
			
		||||
                    true, Network.GuestType.Isolated, false, null, true, null, false);
 | 
			
		||||
                    true, Network.GuestType.Isolated, false, null, false, null, false);
 | 
			
		||||
            offering.setState(NetworkOffering.State.Enabled);
 | 
			
		||||
            _networkOfferingDao.update(offering.getId(), offering);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -385,7 +385,6 @@ public class VpcManagerImpl implements VpcManager, Manager{
 | 
			
		||||
            offering.setDisplayText(displayText);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        if (state != null) {
 | 
			
		||||
            boolean validState = false;
 | 
			
		||||
            for (VpcOffering.State st : VpcOffering.State.values()) {
 | 
			
		||||
@ -704,19 +703,42 @@ public class VpcManagerImpl implements VpcManager, Manager{
 | 
			
		||||
        DeployDestination dest = new DeployDestination(dc, null, null, null);
 | 
			
		||||
        ReservationContext context = new ReservationContextImpl(null, null, callerUser, 
 | 
			
		||||
                _accountMgr.getAccount(vpc.getAccountId()));
 | 
			
		||||
        
 | 
			
		||||
        boolean result = true;
 | 
			
		||||
        try {
 | 
			
		||||
            if (!startVpc(vpc, dest, context)) {
 | 
			
		||||
                s_logger.warn("Failed to start vpc " + vpc);
 | 
			
		||||
                result = false;
 | 
			
		||||
            }
 | 
			
		||||
        } catch (Exception ex) {
 | 
			
		||||
            s_logger.warn("Failed to start vpc " + vpc + " due to ", ex);
 | 
			
		||||
            result = false;
 | 
			
		||||
        } finally {
 | 
			
		||||
            //do cleanup
 | 
			
		||||
            if (!result) {
 | 
			
		||||
                s_logger.debug("Destroying vpc " + vpc + " that failed to start");
 | 
			
		||||
                if (destroyVpc(vpc)) {
 | 
			
		||||
                    s_logger.warn("Successfully destroyed vpc " + vpc + " that failed to start");
 | 
			
		||||
                } else {
 | 
			
		||||
                    s_logger.warn("Failed to destroy vpc " + vpc + " that failed to start");
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected boolean startVpc(Vpc vpc, DeployDestination dest, ReservationContext context) 
 | 
			
		||||
            throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
 | 
			
		||||
        //deploy provider
 | 
			
		||||
        if (getVpcElement().implementVpc(vpc, dest, context)) {
 | 
			
		||||
            s_logger.debug("Vpc " + vpc + " has started succesfully");
 | 
			
		||||
            return true;
 | 
			
		||||
        } else {
 | 
			
		||||
            s_logger.warn("Vpc " + vpc + " failed to start");
 | 
			
		||||
            //FIXME - add cleanup logic here
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean shutdownVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException {
 | 
			
		||||
        UserContext ctx = UserContext.current();
 | 
			
		||||
@ -778,14 +800,16 @@ public class VpcManagerImpl implements VpcManager, Manager{
 | 
			
		||||
            
 | 
			
		||||
            //4) vpc and network should belong to the same owner
 | 
			
		||||
            if (vpc.getAccountId() != networkOwner.getId()) {
 | 
			
		||||
                throw new InvalidParameterValueException("Vpc " + vpc + " owner is different from the network owner " + networkOwner);
 | 
			
		||||
                throw new InvalidParameterValueException("Vpc " + vpc + " owner is different from the network owner "
 | 
			
		||||
            + networkOwner);
 | 
			
		||||
            }
 | 
			
		||||
            
 | 
			
		||||
            //5) Only Isolated networks with Source nat service enabled can be added to vpc
 | 
			
		||||
            if (!(guestNtwkOff.getGuestType() == GuestType.Isolated 
 | 
			
		||||
                    && _ntwkMgr.areServicesSupportedByNetworkOffering(guestNtwkOff.getId(), Service.SourceNat))) {
 | 
			
		||||
                
 | 
			
		||||
                throw new InvalidParameterValueException("Only networks of type " + GuestType.Isolated + " with service " + Service.SourceNat + 
 | 
			
		||||
                throw new InvalidParameterValueException("Only networks of type " + GuestType.Isolated + " with service "
 | 
			
		||||
                + Service.SourceNat + 
 | 
			
		||||
                        " can be added as a part of VPC");
 | 
			
		||||
            }
 | 
			
		||||
            
 | 
			
		||||
@ -842,7 +866,6 @@ public class VpcManagerImpl implements VpcManager, Manager{
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        return success;
 | 
			
		||||
       
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1014,7 +1014,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
 | 
			
		||||
                "Offering for Isolated Vpc networks with Source Nat service enabled",
 | 
			
		||||
                TrafficType.Guest,
 | 
			
		||||
                false, false, null, null, true, Availability.Required,
 | 
			
		||||
                null, Network.GuestType.Isolated, true, false);
 | 
			
		||||
                null, Network.GuestType.Isolated, false, false);
 | 
			
		||||
 | 
			
		||||
        defaultNetworkOfferingForVpcNetworks.setState(NetworkOffering.State.Enabled);
 | 
			
		||||
        defaultNetworkOfferingForVpcNetworks = _networkOfferingDao.persistDefaultNetworkOffering(defaultNetworkOfferingForVpcNetworks);
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										2
									
								
								wscript
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								wscript
									
									
									
									
									
								
							@ -3,7 +3,7 @@
 | 
			
		||||
 | 
			
		||||
# the following two variables are used by the target "waf dist"
 | 
			
		||||
# if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog
 | 
			
		||||
VERSION = '3.0.3.2012-05-25T22:13:38Z'
 | 
			
		||||
VERSION = '3.0.3.2012-05-29T17:33:07Z'
 | 
			
		||||
APPNAME = 'cloud'
 | 
			
		||||
 | 
			
		||||
import shutil,os
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user