mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-11-04 00:02:37 +01:00 
			
		
		
		
	Basic zone is fixed and works with new NaaS now
This commit is contained in:
		
							parent
							
								
									f4136bfd9e
								
							
						
					
					
						commit
						87f5150e38
					
				@ -1430,11 +1430,6 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
 | 
			
		||||
        if (zone != null) {
 | 
			
		||||
            List<NetworkOfferingVO> ntwkOff = _networkOfferingDao.listSystemNetworkOfferings();
 | 
			
		||||
 | 
			
		||||
            //for Advance security group enabled zone and Basic zone we have to find only one guest network offering enabled in the system
 | 
			
		||||
            if (zone.getNetworkType() == NetworkType.Basic || isSecurityGroupEnabled) {
 | 
			
		||||
                ntwkOff.add(_networkMgr.getExclusiveGuestNetworkOffering());
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            for (NetworkOfferingVO offering : ntwkOff) {
 | 
			
		||||
                DataCenterDeployment plan = new DataCenterDeployment(zone.getId(), null, null, null, null, null);
 | 
			
		||||
                NetworkVO userNetwork = new NetworkVO();
 | 
			
		||||
@ -1453,20 +1448,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
 | 
			
		||||
                    } else {
 | 
			
		||||
                        continue;
 | 
			
		||||
                    }
 | 
			
		||||
                } else if (offering.getTrafficType() == TrafficType.Guest) {
 | 
			
		||||
                    if (zone.getNetworkType() == NetworkType.Basic) {
 | 
			
		||||
                        isNetworkDefault = true;
 | 
			
		||||
                        broadcastDomainType = BroadcastDomainType.Native;
 | 
			
		||||
                        //set physicalnetworkId to the default Guest network in a basic Zone.
 | 
			
		||||
                        plan = new DataCenterDeployment(zone.getId(), null, null, null, null, physicalNetworkId);
 | 
			
		||||
                    } else if (offering.getGuestType() == GuestType.Shared && isSecurityGroupEnabled) {
 | 
			
		||||
                        isNetworkDefault = true;
 | 
			
		||||
                    } else {
 | 
			
		||||
                        continue;
 | 
			
		||||
                }
 | 
			
		||||
                
 | 
			
		||||
                    networkDomain = "cs" + Long.toHexString(Account.ACCOUNT_ID_SYSTEM) + _networkMgr.getGlobalGuestDomainSuffix();
 | 
			
		||||
                }
 | 
			
		||||
                userNetwork.setBroadcastDomainType(broadcastDomainType);
 | 
			
		||||
                userNetwork.setNetworkDomain(networkDomain);
 | 
			
		||||
                _networkMgr.setupNetwork(systemAccount, offering, userNetwork, plan, null, null, isNetworkDefault, false, Domain.ROOT_DOMAIN, null);
 | 
			
		||||
 | 
			
		||||
@ -22,6 +22,8 @@ import java.util.HashMap;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
import com.cloud.identity.IdentityServiceImpl;
 | 
			
		||||
import com.cloud.identity.dao.IdentityDaoImpl;
 | 
			
		||||
import com.cloud.agent.manager.ClusteredAgentManagerImpl;
 | 
			
		||||
import com.cloud.alert.AlertManagerImpl;
 | 
			
		||||
import com.cloud.alert.dao.AlertDaoImpl;
 | 
			
		||||
@ -65,8 +67,6 @@ import com.cloud.host.dao.HostDetailsDaoImpl;
 | 
			
		||||
import com.cloud.host.dao.HostTagsDaoImpl;
 | 
			
		||||
import com.cloud.hypervisor.HypervisorGuruManagerImpl;
 | 
			
		||||
import com.cloud.hypervisor.dao.HypervisorCapabilitiesDaoImpl;
 | 
			
		||||
import com.cloud.identity.IdentityServiceImpl;
 | 
			
		||||
import com.cloud.identity.dao.IdentityDaoImpl;
 | 
			
		||||
import com.cloud.keystore.KeystoreDaoImpl;
 | 
			
		||||
import com.cloud.keystore.KeystoreManagerImpl;
 | 
			
		||||
import com.cloud.maint.UpgradeManagerImpl;
 | 
			
		||||
 | 
			
		||||
@ -32,6 +32,7 @@ import javax.naming.ConfigurationException;
 | 
			
		||||
 | 
			
		||||
import org.apache.log4j.Logger;
 | 
			
		||||
 | 
			
		||||
import com.cloud.identity.dao.IdentityDao;
 | 
			
		||||
import com.cloud.agent.AgentManager;
 | 
			
		||||
import com.cloud.agent.api.AgentControlAnswer;
 | 
			
		||||
import com.cloud.agent.api.Answer;
 | 
			
		||||
@ -69,12 +70,11 @@ import com.cloud.exception.InvalidParameterValueException;
 | 
			
		||||
import com.cloud.exception.OperationTimedoutException;
 | 
			
		||||
import com.cloud.exception.ResourceUnavailableException;
 | 
			
		||||
import com.cloud.exception.StorageUnavailableException;
 | 
			
		||||
import com.cloud.host.Host.Type;
 | 
			
		||||
import com.cloud.host.Host;
 | 
			
		||||
import com.cloud.host.Host.Type;
 | 
			
		||||
import com.cloud.host.HostVO;
 | 
			
		||||
import com.cloud.host.dao.HostDao;
 | 
			
		||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
 | 
			
		||||
import com.cloud.identity.dao.IdentityDao;
 | 
			
		||||
import com.cloud.info.ConsoleProxyConnectionInfo;
 | 
			
		||||
import com.cloud.info.ConsoleProxyInfo;
 | 
			
		||||
import com.cloud.info.ConsoleProxyLoadInfo;
 | 
			
		||||
@ -88,6 +88,7 @@ import com.cloud.keystore.KeystoreVO;
 | 
			
		||||
import com.cloud.network.NetworkManager;
 | 
			
		||||
import com.cloud.network.NetworkVO;
 | 
			
		||||
import com.cloud.network.Networks.TrafficType;
 | 
			
		||||
import com.cloud.network.dao.NetworkDao;
 | 
			
		||||
import com.cloud.offerings.NetworkOfferingVO;
 | 
			
		||||
import com.cloud.offerings.dao.NetworkOfferingDao;
 | 
			
		||||
import com.cloud.resource.ResourceManager;
 | 
			
		||||
@ -118,10 +119,10 @@ import com.cloud.utils.component.Inject;
 | 
			
		||||
import com.cloud.utils.component.Manager;
 | 
			
		||||
import com.cloud.utils.db.DB;
 | 
			
		||||
import com.cloud.utils.db.GlobalLock;
 | 
			
		||||
import com.cloud.utils.db.SearchCriteria.Op;
 | 
			
		||||
import com.cloud.utils.db.SearchCriteria2;
 | 
			
		||||
import com.cloud.utils.db.SearchCriteriaService;
 | 
			
		||||
import com.cloud.utils.db.Transaction;
 | 
			
		||||
import com.cloud.utils.db.SearchCriteria.Op;
 | 
			
		||||
import com.cloud.utils.events.SubscriptionMgr;
 | 
			
		||||
import com.cloud.utils.exception.CloudRuntimeException;
 | 
			
		||||
import com.cloud.utils.net.NetUtils;
 | 
			
		||||
@ -209,9 +210,10 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
 | 
			
		||||
    UserVmDetailsDao _vmDetailsDao;
 | 
			
		||||
    @Inject
 | 
			
		||||
    ResourceManager _resourceMgr; 
 | 
			
		||||
    
 | 
			
		||||
    @Inject
 | 
			
		||||
    IdentityDao _identityDao;
 | 
			
		||||
    @Inject
 | 
			
		||||
    NetworkDao _networkDao;
 | 
			
		||||
 | 
			
		||||
    private ConsoleProxyListener _listener;
 | 
			
		||||
 | 
			
		||||
@ -221,6 +223,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
 | 
			
		||||
    NetworkOfferingVO _managementNetworkOffering;
 | 
			
		||||
    NetworkOfferingVO _linkLocalNetworkOffering;
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    @Inject
 | 
			
		||||
    private VirtualMachineManager _itMgr;
 | 
			
		||||
 | 
			
		||||
@ -560,18 +563,28 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
 | 
			
		||||
        Account systemAcct = _accountMgr.getSystemAccount();
 | 
			
		||||
 | 
			
		||||
        DataCenterDeployment plan = new DataCenterDeployment(dataCenterId);
 | 
			
		||||
        NetworkOfferingVO defaultOffering = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemPublicNetwork).get(0);
 | 
			
		||||
       
 | 
			
		||||
        TrafficType defaultTrafficType = TrafficType.Public;
 | 
			
		||||
        if (dc.getNetworkType() == NetworkType.Basic || dc.isSecurityGroupEnabled()) {
 | 
			
		||||
            defaultOffering = _networkMgr.getExclusiveGuestNetworkOffering();
 | 
			
		||||
        	defaultTrafficType = TrafficType.Guest;
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        List<NetworkVO> defaultNetworks = _networkDao.listByZoneAndTrafficType(dataCenterId, defaultTrafficType);
 | 
			
		||||
        
 | 
			
		||||
        if (defaultNetworks.size() != 1) {
 | 
			
		||||
        	throw new CloudRuntimeException("Found " + defaultNetworks.size() + " networks of type " + defaultTrafficType + " when expect to find 1");
 | 
			
		||||
        }        
 | 
			
		||||
        
 | 
			
		||||
        NetworkVO defaultNetwork = defaultNetworks.get(0);
 | 
			
		||||
 | 
			
		||||
        List<NetworkOfferingVO> offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemControlNetwork, NetworkOfferingVO.SystemManagementNetwork);
 | 
			
		||||
        List<Pair<NetworkVO, NicProfile>> networks = new ArrayList<Pair<NetworkVO, NicProfile>>(offerings.size() + 1);
 | 
			
		||||
        NicProfile defaultNic = new NicProfile();
 | 
			
		||||
        defaultNic.setDefaultNic(true);
 | 
			
		||||
        defaultNic.setDeviceId(2);
 | 
			
		||||
        networks.add(new Pair<NetworkVO, NicProfile>(_networkMgr.setupNetwork(systemAcct, defaultOffering, plan, null, null, false).get(0), defaultNic));
 | 
			
		||||
 | 
			
		||||
        networks.add(new Pair<NetworkVO, NicProfile>(_networkMgr.setupNetwork(systemAcct, _networkOfferingDao.findById(defaultNetwork.getNetworkOfferingId()), null, plan, null, null, false, false, null, null).get(0), defaultNic));
 | 
			
		||||
 | 
			
		||||
        for (NetworkOfferingVO offering : offerings) {
 | 
			
		||||
            networks.add(new Pair<NetworkVO, NicProfile>(_networkMgr.setupNetwork(systemAcct, offering, plan, null, null, false).get(0), null));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -236,8 +236,6 @@ public interface NetworkManager extends NetworkService {
 | 
			
		||||
 | 
			
		||||
    boolean canElementEnableIndividualServices(Provider provider);
 | 
			
		||||
    
 | 
			
		||||
    NetworkOfferingVO getExclusiveGuestNetworkOffering();
 | 
			
		||||
    
 | 
			
		||||
    PhysicalNetworkServiceProvider addDefaultVirtualRouterToPhysicalNetwork(long physicalNetworkId);
 | 
			
		||||
    
 | 
			
		||||
    boolean areServicesSupportedInNetwork(long networkId, Service... services);
 | 
			
		||||
 | 
			
		||||
@ -1149,22 +1149,6 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
 | 
			
		||||
        return offerings;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    
 | 
			
		||||
    @Override
 | 
			
		||||
    public NetworkOfferingVO getExclusiveGuestNetworkOffering() {
 | 
			
		||||
        //this method should return Guest network offering in Enabled state; and this network offering should be unique, otherwise Runtime exception is going to be thrown
 | 
			
		||||
        List<NetworkOfferingVO> offerings = _networkOfferingDao.listByTrafficTypeGuestTypeAndState(NetworkOffering.State.Enabled, TrafficType.Guest, GuestType.Shared);
 | 
			
		||||
        if (offerings.isEmpty()) {
 | 
			
		||||
            throw new CloudRuntimeException("Unable to find network offering in state " + NetworkOffering.State.Enabled + ", traffic type " + TrafficType.Guest + " and guest type " + GuestType.Shared);
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        if (offerings.size() > 1) {
 | 
			
		||||
            throw new CloudRuntimeException("Found more than 1 network offering in state " + NetworkOffering.State.Enabled + ", traffic type " + TrafficType.Guest + " and guest type " + GuestType.Shared);
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
        return offerings.get(0);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    @DB
 | 
			
		||||
    public void allocate(VirtualMachineProfile<? extends VMInstanceVO> vm, List<Pair<NetworkVO, NicProfile>> networks) throws InsufficientCapacityException, ConcurrentOperationException {
 | 
			
		||||
@ -1886,12 +1870,12 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
 | 
			
		||||
 | 
			
		||||
        Network network = createNetwork(networkOfferingId, name, displayText, isDefault, gateway, cidr, vlanId, networkDomain, owner, false, sharedDomainId, pNtwk, zoneId, aclType);
 | 
			
		||||
        
 | 
			
		||||
        //Vlan is created in 2 cases:
 | 
			
		||||
        //Vlan is created in 2 cases - works in Advance zone only:
 | 
			
		||||
        //1) GuestType is Shared
 | 
			
		||||
        //2) GuestType is Isolated, but SourceNat service is disabled
 | 
			
		||||
        boolean createVlan = ((network.getGuestType() == Network.GuestType.Shared) || (network.getGuestType() == GuestType.Isolated && !areServicesSupportedByNetworkOffering(networkOffering.getId(), Service.SourceNat)));
 | 
			
		||||
 | 
			
		||||
        if (caller.getType() == Account.ACCOUNT_TYPE_ADMIN && createVlan && defineNetworkConfig) {
 | 
			
		||||
        if (zone.getNetworkType() == NetworkType.Advanced && caller.getType() == Account.ACCOUNT_TYPE_ADMIN && createVlan && defineNetworkConfig) {
 | 
			
		||||
            // Create vlan ip range
 | 
			
		||||
            _configMgr.createVlanAndPublicIpRange(userId, pNtwk.getDataCenterId(), null, startIP, endIP, gateway, netmask, false, vlanId, null, network.getId(), physicalNetworkId);
 | 
			
		||||
        }
 | 
			
		||||
@ -1908,25 +1892,31 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
 | 
			
		||||
 | 
			
		||||
        NetworkOfferingVO networkOffering = _networkOfferingDao.findById(networkOfferingId);
 | 
			
		||||
        DataCenterVO zone = _dcDao.findById(zoneId);
 | 
			
		||||
// removed during the merge for network as service 
 | 
			
		||||
// Only Direct Account specific networks can be created in Advanced Security Group enabled zone
 | 
			
		||||
//        if (zone.isSecurityGroupEnabled() && (networkOffering.getGuestType() == GuestIpType.Virtual || (isShared != null && isShared))) {
 | 
			
		||||
//            throw new InvalidParameterValueException("Virtual Network and Direct Shared Network creation is not allowed if zone is security group enabled");
 | 
			
		||||
//        }
 | 
			
		||||
//
 | 
			
		||||
//        if (zone.getNetworkType() == NetworkType.Basic) {
 | 
			
		||||
//            throw new InvalidParameterValueException("Network creation is not allowed in zone with network type " + NetworkType.Basic);
 | 
			
		||||
//        }
 | 
			
		||||
//
 | 
			
		||||
        
 | 
			
		||||
        //Only one guest network is supported in Basic zone
 | 
			
		||||
        
 | 
			
		||||
        if (zone.getNetworkType() == NetworkType.Basic) {
 | 
			
		||||
        	throw new InvalidParameterValueException("Network creation is not allowed in zone with network type " + NetworkType.Basic);
 | 
			
		||||
        	//Only one guest network is supported in Basic zone
 | 
			
		||||
        	List<NetworkVO> guestNetworks = _networksDao.listByZoneAndTrafficType(zone.getId(), TrafficType.Guest);
 | 
			
		||||
        	if (!guestNetworks.isEmpty()) {
 | 
			
		||||
            	throw new InvalidParameterValueException("Can't have more than one Guest network in zone with network type " + NetworkType.Basic);
 | 
			
		||||
        	}
 | 
			
		||||
        	
 | 
			
		||||
        	//if zone is basic, only Shared network offerings w/o source nat service are allowed
 | 
			
		||||
        	if (!(networkOffering.getGuestType() == GuestType.Shared && !areServicesSupportedByNetworkOffering(networkOffering.getId(), Service.SourceNat))) {
 | 
			
		||||
        		throw new InvalidParameterValueException("For zone of type " + NetworkType.Basic + " only offerings of guestType " + GuestType.Shared + " with disabled " + Service.SourceNat.getName() + " service are allowed");
 | 
			
		||||
        	}
 | 
			
		||||
            
 | 
			
		||||
        } else if (zone.isSecurityGroupEnabled()) {
 | 
			
		||||
            //Only Account specific Isolated network with sourceNat service disabled are allowed in security group enabled zone
 | 
			
		||||
        	boolean allowCreation = (networkOffering.getGuestType() == GuestType.Isolated && !areServicesSupportedByNetworkOffering(networkOffering.getId(), Service.SourceNat));
 | 
			
		||||
        	if (!allowCreation) {
 | 
			
		||||
        		throw new InvalidParameterValueException("Only Account specific Isolated network with sourceNat service disabled are allowed in security group enabled zone");
 | 
			
		||||
        	}
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        
 | 
			
		||||
        // allow isDefault to be set only for Shared network and Isolated networks with source nat disabled service
 | 
			
		||||
        boolean allowSettingDefault = (networkOffering.getGuestType() == GuestType.Shared || (networkOffering.getGuestType() == GuestType.Isolated && !areServicesSupportedByNetworkOffering(networkOffering.getId(), Service.SourceNat)));
 | 
			
		||||
        boolean allowSettingDefault = (zone.getNetworkType() == NetworkType.Advanced && (networkOffering.getGuestType() == GuestType.Shared || (networkOffering.getGuestType() == GuestType.Isolated && !areServicesSupportedByNetworkOffering(networkOffering.getId(), Service.SourceNat))));
 | 
			
		||||
        if (allowSettingDefault) {
 | 
			
		||||
        	if (isDefault == null) {
 | 
			
		||||
                isDefault = false;
 | 
			
		||||
@ -1934,15 +1924,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
 | 
			
		||||
        } else {
 | 
			
		||||
        	if (isDefault == null) {
 | 
			
		||||
                isDefault = true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Don't allow to create network with vlan that already exists in the system
 | 
			
		||||
        if (vlanId != null) {
 | 
			
		||||
            String uri = "vlan://" + vlanId;
 | 
			
		||||
            List<NetworkVO> networks = _networksDao.listBy(zoneId, uri);
 | 
			
		||||
            if ((networks != null && !networks.isEmpty())) {
 | 
			
		||||
                throw new InvalidParameterValueException("Network with vlan " + vlanId + " already exists in zone " + zoneId);
 | 
			
		||||
            } else {
 | 
			
		||||
            	throw new InvalidParameterValueException("isDefault parameter can be passed in only for network creation of guestType Shared or Isolated with source nat service disabled; and only in Advance zone");
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
         
 | 
			
		||||
@ -1962,6 +1945,16 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
 | 
			
		||||
        	}
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Don't allow to create network with vlan that already exists in the system
 | 
			
		||||
        if (vlanId != null) {
 | 
			
		||||
            String uri = "vlan://" + vlanId;
 | 
			
		||||
            List<NetworkVO> networks = _networksDao.listBy(zoneId, uri);
 | 
			
		||||
            if ((networks != null && !networks.isEmpty())) {
 | 
			
		||||
                throw new InvalidParameterValueException("Network with vlan " + vlanId + " already exists in zone " + zoneId);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
        // If networkDomain is not specified, take it from the global configuration
 | 
			
		||||
        if (areServicesSupportedByNetworkOffering(networkOfferingId, Service.Dns)) {
 | 
			
		||||
            Map<Network.Capability, String> dnsCapabilities = getNetworkOfferingServiceCapabilities(_configMgr.getNetworkOffering(networkOfferingId), Service.Dns);
 | 
			
		||||
@ -1995,13 +1988,18 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Cidr for Shared networks and Isolated networks w/o source nat service can't be NULL - 2.2.x limitation, remove after we introduce support for multiple ip ranges
 | 
			
		||||
        // In Advance zone Cidr for Shared networks and Isolated networks w/o source nat service can't be NULL - 2.2.x limitation, remove after we introduce support for multiple ip ranges
 | 
			
		||||
        // with different Cidrs for the same Shared network
 | 
			
		||||
        boolean cidrRequired = networkOffering.getTrafficType() == TrafficType.Guest && (networkOffering.getGuestType() == GuestType.Shared || (networkOffering.getGuestType() == GuestType.Isolated && !areServicesSupportedByNetworkOffering(networkOffering.getId(), Service.SourceNat)));
 | 
			
		||||
        boolean cidrRequired = zone.getNetworkType() == NetworkType.Advanced && networkOffering.getTrafficType() == TrafficType.Guest && (networkOffering.getGuestType() == GuestType.Shared || (networkOffering.getGuestType() == GuestType.Isolated && !areServicesSupportedByNetworkOffering(networkOffering.getId(), Service.SourceNat)));
 | 
			
		||||
        if (cidr == null && cidrRequired) {
 | 
			
		||||
            throw new InvalidParameterValueException("StartIp/endIp/gateway/netmask are required when create network of type " + Network.GuestType.Shared + " and network of type " + GuestType.Isolated + " with service " + Service.SourceNat.getName() + " disabled");
 | 
			
		||||
        } 
 | 
			
		||||
        
 | 
			
		||||
        //No cidr can be specified in Basic zone
 | 
			
		||||
        if (zone.getNetworkType() == NetworkType.Basic && cidr != null) {
 | 
			
		||||
            throw new InvalidParameterValueException("StartIp/endIp/gateway/netmask can't be specified for zone of type " + NetworkType.Basic);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Check if cidr is RFC1918 compliant if the network is Guest Isolated
 | 
			
		||||
        if (cidr != null && networkOffering.getGuestType() == Network.GuestType.Isolated && networkOffering.getTrafficType() == TrafficType.Guest) {
 | 
			
		||||
            if (!NetUtils.validateGuestCidr(cidr)) {
 | 
			
		||||
@ -3285,6 +3283,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
 | 
			
		||||
        
 | 
			
		||||
        long oldNetworkOfferingId = network.getNetworkOfferingId();
 | 
			
		||||
        if (networkOfferingId != null) {
 | 
			
		||||
        	
 | 
			
		||||
            NetworkOfferingVO networkOffering = _networkOfferingDao.findById(networkOfferingId);
 | 
			
		||||
            if (networkOffering == null || networkOffering.isSystemOnly()) {
 | 
			
		||||
                throw new InvalidParameterValueException("Unable to find network offering by id " + networkOfferingId);
 | 
			
		||||
 | 
			
		||||
@ -90,4 +90,5 @@ public interface NetworkDao extends GenericDao<NetworkVO, Long> {
 | 
			
		||||
	
 | 
			
		||||
	boolean update(Long networkId, NetworkVO network, Map<String, String> serviceProviderMap);
 | 
			
		||||
	
 | 
			
		||||
	List<NetworkVO> listByZoneAndTrafficType(long zoneId, TrafficType trafficType);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -387,4 +387,13 @@ public class NetworkDaoImpl extends GenericDaoBase<NetworkVO, Long> implements N
 | 
			
		||||
        
 | 
			
		||||
        return listBy(sc, null);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<NetworkVO> listByZoneAndTrafficType(long zoneId, TrafficType trafficType) {
 | 
			
		||||
    	SearchCriteria<NetworkVO> sc = AllFieldsSearch.create();
 | 
			
		||||
        sc.setParameters("datacenter", zoneId);
 | 
			
		||||
        sc.setParameters("trafficType", trafficType);
 | 
			
		||||
        
 | 
			
		||||
        return listBy(sc, null);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -589,22 +589,13 @@ public class ElasticLoadBalancerManagerImpl implements
 | 
			
		||||
    
 | 
			
		||||
    @DB
 | 
			
		||||
    public PublicIp allocIp(CreateLoadBalancerRuleCmd lb, Account account) throws InsufficientAddressCapacityException {
 | 
			
		||||
        //TODO: this only works in the guest network. Handle the public network case also.
 | 
			
		||||
        NetworkOfferingVO frontEndOffering = null;
 | 
			
		||||
        if (_frontendTrafficType == TrafficType.Guest) {
 | 
			
		||||
            frontEndOffering = _networkMgr.getExclusiveGuestNetworkOffering();
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        if (frontEndOffering == null) {
 | 
			
		||||
            s_logger.warn("ELB: Could not find offering for direct networks of type " + _frontendTrafficType);
 | 
			
		||||
        //TODO: this only works in the guest network in Basic zone. Handle the public network case also.
 | 
			
		||||
    	List<NetworkVO> networks = _networkDao.listByZoneAndTrafficType(lb.getZoneId(), TrafficType.Guest);
 | 
			
		||||
    	if (networks.isEmpty()) { 
 | 
			
		||||
    		s_logger.warn("Unable to find network with traffic type " + TrafficType.Guest + " in zone id=" + lb.getZoneId());
 | 
			
		||||
    		return null;
 | 
			
		||||
    	}
 | 
			
		||||
    	
 | 
			
		||||
        List<NetworkVO> networks = _networksDao.listBy(Account.ACCOUNT_ID_SYSTEM, frontEndOffering.getId(), lb.getZoneId());
 | 
			
		||||
        if (networks == null || networks.size() == 0) {
 | 
			
		||||
            s_logger.warn("ELB: Could not find network of offering type " + frontEndOffering +  " in zone " + lb.getZoneId());
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
        Network frontEndNetwork = networks.get(0);
 | 
			
		||||
        Transaction txn = Transaction.currentTxn();
 | 
			
		||||
        txn.start();
 | 
			
		||||
 | 
			
		||||
@ -71,7 +71,9 @@ import com.cloud.info.RunningHostInfoAgregator.ZoneHostInfo;
 | 
			
		||||
import com.cloud.network.NetworkManager;
 | 
			
		||||
import com.cloud.network.NetworkVO;
 | 
			
		||||
import com.cloud.network.Networks.TrafficType;
 | 
			
		||||
import com.cloud.network.dao.NetworkDao;
 | 
			
		||||
import com.cloud.offerings.NetworkOfferingVO;
 | 
			
		||||
import com.cloud.offerings.dao.NetworkOfferingDao;
 | 
			
		||||
import com.cloud.resource.ResourceManager;
 | 
			
		||||
import com.cloud.resource.ResourceStateAdapter;
 | 
			
		||||
import com.cloud.resource.ServerResource;
 | 
			
		||||
@ -208,6 +210,11 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
 | 
			
		||||
    protected ResourceManager _resourceMgr;
 | 
			
		||||
    @Inject
 | 
			
		||||
    protected SecondaryStorageVmManager _ssvmMgr;
 | 
			
		||||
    @Inject
 | 
			
		||||
    NetworkDao _networkDao;
 | 
			
		||||
    @Inject
 | 
			
		||||
    NetworkOfferingDao _networkOfferingDao;
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    private long _capacityScanInterval = DEFAULT_CAPACITY_SCAN_INTERVAL;
 | 
			
		||||
 | 
			
		||||
@ -514,19 +521,27 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
 | 
			
		||||
        DataCenterDeployment plan = new DataCenterDeployment(dataCenterId);
 | 
			
		||||
        DataCenter dc = _dcDao.findById(plan.getDataCenterId());
 | 
			
		||||
        
 | 
			
		||||
        NetworkOfferingVO defaultOffering = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemPublicNetwork).get(0);
 | 
			
		||||
 | 
			
		||||
        TrafficType defaultTrafficType = TrafficType.Public;
 | 
			
		||||
        if (dc.getNetworkType() == NetworkType.Basic || dc.isSecurityGroupEnabled()) {
 | 
			
		||||
            defaultOffering = _networkMgr.getExclusiveGuestNetworkOffering();
 | 
			
		||||
        	defaultTrafficType = TrafficType.Guest;
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        List<NetworkVO> defaultNetworks = _networkDao.listByZoneAndTrafficType(dataCenterId, defaultTrafficType);
 | 
			
		||||
        
 | 
			
		||||
        //api should never allow this situation to happen
 | 
			
		||||
        if (defaultNetworks.size() != 1) {
 | 
			
		||||
        	throw new CloudRuntimeException("Found " + defaultNetworks.size() + " networks of type " + defaultTrafficType + " when expect to find 1");
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        NetworkVO defaultNetwork = defaultNetworks.get(0);
 | 
			
		||||
 | 
			
		||||
        List<NetworkOfferingVO> offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemControlNetwork, NetworkOfferingVO.SystemManagementNetwork);
 | 
			
		||||
        List<Pair<NetworkVO, NicProfile>> networks = new ArrayList<Pair<NetworkVO, NicProfile>>(offerings.size() + 1);
 | 
			
		||||
        NicProfile defaultNic = new NicProfile();
 | 
			
		||||
        defaultNic.setDefaultNic(true);
 | 
			
		||||
        defaultNic.setDeviceId(2);
 | 
			
		||||
        try {
 | 
			
		||||
            networks.add(new Pair<NetworkVO, NicProfile>(_networkMgr.setupNetwork(systemAcct, defaultOffering, plan, null, null, false).get(0), defaultNic));
 | 
			
		||||
        	networks.add(new Pair<NetworkVO, NicProfile>(_networkMgr.setupNetwork(systemAcct, _networkOfferingDao.findById(defaultNetwork.getNetworkOfferingId()), null, plan, null, null, false, false, null, null).get(0), defaultNic));
 | 
			
		||||
            for (NetworkOfferingVO offering : offerings) {
 | 
			
		||||
                networks.add(new Pair<NetworkVO, NicProfile>(_networkMgr.setupNetwork(systemAcct, offering, plan, null, null, false).get(0), null));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
@ -655,12 +655,6 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public NetworkOfferingVO getExclusiveGuestNetworkOffering() {
 | 
			
		||||
        // TODO Auto-generated method stub
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<? extends UserDataServiceProvider> getPasswordResetElements() {
 | 
			
		||||
        // TODO Auto-generated method stub
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user