From c0b58130d34d4a2b6e7619dba3fe4d33d561bc1a Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Fri, 27 Jul 2012 11:28:42 -0700 Subject: [PATCH] VPC: CS-15725 - don't allow regular offering upgrade to the offering that can be used inside vpc only --- .../cloud/configuration/ConfigurationManagerImpl.java | 9 ++++++--- server/src/com/cloud/network/NetworkManagerImpl.java | 10 +++++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index c9fc65cb477..191ebde33b8 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -3400,9 +3400,10 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura sc.addAnd("systemOnly", SearchCriteria.Op.EQ, false); // if networkId is specified, list offerings available for upgrade only (for this network) + Network network = null; if (networkId != null) { // check if network exists and the caller can operate with it - Network network = _networkMgr.getNetwork(networkId); + network = _networkMgr.getNetwork(networkId); if (network == null) { throw new InvalidParameterValueException("Unable to find the network by id", null); } @@ -3462,7 +3463,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura boolean listBySupportedServices = (supportedServicesStr != null && !supportedServicesStr.isEmpty() && !offerings.isEmpty()); boolean checkIfProvidersAreEnabled = (zoneId != null); boolean parseOfferings = (listBySupportedServices || sourceNatSupported != null || checkIfProvidersAreEnabled - || forVpc != null); + || forVpc != null || network != null); if (parseOfferings) { List supportedOfferings = new ArrayList(); @@ -3511,7 +3512,9 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura } if (forVpc != null) { - addOffering = addOffering && (isOfferingForVpc(offering) == forVpc.booleanValue()); + addOffering = addOffering && (isOfferingForVpc(offering) == forVpc.booleanValue()); + } else if (network != null){ + addOffering = addOffering && (isOfferingForVpc(offering) == (network.getVpcId() != null)); } if (addOffering) { diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index b4381b3a121..9bb2ae3c147 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -4668,6 +4668,14 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag idList.add(new IdentityProxy(networkOffering, networkOfferingId, "networkOfferingId")); throw new InvalidParameterValueException("Network offering with specified id is not in " + NetworkOffering.State.Enabled + " state, can't upgrade to it", idList); } + + //can't update from vpc to non-vpc network offering + boolean forVpcNew = _configMgr.isOfferingForVpc(networkOffering); + boolean vorVpcOriginal = _configMgr.isOfferingForVpc(_configMgr.getNetworkOffering(oldNetworkOfferingId)); + if (forVpcNew != vorVpcOriginal) { + String errMsg = forVpcNew ? "a vpc offering " : "not a vpc offering"; + throw new InvalidParameterValueException("Can't update as the new offering is " + errMsg); + } //perform below validation if the network is vpc network if (network.getVpcId() != null) { @@ -4730,7 +4738,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag ReservationContext context = new ReservationContextImpl(null, null, callerUser, callerAccount); // 1) Shutdown all the elements and cleanup all the rules. Don't allow to shutdown network in intermediate -// states - Shutdown and Implementing + // states - Shutdown and Implementing boolean validStateToShutdown = (network.getState() == Network.State.Implemented || network.getState() == Network.State.Setup || network.getState() == Network.State.Allocated); if (restartNetwork) { if (validStateToShutdown) {