diff --git a/api/src/com/cloud/api/commands/DeployVMCmd.java b/api/src/com/cloud/api/commands/DeployVMCmd.java index 2d86dbcb759..9803f4fcaa5 100644 --- a/api/src/com/cloud/api/commands/DeployVMCmd.java +++ b/api/src/com/cloud/api/commands/DeployVMCmd.java @@ -230,14 +230,6 @@ public class DeployVMCmd extends BaseAsyncCreateCmd { return hostId; } - private String getIpAddress() { - return ipAddress; - } - - private String getKeyboard() { - return keyboard; - } - private Map getIpToNetworkMap() { if ((networkIds != null || ipAddress != null) && ipToNetworkList != null) { throw new InvalidParameterValueException("NetworkIds and ipAddress can't be specified along with ipToNetworkMap parameter"); diff --git a/api/src/com/cloud/api/commands/UpdateNetworkCmd.java b/api/src/com/cloud/api/commands/UpdateNetworkCmd.java index 142beb1c383..a431de207f7 100644 --- a/api/src/com/cloud/api/commands/UpdateNetworkCmd.java +++ b/api/src/com/cloud/api/commands/UpdateNetworkCmd.java @@ -60,7 +60,7 @@ public class UpdateNetworkCmd extends BaseAsyncCmd { @Parameter(name=ApiConstants.NETWORK_DOMAIN, type=CommandType.STRING, description="network domain") private String networkDomain; - @Parameter(name=ApiConstants.NETWORK_OFFERING_ID, type=CommandType.LONG, description="network offering ID") + @Parameter(name=ApiConstants.NETWORK_OFFERING_ID, type=CommandType.LONG, description="network offering ID - upgrade network to the new network offering") private Long networkOfferingId; ///////////////////////////////////////////////////// diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 5de0ecf2b54..d7e003502f2 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -147,7 +147,6 @@ import com.cloud.utils.db.Transaction; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.net.Ip; import com.cloud.utils.net.NetUtils; -import com.cloud.vm.DomainRouterVO; import com.cloud.vm.Nic; import com.cloud.vm.NicProfile; import com.cloud.vm.NicVO; @@ -3071,9 +3070,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } _accountMgr.checkAccess(caller, null, network); - // Don't allow to update system network - make an exception for the Guest network in Basic zone + // Don't allow to update system network NetworkOffering offering = _networkOfferingDao.findByIdIncludingRemoved(network.getNetworkOfferingId()); - if (offering.isSystemOnly() && network.getTrafficType() != TrafficType.Guest) { + if (offering.isSystemOnly()) { throw new InvalidParameterValueException("Can't update system networks"); } @@ -3093,12 +3092,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag throw new InvalidParameterValueException("Domain name change is not supported for network id=" + network.getNetworkOfferingId() + " in zone id=" + network.getDataCenterId()); } - //restart network if it has active network elements - List routers = _routerDao.listActive(networkId); - if (!routers.isEmpty()) { - restartNetwork = true; - } network.setNetworkDomain(domainSuffix); + //have to restart the network + restartNetwork = true; } if (name != null) { @@ -3119,15 +3115,19 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (networkOffering == null || networkOffering.isSystemOnly()) { throw new InvalidParameterValueException("Unable to find network offering by id " + networkOfferingId); } - if (networkOffering.getAvailability() == Availability.Unavailable) { - throw new InvalidParameterValueException("Can't update network; network offering id=" + networkOfferingId + " is " + networkOffering.getAvailability()); + if (networkOffering.getAvailability() == Availability.Unavailable || networkOffering.getState() == NetworkOffering.State.Disabled || networkOffering.getState() == NetworkOffering.State.Inactive) { + throw new InvalidParameterValueException("Can't update network; network offering id=" + networkOfferingId + " is " + networkOffering.getAvailability() + " and " + networkOffering.getState()); } - network.setNetworkOfferingId(networkOfferingId); - } - - if ((networkOfferingId != 0) && (networkOfferingId != oldNetworkOfferingId)) { - restartNetwork = true; - } + + if (networkOfferingId != oldNetworkOfferingId) { + //check if the network is upgradable + if (!canUpgrade(oldNetworkOfferingId, networkOfferingId)) { + throw new InvalidParameterValueException("Can't upgrade from network offering " + oldNetworkOfferingId + " to " + networkOfferingId + "; check logs for more information"); + } + network.setNetworkOfferingId(networkOfferingId); + restartNetwork = true; + } + } boolean success = _networksDao.update(networkId, network); @@ -3344,4 +3344,54 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag public boolean isProviderSupported(long networkOfferingId, Service service, Provider provider){ return _ntwkOfferingSrvcDao.isProviderSupported(networkOfferingId, service, provider); } + + protected boolean canUpgrade(long oldNetworkOfferingId, long newNetworkOfferingId) { + NetworkOffering oldNetworkOffering = _networkOfferingDao.findByIdIncludingRemoved(oldNetworkOfferingId); + NetworkOffering newNetworkOffering = _networkOfferingDao.findById(newNetworkOfferingId); + + //security group property should be the same + if (oldNetworkOffering.isSecurityGroupEnabled() != newNetworkOffering.isSecurityGroupEnabled()) { + s_logger.debug("Offerings " + newNetworkOfferingId + " and " + oldNetworkOfferingId + " have different securityGroupProperty, can't upgrade"); + return false; + } + + //Type of the network should be the same + if (oldNetworkOffering.getType() != newNetworkOffering.getType()){ + s_logger.debug("Network offerings " + newNetworkOfferingId + " and " + oldNetworkOfferingId + " are of different types, can't upgrade"); + return false; + } + + //Traffic types should be the same + if (oldNetworkOffering.getTrafficType() != newNetworkOffering.getTrafficType()) { + s_logger.debug("Network offerings " + newNetworkOfferingId + " and " + oldNetworkOfferingId + " have different traffic types, can't upgrade"); + return false; + } + + //list of services and providers should be the same + Map> newServices = listNetworkOfferingServices(newNetworkOfferingId); + Map> oldServices = listNetworkOfferingServices(oldNetworkOfferingId); + + if (newServices.size() != oldServices.size()) { + s_logger.debug("Number of supported services is not the same for offering " + newNetworkOfferingId + " and " + oldNetworkOfferingId); + return false; + } + + for (String service : newServices.keySet()) { + Set newProviders = newServices.get(service); + Set oldProviders = oldServices.get(service); + if (newProviders.size() != oldProviders.size()) { + s_logger.debug("Number of providers for the service " + service + " is not the same for offering " + newNetworkOfferingId + " and " + oldNetworkOfferingId); + return false; + } + + for (String provider : newProviders) { + if (!oldProviders.contains(provider)) { + s_logger.debug("Providers are different for the " + service + " is not the same for offering " + newNetworkOfferingId + " and " + oldNetworkOfferingId); + return false; + } + } + } + + return true; + } } diff --git a/server/src/com/cloud/network/guru/DirectPodBasedNetworkGuru.java b/server/src/com/cloud/network/guru/DirectPodBasedNetworkGuru.java index a7ee89f211f..4c8fd1daac2 100644 --- a/server/src/com/cloud/network/guru/DirectPodBasedNetworkGuru.java +++ b/server/src/com/cloud/network/guru/DirectPodBasedNetworkGuru.java @@ -19,7 +19,6 @@ package com.cloud.network.guru; import java.net.URI; -import java.util.List; import javax.ejb.Local; @@ -80,7 +79,7 @@ public class DirectPodBasedNetworkGuru extends DirectNetworkGuru { @Override protected boolean canHandle(NetworkOffering offering, DataCenter dc) { // this guru handles system Direct pod based network - if (dc.getNetworkType() == NetworkType.Basic && offering.getTrafficType() == TrafficType.Guest && offering.isSystemOnly()) { + if (dc.getNetworkType() == NetworkType.Basic && offering.getTrafficType() == TrafficType.Guest && offering.isSecurityGroupEnabled()) { return true; } else { s_logger.trace("We only take care of Guest Direct Pod based networks"); diff --git a/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java b/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java index 9e16c53eada..b2e91f71f83 100644 --- a/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java +++ b/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java @@ -246,7 +246,6 @@ public class ExternalGuestNetworkGuru extends GuestNetworkGuru { } else { super.reserve(nic, config, vm, dest, context); } - } @Override diff --git a/server/src/com/cloud/offerings/NetworkOfferingVO.java b/server/src/com/cloud/offerings/NetworkOfferingVO.java index 6b09cc52de6..27823837b3f 100644 --- a/server/src/com/cloud/offerings/NetworkOfferingVO.java +++ b/server/src/com/cloud/offerings/NetworkOfferingVO.java @@ -30,6 +30,7 @@ import javax.persistence.Table; import com.cloud.network.Network; import com.cloud.network.Network.GuestIpType; +import com.cloud.network.Network.Type; import com.cloud.network.Networks.TrafficType; import com.cloud.offering.NetworkOffering; import com.cloud.utils.db.GenericDao; @@ -260,6 +261,7 @@ public class NetworkOfferingVO implements NetworkOffering { public NetworkOfferingVO(String name, TrafficType trafficType) { this(name, "System Offering for " + name, trafficType, true, false, 0, 0, null, true, Availability.Required, null, null, false, null); this.state = State.Enabled; + this.type = Type.Shared; } @Override