private synchronized void checkAndSetAttaching(Long volumeId, Long hostId) { VolumeInfo volumeToAttach = volFactory.getVolume(volumeId); if (volumeToAttach.isAttachedVM()) { throw new CloudRuntimeException("volume: " + volumeToAttach.getName() + " is already attached to a VM: " + volumeToAttach.getAttachedVmName()); } if (volumeToAttach.getState().equals(Volume.State.Ready)) { volumeToAttach.stateTransit(Volume.Event.AttachRequested); } else { String error = null; if (hostId == null) { error = "Please try attach operation after starting VM once"; } else { error = "Volume: " + volumeToAttach.getName() + " is in " + volumeToAttach.getState() + ". It should be in Ready state"; } s_logger.error(error); throw new CloudRuntimeException(error); } }
details.put(PrimaryDataStore.MANAGED_STORE_TARGET_ROOT_VOLUME, volumeInfo.getName()); details.put(PrimaryDataStore.VOLUME_SIZE, String.valueOf(volumeInfo.getSize()));
protected VolumeVO createVolumeFromSnapshot(VolumeVO volume, long snapshotId, Long vmId) throws StorageUnavailableException { VolumeInfo createdVolume = null; SnapshotVO snapshot = _snapshotDao.findById(snapshotId); snapshot.getVolumeId(); UserVmVO vm = null; if (vmId != null) { vm = _userVmDao.findById(vmId); } // sync old snapshots to region store if necessary createdVolume = _volumeMgr.createVolumeFromSnapshot(volume, snapshot, vm); VolumeVO volumeVo = _volsDao.findById(createdVolume.getId()); UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_CREATE, createdVolume.getAccountId(), createdVolume.getDataCenterId(), createdVolume.getId(), createdVolume.getName(), createdVolume.getDiskOfferingId(), null, createdVolume.getSize(), Volume.class.getName(), createdVolume.getUuid(), volumeVo.isDisplayVolume()); return volumeVo; }
private SolidFireUtil.SolidFireVolume createClone(SolidFireUtil.SolidFireConnection sfConnection, long dataObjectId, VolumeInfo volumeInfo, long sfAccountId, long storagePoolId, DataObjectType dataObjectType) { String sfNewVolumeName = volumeInfo.getName(); long sfVolumeId = Long.MIN_VALUE; long sfSnapshotId = Long.MIN_VALUE; if (dataObjectType == DataObjectType.SNAPSHOT) { SnapshotDetailsVO snapshotDetails = snapshotDetailsDao.findDetail(dataObjectId, SolidFireUtil.SNAPSHOT_ID); if (snapshotDetails != null && snapshotDetails.getValue() != null) { sfSnapshotId = Long.parseLong(snapshotDetails.getValue()); } snapshotDetails = snapshotDetailsDao.findDetail(dataObjectId, SolidFireUtil.VOLUME_ID); sfVolumeId = Long.parseLong(snapshotDetails.getValue()); } else if (dataObjectType == DataObjectType.TEMPLATE) { // get the cached template on this storage VMTemplateStoragePoolVO templatePoolRef = tmpltPoolDao.findByPoolTemplate(storagePoolId, dataObjectId); if (templatePoolRef != null) { sfVolumeId = Long.parseLong(templatePoolRef.getLocalDownloadPath()); } } if (sfVolumeId <= 0) { throw new CloudRuntimeException("Unable to find SolidFire volume for the following data-object ID: " + dataObjectId + " and data-object type: " + dataObjectType); } final long newSfVolumeId = SolidFireUtil.createClone(sfConnection, sfVolumeId, sfSnapshotId, sfAccountId, SolidFireUtil.getSolidFireVolumeName(sfNewVolumeName), getVolumeAttributes(volumeInfo)); final Iops iops = getIops(volumeInfo.getMinIops(), volumeInfo.getMaxIops(), storagePoolId); SolidFireUtil.modifyVolume(sfConnection, newSfVolumeId, null, null, iops.getMinIops(), iops.getMaxIops(), iops.getBurstIops()); return SolidFireUtil.getVolume(sfConnection, newSfVolumeId); }
, srcVolume.getName() , srcVolume.getId() , srcRole
protected DiskProfile createDiskCharacteristics(VolumeInfo volume, VirtualMachineTemplate template, DataCenter dc, DiskOffering diskOffering) { if (volume.getVolumeType() == Type.ROOT && Storage.ImageFormat.ISO != template.getFormat()) { TemplateDataStoreVO ss = _vmTemplateStoreDao.findByTemplateZoneDownloadStatus(template.getId(), dc.getId(), VMTemplateStorageResourceAssoc.Status.DOWNLOADED); if (ss == null) { throw new CloudRuntimeException("Template " + template.getName() + " has not been completely downloaded to zone " + dc.getId()); } return new DiskProfile(volume.getId(), volume.getVolumeType(), volume.getName(), diskOffering.getId(), ss.getSize(), diskOffering.getTagsArray(), diskOffering.isUseLocalStorage(), diskOffering.isRecreatable(), Storage.ImageFormat.ISO != template.getFormat() ? template.getId() : null); } else { return new DiskProfile(volume.getId(), volume.getVolumeType(), volume.getName(), diskOffering.getId(), diskOffering.getDiskSize(), diskOffering.getTagsArray(), diskOffering.isUseLocalStorage(), diskOffering.isRecreatable(), null); } }
@Override public VolumeInfo moveVolume(VolumeInfo volume, long destPoolDcId, Long destPoolPodId, Long destPoolClusterId, HypervisorType dataDiskHyperType) throws ConcurrentOperationException, StorageUnavailableException { // Find a destination storage pool with the specified criteria DiskOffering diskOffering = _entityMgr.findById(DiskOffering.class, volume.getDiskOfferingId()); DiskProfile dskCh = new DiskProfile(volume.getId(), volume.getVolumeType(), volume.getName(), diskOffering.getId(), diskOffering.getDiskSize(), diskOffering.getTagsArray(), diskOffering.isUseLocalStorage(), diskOffering.isRecreatable(), null); dskCh.setHyperType(dataDiskHyperType); storageMgr.setDiskProfileThrottling(dskCh, null, diskOffering); DataCenter destPoolDataCenter = _entityMgr.findById(DataCenter.class, destPoolDcId); Pod destPoolPod = _entityMgr.findById(Pod.class, destPoolPodId); StoragePool destPool = findStoragePool(dskCh, destPoolDataCenter, destPoolPod, destPoolClusterId, null, null, new HashSet<StoragePool>()); if (destPool == null) { throw new CloudRuntimeException("Failed to find a storage pool with enough capacity to move the volume to."); } Volume newVol = migrateVolume(volume, destPool); return volFactory.getVolume(newVol.getId()); }
if (volumeStore != null) { if (volumeStore.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOAD_IN_PROGRESS) { s_logger.debug("Volume: " + volume.getName() + " is currently being uploaded; cant' delete it."); future.complete(result); return future;
if (primaryStore.isLocal()) { throw new CloudRuntimeException( "Failed to attach local data volume " + volumeToAttach.getName() + " to VM " + vm.getDisplayName() + " as migration of local data volume is not allowed");
String volumeName = volumeInfo.getName(); Long Iops = volumeInfo.getMaxIops();
vol.getName(), vol.getFormat().toString(), dataObject.getDataStore().getUri(), dataObject.getDataStore().getRole().toString()); command.setLocalPath(volumeStore.getLocalDownloadPath());
snapshotName = vmDisplayName + "_" + volume.getName() + "_" + timeString;
private SolidFireUtil.SolidFireVolume createSolidFireVolume(SolidFireUtil.SolidFireConnection sfConnection, DataObject dataObject, long storagePoolId, long sfAccountId) { final Long minIops; final Long maxIops; final Long volumeSize; final String volumeName; final Map<String, String> mapAttributes; if (dataObject.getType() == DataObjectType.VOLUME) { VolumeInfo volumeInfo = (VolumeInfo)dataObject; minIops = volumeInfo.getMinIops(); maxIops = volumeInfo.getMaxIops(); volumeSize = getDataObjectSizeIncludingHypervisorSnapshotReserve(volumeInfo, storagePoolDao.findById(storagePoolId)); volumeName = volumeInfo.getName(); mapAttributes = getVolumeAttributes(volumeInfo); } else if (dataObject.getType() == DataObjectType.TEMPLATE) { TemplateInfo templateInfo = (TemplateInfo)dataObject; minIops = MIN_IOPS_FOR_TEMPLATE_VOLUME; maxIops = MAX_IOPS_FOR_TEMPLATE_VOLUME; volumeSize = getDataObjectSizeIncludingHypervisorSnapshotReserve(templateInfo, storagePoolDao.findById(storagePoolId)); volumeName = templateInfo.getUniqueName(); mapAttributes = getTemplateAttributes(templateInfo); } else { throw new CloudRuntimeException("Invalid type passed to createSolidFireVolume: " + dataObject.getType()); } final Iops iops = getIops(minIops, maxIops, storagePoolId); long sfVolumeId = SolidFireUtil.createVolume(sfConnection, SolidFireUtil.getSolidFireVolumeName(volumeName), sfAccountId, volumeSize, true, mapAttributes, iops.getMinIops(), iops.getMaxIops(), iops.getBurstIops()); return SolidFireUtil.getVolume(sfConnection, sfVolumeId); }
public VolumeObjectTO(VolumeInfo volume) { uuid = volume.getUuid(); path = volume.getPath(); accountId = volume.getAccountId(); if (volume.getDataStore() != null) { dataStore = volume.getDataStore().getTO(); } else { dataStore = null; } vmName = volume.getAttachedVmName(); size = volume.getSize(); setVolumeId(volume.getId()); chainInfo = volume.getChainInfo(); volumeType = volume.getVolumeType(); name = volume.getName(); setId(volume.getId()); format = volume.getFormat(); provisioningType = volume.getProvisioningType(); bytesReadRate = volume.getBytesReadRate(); bytesWriteRate = volume.getBytesWriteRate(); iopsReadRate = volume.getIopsReadRate(); iopsWriteRate = volume.getIopsWriteRate(); cacheMode = volume.getCacheMode(); hypervisorType = volume.getHypervisorType(); setDeviceId(volume.getDeviceId()); }
@Override public void createAsync(DataStore dataStore, DataObject dataObject, AsyncCompletionCallback<CreateCmdResult> callback) { String iqn = null; String errorMessage = null; if (dataObject.getType() != DataObjectType.VOLUME) { errorMessage = "Invalid DataObjectType (" + dataObject.getType() + ") passed to createAsync"; } else { VolumeInfo volumeInfo = (VolumeInfo) dataObject; long storagePoolId = dataStore.getId(); NexentaStorAppliance appliance = getNexentaStorAppliance(storagePoolId); // TODO: maybe we should use md5(volume name) as volume name NexentaStorZvol zvol = (NexentaStorZvol) appliance.createVolume(volumeInfo.getName(), volumeInfo.getSize()); iqn = zvol.getIqn(); VolumeVO volume = this._volumeDao.findById(volumeInfo.getId()); volume.set_iScsiName(iqn); volume.setFolder(zvol.getName()); volume.setPoolType(Storage.StoragePoolType.IscsiLUN); volume.setPoolId(storagePoolId); _volumeDao.update(volume.getId(), volume); StoragePoolVO storagePool = _storagePoolDao.findById(storagePoolId); long capacityBytes = storagePool.getCapacityBytes(); long usedBytes = storagePool.getUsedBytes(); usedBytes += volumeInfo.getSize(); storagePool.setUsedBytes(usedBytes > capacityBytes ? capacityBytes : usedBytes); _storagePoolDao.update(storagePoolId, storagePool); } CreateCmdResult result = new CreateCmdResult(iqn, new Answer(null, errorMessage == null, errorMessage)); result.setResult(errorMessage); callback.complete(result); }
System.out.println("------------------------------------------------"); volume = volumeIter.next(); System.out.println("Name : " + volume.getName()); System.out.println("Type : " + volume.getType()); System.out.println("State : " + volume.getState());