CS-15908 : LDV: Prevent attach local data volume to a VM created in a zone with local storage disabled

Following scenarios are not allowed in case local storage is disabled on zone:
-Creation of volume (new or from snapshot) with local disk offering.
-Attach/reattach of volume with local disk offering.

Reviewed-by: Nitin
This commit is contained in:
Koushik Das 2012-08-13 17:11:26 +05:30
parent 6246191084
commit 7e681a701c
2 changed files with 21 additions and 6 deletions

View File

@ -1856,6 +1856,7 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
Long zoneId = cmd.getZoneId();
Long diskOfferingId = null;
DiskOfferingVO diskOffering = null;
Long size = null;
// validate input parameters before creating the volume
@ -1875,11 +1876,9 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
throw new InvalidParameterValueException("Disk size must be larger than 0", null);
}
}
if (diskOfferingId == null) {
throw new InvalidParameterValueException("Missing parameter(s),either a positive volume size or a valid disk offering id must be specified.", null);
}
// Check that the the disk offering is specified
DiskOfferingVO diskOffering = _diskOfferingDao.findById(diskOfferingId);
diskOffering = _diskOfferingDao.findById(diskOfferingId);
if ((diskOffering == null) || diskOffering.getRemoved() != null || !DiskOfferingVO.Type.Disk.equals(diskOffering.getType())) {
throw new InvalidParameterValueException("Please specify a valid disk offering.", null);
}
@ -1924,7 +1923,8 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
Snapshot.Status.BackedUp + " state yet and can't be used for volume creation", idList);
}
diskOfferingId = (cmd.getDiskOfferingId() != null) ? cmd.getDiskOfferingId() : snapshotCheck.getDiskOfferingId();
diskOfferingId = snapshotCheck.getDiskOfferingId();
diskOffering = _diskOfferingDao.findById(diskOfferingId);
zoneId = snapshotCheck.getDataCenterId();
size = snapshotCheck.getSize(); // ; disk offering is used for tags purposes
@ -1953,6 +1953,11 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
throw new PermissionDeniedException("Cannot perform this operation, Zone is currently disabled: " + zoneId);
}
// If local storage is disabled then creation of volume with local disk offering not allowed
if (!zone.isLocalStorageEnabled() && diskOffering.getUseLocalStorage()) {
throw new InvalidParameterValueException("Zone is not configured to use local storage but volume's disk offering " + diskOffering.getName() + " uses it", null);
}
// Check that there is a shared primary storage pool in the specified zone
List<StoragePoolVO> storagePools = _storagePoolDao.listByDataCenterId(zoneId);
boolean sharedPoolExists = false;

View File

@ -134,6 +134,7 @@ import com.cloud.network.security.SecurityGroup;
import com.cloud.network.security.SecurityGroupManager;
import com.cloud.network.security.dao.SecurityGroupDao;
import com.cloud.network.security.dao.SecurityGroupVMMapDao;
import com.cloud.offering.DiskOffering;
import com.cloud.offering.NetworkOffering;
import com.cloud.offering.NetworkOffering.Availability;
import com.cloud.offering.ServiceOffering;
@ -581,6 +582,15 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
throw new InvalidParameterValueException("Please specify a VM that is in the same zone as the volume.", null);
}
// If local storage is disabled then attaching a volume with local disk offering not allowed
DataCenterVO dataCenter = _dcDao.findById(volume.getDataCenterId());
if (!dataCenter.isLocalStorageEnabled()) {
DiskOfferingVO diskOffering = _diskOfferingDao.findById(volume.getDiskOfferingId());
if (diskOffering.getUseLocalStorage()) {
throw new InvalidParameterValueException("Zone is not configured to use local storage but volume's disk offering " + diskOffering.getName() + " uses it", null);
}
}
//permission check
_accountMgr.checkAccess(caller, null, true, volume, vm);
@ -728,7 +738,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
throw new CloudRuntimeException(e.toString());
}
} else {
throw new CloudRuntimeException("Moving a local data volume " + volume + " is not allowed");
throw new CloudRuntimeException("Failed to attach local data volume " + volume.getName() + " to VM " + vm.getDisplayName() + " as migration of local data volume is not allowed");
}
}
}