Add "changecidr" parameter for updateNetwork API

CIDR may be different after update to a service offering contained external
network element, user is required to acknowledge this, otherwise the update
won't process
This commit is contained in:
Sheng Yang 2012-02-08 15:09:36 -08:00
parent 9317eb6bc3
commit fadec7afe7
5 changed files with 18 additions and 6 deletions

View File

@ -331,6 +331,7 @@ public class ApiConstants {
public static final String IS_SOURCE_NAT = "issourcenat";
public static final String IS_STATIC_NAT = "isstaticnat";
public static final String SORT_BY = "sortby";
public static final String CHANGE_CIDR = "changecidr";
public enum HostDetails {
all, capacity, events, stats, min;

View File

@ -59,6 +59,9 @@ public class UpdateNetworkCmd extends BaseAsyncCmd {
@Parameter(name=ApiConstants.NETWORK_DOMAIN, type=CommandType.STRING, description="network domain")
private String networkDomain;
@Parameter(name=ApiConstants.CHANGE_CIDR, type=CommandType.BOOLEAN, description="Force update even if cidr type is different")
private Boolean changeCidr;
@IdentityMapper(entityTableName="network_offerings")
@Parameter(name=ApiConstants.NETWORK_OFFERING_ID, type=CommandType.LONG, description="network offering ID")
private Long networkOfferingId;
@ -86,7 +89,13 @@ public class UpdateNetworkCmd extends BaseAsyncCmd {
private Long getNetworkOfferingId() {
return networkOfferingId;
}
public Boolean getChangeCidr() {
if (changeCidr != null) {
return changeCidr;
}
return false;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@ -110,7 +119,7 @@ public class UpdateNetworkCmd extends BaseAsyncCmd {
public void execute() throws InsufficientCapacityException, ConcurrentOperationException{
User callerUser = _accountService.getActiveUser(UserContext.current().getCallerUserId());
Account callerAccount = _accountService.getActiveAccountById(callerUser.getAccountId());
Network result = _networkService.updateGuestNetwork(getId(), getNetworkName(), getDisplayText(), callerAccount, callerUser, getNetworkDomain(), getNetworkOfferingId());
Network result = _networkService.updateGuestNetwork(getId(), getNetworkName(), getDisplayText(), callerAccount, callerUser, getNetworkDomain(), getNetworkOfferingId(), getChangeCidr());
if (result != null) {
NetworkResponse response = _responseGenerator.createNetworkResponse(result);
response.setResponseName(getCommandName());

View File

@ -79,7 +79,7 @@ public interface NetworkService {
Long getDedicatedNetworkDomain(long networkId);
Network updateGuestNetwork(long networkId, String name, String displayText, Account callerAccount, User callerUser, String domainSuffix, Long networkOfferingId);
Network updateGuestNetwork(long networkId, String name, String displayText, Account callerAccount, User callerUser, String domainSuffix, Long networkOfferingId, Boolean changeCidr);
Integer getNetworkRate(long networkId, Long vmId);

View File

@ -50,6 +50,7 @@ import com.cloud.network.rules.StaticNat;
import com.cloud.offering.NetworkOffering;
import com.cloud.offerings.NetworkOfferingVO;
import com.cloud.user.Account;
import com.cloud.user.User;
import com.cloud.utils.Pair;
import com.cloud.vm.Nic;
import com.cloud.vm.NicProfile;

View File

@ -3852,7 +3852,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_NETWORK_UPDATE, eventDescription = "updating network", async = true)
public Network updateGuestNetwork(long networkId, String name, String displayText, Account callerAccount, User callerUser, String domainSuffix, Long networkOfferingId) {
public Network updateGuestNetwork(long networkId, String name, String displayText, Account callerAccount, User callerUser, String domainSuffix, Long networkOfferingId, Boolean changeCidr) {
boolean restartNetwork = false;
// verify input parameters
@ -3908,8 +3908,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
}
if (networkOfferingId != oldNetworkOfferingId) {
if (networkOfferingIsConfiguredForExternalNetworking(networkOfferingId)) {
throw new InvalidParameterValueException("Network offering " + networkOffering + " contained external network elements, can't be upgraded from a CIDR specify network!");
if (networkOfferingIsConfiguredForExternalNetworking(networkOfferingId) != networkOfferingIsConfiguredForExternalNetworking(oldNetworkOfferingId)
&& !changeCidr) {
throw new InvalidParameterValueException("Network offerings contained external network elements, need user agree to change CIDR!");
}
// check if the network is upgradable
if (!canUpgrade(network, oldNetworkOfferingId, networkOfferingId)) {