use of com.cloud.storage.Volume.Type in project cloudstack by apache.
the class VolumeOrchestrator method allocateTemplatedVolumes.
@Override
public List<DiskProfile> allocateTemplatedVolumes(Type type, String name, DiskOffering offering, Long rootDisksize, Long minIops, Long maxIops, VirtualMachineTemplate template, VirtualMachine vm, Account owner) {
int volumesNumber = 1;
List<DatadiskTO> templateAsIsDisks = null;
String configurationId = null;
boolean deployVmAsIs = false;
if (template.isDeployAsIs() && vm.getType() != VirtualMachine.Type.SecondaryStorageVm) {
List<SecondaryStorageVmVO> runningSSVMs = secondaryStorageVmDao.getSecStorageVmListInStates(null, vm.getDataCenterId(), State.Running);
if (CollectionUtils.isEmpty(runningSSVMs)) {
s_logger.info("Could not find a running SSVM in datacenter " + vm.getDataCenterId() + " for deploying VM as is, " + "not deploying VM " + vm.getInstanceName() + " as-is");
} else {
UserVmDetailVO configurationDetail = userVmDetailsDao.findDetail(vm.getId(), VmDetailConstants.DEPLOY_AS_IS_CONFIGURATION);
if (configurationDetail != null) {
configurationId = configurationDetail.getValue();
}
templateAsIsDisks = _tmpltMgr.getTemplateDisksOnImageStore(template.getId(), DataStoreRole.Image, configurationId);
if (CollectionUtils.isNotEmpty(templateAsIsDisks)) {
templateAsIsDisks = templateAsIsDisks.stream().filter(x -> !x.isIso()).sorted(Comparator.comparing(DatadiskTO::getDiskNumber)).collect(Collectors.toList());
}
volumesNumber = templateAsIsDisks.size();
deployVmAsIs = true;
}
}
if (volumesNumber < 1) {
throw new CloudRuntimeException("Unable to create any volume from template " + template.getName());
}
List<DiskProfile> profiles = new ArrayList<>();
for (int number = 0; number < volumesNumber; number++) {
String volumeName = name;
Long volumeSize = rootDisksize;
long deviceId = type.equals(Type.ROOT) ? 0L : 1L;
if (deployVmAsIs) {
int volumeNameSuffix = templateAsIsDisks.get(number).getDiskNumber();
volumeName = String.format("%s-%d", volumeName, volumeNameSuffix);
volumeSize = templateAsIsDisks.get(number).getVirtualSize();
deviceId = templateAsIsDisks.get(number).getDiskNumber();
}
s_logger.info(String.format("adding disk object %s to %s", volumeName, vm.getInstanceName()));
DiskProfile diskProfile = allocateTemplatedVolume(type, volumeName, offering, volumeSize, minIops, maxIops, template, vm, owner, deviceId, configurationId);
profiles.add(diskProfile);
}
handleRootDiskControllerTpeForDeployAsIs(templateAsIsDisks, vm);
return profiles;
}
Aggregations