mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
validate conditions before adding/deleting storage network traffic type
This commit is contained in:
parent
ad1076f21d
commit
11b98e4389
@ -193,6 +193,7 @@ import com.cloud.vm.NicProfile;
|
||||
import com.cloud.vm.NicVO;
|
||||
import com.cloud.vm.ReservationContext;
|
||||
import com.cloud.vm.ReservationContextImpl;
|
||||
import com.cloud.vm.SecondaryStorageVmVO;
|
||||
import com.cloud.vm.UserVmVO;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
@ -287,6 +288,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
||||
@Inject AgentManager _agentMgr;
|
||||
@Inject HostDao _hostDao;
|
||||
@Inject NetworkServiceMapDao _ntwkSrvcDao;
|
||||
@Inject StorageNetworkManager _stnwMgr;
|
||||
|
||||
private final HashMap<String, NetworkOfferingVO> _systemNetworks = new HashMap<String, NetworkOfferingVO>(5);
|
||||
|
||||
@ -5198,11 +5200,23 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
||||
//For Storage, Control, Management, Public check if the zone has any other physical network with this traffictype already present
|
||||
//If yes, we cant add these traffics to one more physical network in the zone.
|
||||
|
||||
if(TrafficType.isSystemNetwork(trafficType) || TrafficType.Public.equals(trafficType)){
|
||||
if(TrafficType.isSystemNetwork(trafficType) || TrafficType.Public.equals(trafficType) || TrafficType.Storage.equals(trafficType)){
|
||||
if(!_physicalNetworkDao.listByZoneAndTrafficType(network.getDataCenterId(), trafficType).isEmpty()){
|
||||
throw new CloudRuntimeException("Fail to add the traffic type to physical network because Zone already has a physical network with this traffic type: "+trafficType);
|
||||
}
|
||||
}
|
||||
|
||||
if (TrafficType.Storage.equals(trafficType)) {
|
||||
List<SecondaryStorageVmVO> ssvms = _stnwMgr.getSSVMWithNoStorageNetwork(network.getDataCenterId());
|
||||
if (!ssvms.isEmpty()) {
|
||||
StringBuilder sb = new StringBuilder("Cannot add " + trafficType + " traffic type as there are below secondary storage vm still running. Please stop them all and add Storage traffic type again, then destory them all to allow CloudStack recreate them with storage network(If you have added storage network ip range)");
|
||||
sb.append("SSVMs:");
|
||||
for (SecondaryStorageVmVO ssvm : ssvms) {
|
||||
sb.append(ssvm.getInstanceName()).append(":").append(ssvm.getState());
|
||||
}
|
||||
throw new CloudRuntimeException(sb.toString());
|
||||
}
|
||||
}
|
||||
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
try {
|
||||
@ -5284,7 +5298,12 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
||||
if(!_networksDao.listByPhysicalNetworkTrafficType(trafficType.getPhysicalNetworkId(), trafficType.getTrafficType()).isEmpty()){
|
||||
throw new CloudRuntimeException("The Traffic Type is not deletable because there are existing networks with this traffic type:"+trafficType.getTrafficType());
|
||||
}
|
||||
}
|
||||
} else if (TrafficType.Storage.equals(trafficType.getTrafficType())) {
|
||||
PhysicalNetworkVO pn = _physicalNetworkDao.findById(trafficType.getPhysicalNetworkId());
|
||||
if (_stnwMgr.isAnyStorageIpInUseInZone(pn.getDataCenterId())) {
|
||||
throw new CloudRuntimeException("The Traffic Type is not deletable because there are still some storage network ip addresses in use:"+trafficType.getTrafficType());
|
||||
}
|
||||
}
|
||||
return _pNTrafficTypeDao.remove(id);
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,10 @@
|
||||
package com.cloud.network;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.dc.StorageNetworkIpAddressVO;
|
||||
import com.cloud.utils.component.Manager;
|
||||
import com.cloud.vm.SecondaryStorageVmVO;
|
||||
|
||||
public interface StorageNetworkManager extends Manager {
|
||||
StorageNetworkIpAddressVO acquireIpAddress(long podId);
|
||||
@ -9,4 +12,8 @@ public interface StorageNetworkManager extends Manager {
|
||||
void releaseIpAddress(String ip);
|
||||
|
||||
boolean isStorageIpRangeAvailable();
|
||||
|
||||
List<SecondaryStorageVmVO> getSSVMWithNoStorageNetwork(long zoneId);
|
||||
|
||||
boolean isAnyStorageIpInUseInZone(long zoneId);
|
||||
}
|
||||
|
||||
@ -35,6 +35,10 @@ import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
import com.cloud.vm.SecondaryStorageVmVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.dao.SecondaryStorageVmDao;
|
||||
import com.cloud.vm.dao.VMInstanceDao;
|
||||
|
||||
@Local(value = {StorageNetworkManager.class, StorageNetworkService.class})
|
||||
public class StorageNetworkManagerImpl implements StorageNetworkManager, StorageNetworkService {
|
||||
@ -49,6 +53,8 @@ public class StorageNetworkManagerImpl implements StorageNetworkManager, Storage
|
||||
NetworkDao _networkDao;
|
||||
@Inject
|
||||
HostPodDao _podDao;
|
||||
@Inject
|
||||
SecondaryStorageVmDao _ssvmDao;
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
@ -339,4 +345,21 @@ public class StorageNetworkManagerImpl implements StorageNetworkManager, Storage
|
||||
public boolean isStorageIpRangeAvailable() {
|
||||
return _sNwIpRangeDao.countRanges() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SecondaryStorageVmVO> getSSVMWithNoStorageNetwork(long zoneId) {
|
||||
List<SecondaryStorageVmVO> ssvms = _ssvmDao.getSecStorageVmListInStates(null, zoneId, VirtualMachine.State.Starting, VirtualMachine.State.Running, VirtualMachine.State.Stopping);
|
||||
return ssvms;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnyStorageIpInUseInZone(long zoneId) {
|
||||
List<StorageNetworkIpRangeVO> ranges = _sNwIpRangeDao.listByDataCenterId(zoneId);
|
||||
for (StorageNetworkIpRangeVO r : ranges) {
|
||||
if (_sNwIpDao.countInUseIpByRangeId(r.getId()) > 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user