Skip to content

Commit fe2681f

Browse files
author
Alena Prokharchyk
committed
VPC: CS-15725 - don't allow regular offering upgrade to the offering that can be used inside vpc only
Conflicts: server/src/com/cloud/network/NetworkManagerImpl.java
1 parent 807a9ed commit fe2681f

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

‎server/src/com/cloud/configuration/ConfigurationManagerImpl.java‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3356,9 +3356,10 @@ public List<? extends NetworkOffering> searchForNetworkOfferings(ListNetworkOffe
33563356
sc.addAnd("systemOnly", SearchCriteria.Op.EQ, false);
33573357

33583358
// if networkId is specified, list offerings available for upgrade only (for this network)
3359+
Network network = null;
33593360
if (networkId != null) {
33603361
// check if network exists and the caller can operate with it
3361-
Network network = _networkMgr.getNetwork(networkId);
3362+
network = _networkMgr.getNetwork(networkId);
33623363
if (network == null) {
33633364
throw new InvalidParameterValueException("Unable to find the network by id=" + networkId);
33643365
}
@@ -3418,7 +3419,7 @@ public List<? extends NetworkOffering> searchForNetworkOfferings(ListNetworkOffe
34183419
boolean listBySupportedServices = (supportedServicesStr != null && !supportedServicesStr.isEmpty() && !offerings.isEmpty());
34193420
boolean checkIfProvidersAreEnabled = (zoneId != null);
34203421
boolean parseOfferings = (listBySupportedServices || sourceNatSupported != null || checkIfProvidersAreEnabled
3421-
|| forVpc != null);
3422+
|| forVpc != null || network != null);
34223423

34233424
if (parseOfferings) {
34243425
List<NetworkOfferingVO> supportedOfferings = new ArrayList<NetworkOfferingVO>();
@@ -3467,7 +3468,9 @@ public List<? extends NetworkOffering> searchForNetworkOfferings(ListNetworkOffe
34673468
}
34683469

34693470
if (forVpc != null) {
3470-
addOffering = addOffering && (isOfferingForVpc(offering) == forVpc.booleanValue());
3471+
addOffering = addOffering && (isOfferingForVpc(offering) == forVpc.booleanValue());
3472+
} else if (network != null){
3473+
addOffering = addOffering && (isOfferingForVpc(offering) == (network.getVpcId() != null));
34713474
}
34723475

34733476
if (addOffering) {

‎server/src/com/cloud/network/NetworkManagerImpl.java‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4693,6 +4693,15 @@ public Network updateGuestNetwork(long networkId, String name, String displayTex
46934693
throw ex;
46944694
}
46954695

4696+
4697+
//can't update from vpc to non-vpc network offering
4698+
boolean forVpcNew = _configMgr.isOfferingForVpc(networkOffering);
4699+
boolean vorVpcOriginal = _configMgr.isOfferingForVpc(_configMgr.getNetworkOffering(oldNetworkOfferingId));
4700+
if (forVpcNew != vorVpcOriginal) {
4701+
String errMsg = forVpcNew ? "a vpc offering " : "not a vpc offering";
4702+
throw new InvalidParameterValueException("Can't update as the new offering is " + errMsg);
4703+
}
4704+
46964705
//perform below validation if the network is vpc network
46974706
if (network.getVpcId() != null) {
46984707
Vpc vpc = _vpcMgr.getVpc(network.getVpcId());
@@ -4752,7 +4761,7 @@ public Network updateGuestNetwork(long networkId, String name, String displayTex
47524761

47534762
ReservationContext context = new ReservationContextImpl(null, null, callerUser, callerAccount);
47544763
// 1) Shutdown all the elements and cleanup all the rules. Don't allow to shutdown network in intermediate
4755-
// states - Shutdown and Implementing
4764+
// states - Shutdown and Implementing
47564765
boolean validStateToShutdown = (network.getState() == Network.State.Implemented || network.getState() == Network.State.Setup || network.getState() == Network.State.Allocated);
47574766
if (restartNetwork) {
47584767
if (validStateToShutdown) {

0 commit comments

Comments
 (0)