Fixed vm deployment in Basic zone

This commit is contained in:
alena 2011-11-02 17:02:29 -07:00
parent f42c9e434f
commit 3e20c60d6d
12 changed files with 66 additions and 33 deletions

View File

@ -105,7 +105,7 @@ public class AssociateIPAddrCmd extends BaseAsyncCreateCmd {
assert (networks.size() <= 1) : "Too many virtual networks. This logic should be obsolete";
return networks.get(0).getId();
} else {
Network defaultGuestNetwork = _networkService.getSystemNetworkByZoneAndTrafficType(zone.getId(), TrafficType.Guest);
Network defaultGuestNetwork = _networkService.getExclusiveGuestNetwork(zoneId);
if (defaultGuestNetwork == null) {
throw new InvalidParameterValueException("Unable to find a default Guest network for account " + getAccountName() + " in domain id=" + getDomainId());
} else {

View File

@ -34,7 +34,6 @@ import com.cloud.network.Network.Capability;
import com.cloud.network.Network.Provider;
import com.cloud.network.Network.Service;
import com.cloud.network.Networks.TrafficType;
import com.cloud.offering.NetworkOffering;
import com.cloud.user.Account;
public interface NetworkService {
@ -127,4 +126,6 @@ public interface NetworkService {
List<? extends PhysicalNetworkTrafficType> listTrafficTypes(Long physicalNetworkId);
PhysicalNetwork getDefaultPhysicalNetworkByZoneAndTrafficType(long zoneId, TrafficType trafficType);
Network getExclusiveGuestNetwork(long zoneId);
}

View File

@ -305,7 +305,7 @@ public class BareMetalVmManagerImpl extends UserVmManagerImpl implements BareMet
s_logger.warn("Bare Metal only supports basical network mode now, switch to baisc network automatically");
}
Network defaultNetwork = _networkMgr.getSystemNetworkByZoneAndTrafficType(dc.getId(), TrafficType.Guest);
Network defaultNetwork = _networkMgr.getExclusiveGuestNetwork(dc.getId());
if (defaultNetwork == null) {
throw new InvalidParameterValueException("Unable to find a default network to start a vm");
}

View File

@ -1941,7 +1941,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
} else {
if (network == null) {
if (zone.getNetworkType() == DataCenter.NetworkType.Basic) {
networkId = _networkMgr.getSystemNetworkByZoneAndTrafficType(zoneId, TrafficType.Guest).getId();
networkId = _networkMgr.getExclusiveGuestNetwork(zoneId).getId();
} else {
network = _networkMgr.getNetworkWithSecurityGroupEnabled(zoneId);
if (network == null) {

View File

@ -546,10 +546,10 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
Account systemAcct = _accountMgr.getSystemAccount();
DataCenterDeployment plan = new DataCenterDeployment(dataCenterId);
List<NetworkOfferingVO> defaultOffering = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemPublicNetwork);
NetworkOfferingVO defaultOffering = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemPublicNetwork).get(0);
if (dc.getNetworkType() == NetworkType.Basic || dc.isSecurityGroupEnabled()) {
defaultOffering.add(_networkMgr.getExclusiveGuestNetworkOffering());
defaultOffering = _networkMgr.getExclusiveGuestNetworkOffering();
}
List<NetworkOfferingVO> offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemControlNetwork, NetworkOfferingVO.SystemManagementNetwork);
@ -557,7 +557,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
NicProfile defaultNic = new NicProfile();
defaultNic.setDefaultNic(true);
defaultNic.setDeviceId(2);
networks.add(new Pair<NetworkVO, NicProfile>(_networkMgr.setupNetwork(systemAcct, defaultOffering.get(0), plan, null, null, false, false).get(0), defaultNic));
networks.add(new Pair<NetworkVO, NicProfile>(_networkMgr.setupNetwork(systemAcct, defaultOffering, plan, null, null, false, false).get(0), defaultNic));
for (NetworkOfferingVO offering : offerings) {
networks.add(new Pair<NetworkVO, NicProfile>(_networkMgr.setupNetwork(systemAcct, offering, plan, null, null, false, false).get(0), null));
}

View File

@ -40,7 +40,6 @@ import com.cloud.network.element.UserDataServiceProvider;
import com.cloud.network.guru.NetworkGuru;
import com.cloud.network.rules.FirewallRule;
import com.cloud.network.rules.StaticNat;
import com.cloud.offering.NetworkOffering;
import com.cloud.offerings.NetworkOfferingVO;
import com.cloud.user.Account;
import com.cloud.utils.Pair;
@ -229,7 +228,7 @@ public interface NetworkManager extends NetworkService {
boolean isProviderAvailable(long physicalNetowrkId, String providerName);
boolean isServiceEnabled(Long physicalNetworkId, long networkOfferingId, Service service);
boolean isServiceEnabled(long physicalNetworkId, long networkOfferingId, Service service);
List<String> getNetworkTags(HypervisorType hType, Network network);

View File

@ -1377,11 +1377,13 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
// associate a source NAT IP (if one isn't already associated with the network)
boolean sharedSourceNat = false;
Map<Network.Capability, String> sourceNatCapabilities = getServiceCapabilities(network.getNetworkOfferingId(), Service.SourceNat);
if (sourceNatCapabilities != null) {
String supportedSourceNatTypes = sourceNatCapabilities.get(Capability.SupportedSourceNatTypes).toLowerCase();
if (supportedSourceNatTypes.contains("zone")) {
sharedSourceNat = true;
if (isServiceSupportedByNetworkOffering(network.getNetworkOfferingId(), Service.SourceNat)) {
Map<Network.Capability, String> sourceNatCapabilities = getServiceCapabilities(network.getNetworkOfferingId(), Service.SourceNat);
if (sourceNatCapabilities != null) {
String supportedSourceNatTypes = sourceNatCapabilities.get(Capability.SupportedSourceNatTypes).toLowerCase();
if (supportedSourceNatTypes.contains("zone")) {
sharedSourceNat = true;
}
}
}
@ -1491,7 +1493,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
element.prepare(network, profile, vmProfile, dest, context);
}
profile.setSecurityGroupEnabled(isServiceEnabled(network.getPhysicalNetworkId(), network.getNetworkOfferingId(), Service.SecurityGroup));
profile.setSecurityGroupEnabled(isSecurityGroupSupportedInNetwork(network));
guru.updateNicProfile(profile, network);
vmProfile.addNic(profile);
}
@ -4407,9 +4409,14 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
@Override
public boolean isSecurityGroupSupportedInNetwork(Network network) {
boolean supported = isServiceEnabled(network.getPhysicalNetworkId(), network.getNetworkOfferingId(), Service.SecurityGroup);
Long physicalNetworkId = network.getPhysicalNetworkId();
return supported;
//physical network id can be null in Guest Network in Basic zone, so locate the physical network
if (physicalNetworkId == null) {
physicalNetworkId = findPhysicalNetworkId(network.getDataCenterId(), null);
}
return isServiceEnabled(physicalNetworkId, network.getNetworkOfferingId(), Service.SecurityGroup);
}
@Override
@ -4603,7 +4610,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
}
@Override
public boolean isServiceEnabled(Long physicalNetworkId, long networkOfferingId, Service service) {
public boolean isServiceEnabled(long physicalNetworkId, long networkOfferingId, Service service) {
//check if the service is supported by the network offering
if (!isServiceSupportedByNetworkOffering(networkOfferingId, service)) {
s_logger.debug("Service " + service.getName() + " is not supported by the network offering id=" + networkOfferingId);
@ -4611,13 +4618,11 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
}
//get providers for the service and check if all of them are supported
if (physicalNetworkId != null) {
List<String> providers = _ntwkOfferingSrvcDao.getProvidersForService(networkOfferingId, service);
for (String provider : providers) {
if (!isProviderAvailable(physicalNetworkId, provider)) {
s_logger.debug("Provider " + provider + " is not enabled in physical network id=" + physicalNetworkId);
return false;
}
List<String> providers = _ntwkOfferingSrvcDao.getProvidersForService(networkOfferingId, service);
for (String provider : providers) {
if (!isProviderAvailable(physicalNetworkId, provider)) {
s_logger.debug("Provider " + provider + " is not enabled in physical network id=" + physicalNetworkId);
return false;
}
}
@ -4654,4 +4659,20 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
return new ArrayList<String>();
}
@Override
public NetworkVO getExclusiveGuestNetwork(long zoneId) {
List<NetworkVO> networks = _networksDao.listBy(Account.ACCOUNT_ID_SYSTEM, zoneId, GuestType.Shared, TrafficType.Guest);
if (networks == null || networks.isEmpty()) {
throw new InvalidParameterValueException("Unable to find network with trafficType " + TrafficType.Guest + " and guestType " + GuestType.Shared + " in zone " + zoneId);
}
if (networks.size() > 1) {
throw new InvalidParameterValueException("Found more than 1 network with trafficType " + TrafficType.Guest + " and guestType " + GuestType.Shared + " in zone " + zoneId);
}
return networks.get(0);
}
}

View File

@ -75,4 +75,6 @@ public interface NetworkDao extends GenericDao<NetworkVO, Long> {
List<NetworkVO> listSecurityGroupEnabledNetworks();
List<NetworkVO> listByPhysicalNetworkTrafficType(long physicalNetworkId, TrafficType trafficType);
List<NetworkVO> listBy(long accountId, long dataCenterId, Network.GuestType type, TrafficType trafficType);
}

View File

@ -370,5 +370,14 @@ public class NetworkDaoImpl extends GenericDaoBase<NetworkVO, Long> implements N
return listBy(sc);
}
@Override
public List<NetworkVO> listBy(long accountId, long dataCenterId, Network.GuestType type, TrafficType trafficType) {
SearchCriteria<NetworkVO> sc = AllFieldsSearch.create();
sc.setParameters("datacenter", dataCenterId);
sc.setParameters("account", accountId);
sc.setParameters("guestType", type);
sc.setParameters("trafficType", trafficType);
return listBy(sc, null);
}
}

View File

@ -34,6 +34,7 @@ import com.cloud.exception.InsufficientVirtualNetworkCapcityException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.network.IPAddressVO;
import com.cloud.network.Network;
import com.cloud.network.Network.GuestType;
import com.cloud.network.Network.Service;
import com.cloud.network.Network.State;
import com.cloud.network.NetworkManager;
@ -99,7 +100,7 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
}
State state = State.Allocated;
if (offering.isSystemOnly()) {
if (dc.getNetworkType() == NetworkType.Basic) {
state = State.Setup;
}

View File

@ -492,10 +492,10 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
DataCenterDeployment plan = new DataCenterDeployment(dataCenterId);
DataCenter dc = _dcDao.findById(plan.getDataCenterId());
List<NetworkOfferingVO> defaultOffering = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemPublicNetwork);
NetworkOfferingVO defaultOffering = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemPublicNetwork).get(0);
if (dc.getNetworkType() == NetworkType.Basic || dc.isSecurityGroupEnabled()) {
defaultOffering.add(_networkMgr.getExclusiveGuestNetworkOffering());
defaultOffering = _networkMgr.getExclusiveGuestNetworkOffering();
}
List<NetworkOfferingVO> offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemControlNetwork, NetworkOfferingVO.SystemManagementNetwork);
@ -504,7 +504,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
defaultNic.setDefaultNic(true);
defaultNic.setDeviceId(2);
try {
networks.add(new Pair<NetworkVO, NicProfile>(_networkMgr.setupNetwork(systemAcct, defaultOffering.get(0), plan, null, null, false, false).get(0), defaultNic));
networks.add(new Pair<NetworkVO, NicProfile>(_networkMgr.setupNetwork(systemAcct, defaultOffering, plan, null, null, false, false).get(0), defaultNic));
for (NetworkOfferingVO offering : offerings) {
networks.add(new Pair<NetworkVO, NicProfile>(_networkMgr.setupNetwork(systemAcct, offering, plan, null, null, false, false).get(0), null));
}

View File

@ -1996,7 +1996,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
_accountMgr.checkAccess(caller, null, owner);
// Get default guest network in Basic zone
Network defaultNetwork = _networkMgr.getSystemNetworkByZoneAndTrafficType(zone.getId(), TrafficType.Guest);
Network defaultNetwork = _networkMgr.getExclusiveGuestNetwork(zone.getId());
if (defaultNetwork == null) {
throw new InvalidParameterValueException("Unable to find a default network to start a vm");
@ -2097,7 +2097,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
throw new InvalidParameterValueException("Unable to find network by id " + networkIdList.get(0).longValue());
}
boolean isSecurityGroupEnabled = _networkMgr.isServiceEnabled(network.getPhysicalNetworkId(), network.getNetworkOfferingId(), Service.SecurityGroup);
boolean isSecurityGroupEnabled = _networkMgr.isSecurityGroupSupportedInNetwork(network);
if (isSecurityGroupEnabled && networkIdList.size() > 1) {
throw new InvalidParameterValueException("Can't create a vm with multiple networks one of which is Security Group enabled");
}
@ -2421,7 +2421,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
networks.add(new Pair<NetworkVO, NicProfile>(network, profile));
if (_networkMgr.isServiceEnabled(network.getPhysicalNetworkId(), network.getNetworkOfferingId(), Service.SecurityGroup)) {
if (_networkMgr.isSecurityGroupSupportedInNetwork(network)) {
securityGroupEnabled = true;
}
}