diff --git a/core/src/com/cloud/server/ManagementServer.java b/core/src/com/cloud/server/ManagementServer.java index 60b2b7a3f1d..c3794a40303 100755 --- a/core/src/com/cloud/server/ManagementServer.java +++ b/core/src/com/cloud/server/ManagementServer.java @@ -2200,4 +2200,5 @@ public interface ManagementServer { VolumeVO findVolumeByInstanceAndDeviceId(long instanceId, long deviceId); VolumeVO getRootVolume(Long instanceId); long getPsMaintenanceCount(long podId); + boolean isPoolUp(long instanceId); } diff --git a/server/src/com/cloud/api/commands/StartVMCmd.java b/server/src/com/cloud/api/commands/StartVMCmd.java index 6c70304d573..7f4af063117 100644 --- a/server/src/com/cloud/api/commands/StartVMCmd.java +++ b/server/src/com/cloud/api/commands/StartVMCmd.java @@ -78,7 +78,10 @@ public class StartVMCmd extends BaseCmd { throw new ServerApiException(BaseCmd.PARAM_ERROR, "Invalid virtual machine id (" + vmId + ") given, unable to start virtual machine."); } } - + + if(!getManagementServer().isPoolUp(vmId)){ + throw new ServerApiException(BaseCmd.INTERNAL_ERROR,"Storage pool for this vm is under maintenance"); + } if (userId == null) { userId = Long.valueOf(1); } diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index c12c146badf..66b5518dfa6 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -1762,11 +1762,22 @@ public class ManagementServerImpl implements ManagementServer { // Check that there is a shared primary storage pool in the specified zone List storagePools = _poolDao.listByDataCenterId(zoneId); + boolean sharedPoolExists = false; + boolean readyPoolExists = false; for (StoragePoolVO storagePool : storagePools) { if (storagePool.isShared()) { sharedPoolExists = true; } + //check if there are any pools in the UP state + //if not, throw an error + if(storagePool.getStatus().equals(Status.Up)){ + readyPoolExists = true; + } + } + + if(!readyPoolExists){ + throw new InternalErrorException("There are no ready pools for volume creation"); } // Check that there is at least one host in the specified zone @@ -8729,5 +8740,21 @@ public class ManagementServerImpl implements ManagementServer { else return poolsInMaintenance.size(); } + + @Override + public boolean isPoolUp(long instanceId){ + VolumeVO rootVolume = _volumeDao.findByInstance(instanceId).get(0); + + if(rootVolume!=null){ + Status poolStatus = _poolDao.findById(rootVolume.getPoolId()).getStatus(); + + if(!poolStatus.equals(Status.Up)) + return false; + else + return true; + } + + return false; + } }