mirror of https://github.com/apache/cloudstack.git
Add checking for specified cidr when create network and update network
This commit is contained in:
parent
e3aa4fb4bb
commit
7aed9ea76d
|
|
@ -286,4 +286,6 @@ public interface Network extends ControlledEntity {
|
|||
void setPhysicalNetworkId(Long physicalNetworkId);
|
||||
|
||||
ACLType getAclType();
|
||||
|
||||
boolean isSpecifiedCidr();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ public class NetworkProfile implements Network {
|
|||
private Network.GuestType guestType;
|
||||
private Long physicalNetworkId;
|
||||
private ACLType aclType;
|
||||
private boolean specifiedCidr;
|
||||
|
||||
public NetworkProfile(Network network) {
|
||||
this.id = network.getId();
|
||||
|
|
@ -70,6 +71,7 @@ public class NetworkProfile implements Network {
|
|||
this.guestType = network.getGuestType();
|
||||
this.physicalNetworkId = network.getPhysicalNetworkId();
|
||||
this.aclType = network.getAclType();
|
||||
this.specifiedCidr = network.isSpecifiedCidr();
|
||||
}
|
||||
|
||||
public String getDns1() {
|
||||
|
|
@ -196,4 +198,14 @@ public class NetworkProfile implements Network {
|
|||
public ACLType getAclType() {
|
||||
return aclType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSpecifiedCidr() {
|
||||
return specifiedCidr;
|
||||
}
|
||||
|
||||
public void setSpecifiedCidr(boolean specifiedCidr) {
|
||||
this.specifiedCidr = specifiedCidr;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -248,6 +248,8 @@ public interface NetworkManager extends NetworkService {
|
|||
boolean getAllowSubdomainAccessGlobal();
|
||||
|
||||
boolean isProviderForNetwork(Provider provider, long networkId);
|
||||
|
||||
boolean isProviderForNetworkOffering(Provider provider, long networkOfferingId);
|
||||
|
||||
void canProviderSupportServices(Map<Provider, Set<Service>> providersMap);
|
||||
|
||||
|
|
|
|||
|
|
@ -1871,6 +1871,10 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
throw new InvalidParameterValueException("Cidr size can't be less than " + _cidrLimit);
|
||||
}
|
||||
}
|
||||
|
||||
if (cidr != null && networkOfferingIsConfiguredForExternalNetworking(networkOfferingId)) {
|
||||
throw new InvalidParameterValueException("Cannot specify CIDR when using network offering with external firewall!");
|
||||
}
|
||||
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
|
|
@ -3112,6 +3116,18 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
}
|
||||
}
|
||||
|
||||
public boolean networkOfferingIsConfiguredForExternalNetworking(long networkOfferingId) {
|
||||
boolean netscalerInNetworkOffering = isProviderForNetworkOffering(Network.Provider.Netscaler, networkOfferingId);
|
||||
boolean juniperInNetworkOffering = isProviderForNetworkOffering(Network.Provider.JuniperSRX, networkOfferingId);
|
||||
boolean f5InNetworkOffering = isProviderForNetworkOffering(Network.Provider.F5BigIp, networkOfferingId);
|
||||
|
||||
if (netscalerInNetworkOffering || juniperInNetworkOffering || f5InNetworkOffering) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areServicesSupportedByNetworkOffering(long networkOfferingId, Service... services) {
|
||||
return (_ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(networkOfferingId, services));
|
||||
|
|
@ -3342,6 +3358,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
}
|
||||
|
||||
if (networkOfferingId != oldNetworkOfferingId) {
|
||||
if (network.isSpecifiedCidr() && networkOfferingIsConfiguredForExternalNetworking(networkOfferingId)) {
|
||||
throw new InvalidParameterValueException("Network offering " + networkOffering + " contained external network elements, can't be upgraded from a CIDR specify network!");
|
||||
}
|
||||
//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");
|
||||
|
|
@ -5094,6 +5113,15 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isProviderForNetworkOffering(Provider provider, long networkOfferingId) {
|
||||
if (_ntwkOfferingSrvcDao.isProviderForNetworkOffering(networkOfferingId, provider)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void canProviderSupportServices(Map<Provider, Set<Service>> providersMap) {
|
||||
for (Provider provider : providersMap.keySet()) {
|
||||
|
|
|
|||
|
|
@ -188,6 +188,7 @@ public class NetworkVO implements Network, Identity {
|
|||
state = State.Allocated;
|
||||
}
|
||||
this.uuid = UUID.randomUUID().toString();
|
||||
this.specifiedCidr = that.isSpecifiedCidr();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -464,6 +465,7 @@ public class NetworkVO implements Network, Identity {
|
|||
return aclType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSpecifiedCidr() {
|
||||
return specifiedCidr;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -108,6 +108,7 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
|
|||
if (userSpecified.getCidr() != null) {
|
||||
config.setCidr(userSpecified.getCidr());
|
||||
config.setGateway(userSpecified.getGateway());
|
||||
config.setSpecifiedCidr(true);
|
||||
}
|
||||
|
||||
if (userSpecified.getBroadcastUri() != null) {
|
||||
|
|
@ -118,7 +119,6 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
|
|||
if (userSpecified.getBroadcastDomainType() != null) {
|
||||
config.setBroadcastDomainType(userSpecified.getBroadcastDomainType());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
boolean isSecurityGroupEnabled = _networkMgr.areServicesSupportedByNetworkOffering(offering.getId(), Service.SecurityGroup);
|
||||
|
|
|
|||
|
|
@ -111,6 +111,7 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
|
|||
if (userSpecified.getCidr() != null) {
|
||||
network.setCidr(userSpecified.getCidr());
|
||||
network.setGateway(userSpecified.getGateway());
|
||||
network.setSpecifiedCidr(true);
|
||||
} else {
|
||||
String guestNetworkCidr = dc.getGuestNetworkCidr();
|
||||
// guest network cidr can be null for Basic zone
|
||||
|
|
@ -125,7 +126,6 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
|
|||
network.setBroadcastUri(userSpecified.getBroadcastUri());
|
||||
network.setState(State.Setup);
|
||||
}
|
||||
network.setSpecifiedCidr(true);
|
||||
} else {
|
||||
String guestNetworkCidr = dc.getGuestNetworkCidr();
|
||||
String[] cidrTuple = guestNetworkCidr.split("\\/");
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package com.cloud.offerings.dao;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.network.Network.Provider;
|
||||
import com.cloud.network.Network.Service;
|
||||
import com.cloud.offerings.NetworkOfferingServiceMapVO;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
|
@ -33,6 +34,7 @@ public interface NetworkOfferingServiceMapDao extends GenericDao<NetworkOffering
|
|||
List<NetworkOfferingServiceMapVO> listByNetworkOfferingId(long networkOfferingId);
|
||||
void deleteByOfferingId(long networkOfferingId);
|
||||
List<String> listProvidersForServiceForNetworkOffering(long networkOfferingId, Service service);
|
||||
boolean isProviderForNetworkOffering(long networkOfferingId, Provider provider);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import javax.ejb.Local;
|
|||
import com.cloud.exception.UnsupportedServiceException;
|
||||
import com.cloud.network.NetworkServiceMapVO;
|
||||
import com.cloud.network.Network.Service;
|
||||
import com.cloud.network.Network.Provider;
|
||||
import com.cloud.offerings.NetworkOfferingServiceMapVO;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
|
|
@ -113,4 +114,17 @@ public class NetworkOfferingServiceMapDaoImpl extends GenericDaoBase<NetworkOffe
|
|||
|
||||
return customSearch(sc, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isProviderForNetworkOffering(long networkOfferingId, Provider provider) {
|
||||
SearchCriteria<NetworkOfferingServiceMapVO> sc = AllFieldsSearch.create();;
|
||||
|
||||
sc.setParameters("networkOfferingId", networkOfferingId);
|
||||
sc.setParameters("provider", provider.getName());
|
||||
|
||||
if (findOneBy(sc) != null) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue