mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 20:02:29 +01:00
Don't allow to remove a network with deleteNetwork api when the network has active nics assigned
This commit is contained in:
parent
21bb9df292
commit
724b8d80bd
@ -26,6 +26,7 @@ import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.api.response.SuccessResponse;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
|
||||
@Implementation(description="Deletes a network", responseObject=SuccessResponse.class)
|
||||
public class DeleteNetworkCmd extends BaseCmd{
|
||||
@ -60,6 +61,11 @@ public class DeleteNetworkCmd extends BaseCmd{
|
||||
|
||||
@Override
|
||||
public void execute(){
|
||||
//Don't allow to delete network via api call when it has vms assigned to it
|
||||
int nicCount = _networkService.getActiveNicsInNetwork(id);
|
||||
if (nicCount > 0) {
|
||||
throw new InvalidParameterValueException("Unable to remove the network id=" + id + " as it has active Nics.");
|
||||
}
|
||||
boolean result = _networkService.deleteNetwork(id);
|
||||
if (result) {
|
||||
SuccessResponse response = new SuccessResponse(getCommandName());
|
||||
|
||||
@ -88,4 +88,6 @@ public interface NetworkService {
|
||||
boolean deleteNetwork(long networkId) throws InvalidParameterValueException, PermissionDeniedException;
|
||||
|
||||
boolean restartNetwork(RestartNetworkCmd cmd) throws ConcurrentOperationException;
|
||||
|
||||
int getActiveNicsInNetwork(long networkId);
|
||||
}
|
||||
|
||||
@ -2116,4 +2116,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getActiveNicsInNetwork(long networkId) {
|
||||
return _networksDao.getActiveNicsIn(networkId);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user