mirror of https://github.com/apache/cloudstack.git
Adding Storagepolicies to the service offering for root disks
This commit is contained in:
parent
1244fca367
commit
48dd0dae07
|
|
@ -31,6 +31,7 @@ import org.apache.cloudstack.api.Parameter;
|
|||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.response.DomainResponse;
|
||||
import org.apache.cloudstack.api.response.ServiceOfferingResponse;
|
||||
import org.apache.cloudstack.api.response.VsphereStoragePoliciesResponse;
|
||||
import org.apache.cloudstack.api.response.ZoneResponse;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
|
|
@ -216,6 +217,9 @@ public class CreateServiceOfferingCmd extends BaseCmd {
|
|||
since = "4.13")
|
||||
private Integer minMemory;
|
||||
|
||||
@Parameter(name = ApiConstants.STORAGE_POLICY, type = CommandType.UUID, entityType = VsphereStoragePoliciesResponse.class,required = false, description = "Name of the storage policy defined at vCenter, this is applicable only for VMware")
|
||||
private Long storagePolicy;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
@ -418,6 +422,10 @@ public class CreateServiceOfferingCmd extends BaseCmd {
|
|||
return minMemory;
|
||||
}
|
||||
|
||||
public Long getStoragePolicy() {
|
||||
return storagePolicy;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -26,4 +26,5 @@ import com.cloud.utils.db.GenericDao;
|
|||
public interface ServiceOfferingDetailsDao extends GenericDao<ServiceOfferingDetailsVO, Long>, ResourceDetailsDao<ServiceOfferingDetailsVO> {
|
||||
List<Long> findDomainIds(final long resourceId);
|
||||
List<Long> findZoneIds(final long resourceId);
|
||||
String getDetail(Long diskOfferingId, String key);
|
||||
}
|
||||
|
|
@ -58,4 +58,13 @@ public class ServiceOfferingDetailsDaoImpl extends ResourceDetailsDaoBase<Servic
|
|||
return zoneIds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDetail(Long serviceOfferingId, String key) {
|
||||
String detailValue = null;
|
||||
ServiceOfferingDetailsVO serviceOfferingDetail = findDetail(serviceOfferingId, key);
|
||||
if (serviceOfferingDetail != null) {
|
||||
detailValue = serviceOfferingDetail.getValue();
|
||||
}
|
||||
return detailValue;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2462,6 +2462,13 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
|
|||
}
|
||||
}
|
||||
|
||||
final Long storagePolicyId = cmd.getStoragePolicy();
|
||||
if (storagePolicyId != null) {
|
||||
if (vsphereStoragePolicyDao.findById(storagePolicyId) == null) {
|
||||
throw new InvalidParameterValueException("Please specify a valid vSphere storage policy id");
|
||||
}
|
||||
}
|
||||
|
||||
return createServiceOffering(userId, cmd.isSystem(), vmType, cmd.getServiceOfferingName(), cpuNumber, memory, cpuSpeed, cmd.getDisplayText(),
|
||||
cmd.getProvisioningType(), localStorageRequired, offerHA, limitCpuUse, volatileVm, cmd.getTags(), cmd.getDomainIds(), cmd.getZoneIds(), cmd.getHostTag(),
|
||||
cmd.getNetworkRate(), cmd.getDeploymentPlanner(), details, isCustomizedIops, cmd.getMinIops(), cmd.getMaxIops(),
|
||||
|
|
@ -2469,7 +2476,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
|
|||
cmd.getBytesWriteRate(), cmd.getBytesWriteRateMax(), cmd.getBytesWriteRateMaxLength(),
|
||||
cmd.getIopsReadRate(), cmd.getIopsReadRateMax(), cmd.getIopsReadRateMaxLength(),
|
||||
cmd.getIopsWriteRate(), cmd.getIopsWriteRateMax(), cmd.getIopsWriteRateMaxLength(),
|
||||
cmd.getHypervisorSnapshotReserve(), cmd.getCacheMode());
|
||||
cmd.getHypervisorSnapshotReserve(), cmd.getCacheMode(), storagePolicyId);
|
||||
}
|
||||
|
||||
protected ServiceOfferingVO createServiceOffering(final long userId, final boolean isSystem, final VirtualMachine.Type vmType,
|
||||
|
|
@ -2480,7 +2487,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
|
|||
Long bytesWriteRate, Long bytesWriteRateMax, Long bytesWriteRateMaxLength,
|
||||
Long iopsReadRate, Long iopsReadRateMax, Long iopsReadRateMaxLength,
|
||||
Long iopsWriteRate, Long iopsWriteRateMax, Long iopsWriteRateMaxLength,
|
||||
final Integer hypervisorSnapshotReserve, String cacheMode) {
|
||||
final Integer hypervisorSnapshotReserve, String cacheMode, final Long storagePolicyID) {
|
||||
// Filter child domains when both parent and child domains are present
|
||||
List<Long> filteredDomainIds = filterChildSubDomains(domainIds);
|
||||
|
||||
|
|
@ -2620,6 +2627,10 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
|
|||
}
|
||||
}
|
||||
|
||||
if (storagePolicyID != null) {
|
||||
detailsVO.add(new ServiceOfferingDetailsVO(offering.getId(), ApiConstants.STORAGE_POLICY, String.valueOf(storagePolicyID), false));
|
||||
}
|
||||
|
||||
if ((offering = _serviceOfferingDao.persist(offering)) != null) {
|
||||
for (Long domainId : filteredDomainIds) {
|
||||
detailsVO.add(new ServiceOfferingDetailsVO(offering.getId(), ApiConstants.DOMAIN_ID, String.valueOf(domainId), false));
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ import javax.inject.Inject;
|
|||
import com.cloud.agent.api.to.StorageFilerTO;
|
||||
import com.cloud.dc.VsphereStoragePolicyVO;
|
||||
import com.cloud.dc.dao.VsphereStoragePolicyDao;
|
||||
import com.cloud.service.dao.ServiceOfferingDetailsDao;
|
||||
import com.cloud.utils.StringUtils;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.command.admin.storage.CancelPrimaryStorageMaintenanceCmd;
|
||||
|
|
@ -307,6 +308,8 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
|
|||
@Inject
|
||||
DiskOfferingDetailsDao _diskOfferingDetailsDao;
|
||||
@Inject
|
||||
ServiceOfferingDetailsDao _serviceOfferingDetailsDao;
|
||||
@Inject
|
||||
VsphereStoragePolicyDao _vsphereStoragePolicyDao;
|
||||
|
||||
protected List<StoragePoolDiscoverer> _discoverers;
|
||||
|
|
@ -1990,7 +1993,16 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
|
|||
List<Pair<Volume, Answer>> answers = new ArrayList<Pair<Volume, Answer>>();
|
||||
|
||||
for (Volume volume : volumes) {
|
||||
String storagePolicyId = _diskOfferingDetailsDao.getDetail(volume.getDiskOfferingId(), ApiConstants.STORAGE_POLICY);
|
||||
String storagePolicyId = null;
|
||||
if (volume.getVolumeType() == Type.ROOT) {
|
||||
Long vmId = volume.getInstanceId();
|
||||
if (vmId != null) {
|
||||
VMInstanceVO vm = _vmInstanceDao.findByIdIncludingRemoved(vmId);
|
||||
storagePolicyId = _serviceOfferingDetailsDao.getDetail(vm.getServiceOfferingId(), ApiConstants.STORAGE_POLICY);
|
||||
}
|
||||
} else {
|
||||
storagePolicyId = _diskOfferingDetailsDao.getDetail(volume.getDiskOfferingId(), ApiConstants.STORAGE_POLICY);
|
||||
}
|
||||
if (org.apache.commons.lang.StringUtils.isNotEmpty(storagePolicyId)) {
|
||||
VsphereStoragePolicyVO storagePolicyVO = _vsphereStoragePolicyDao.findById(Long.parseLong(storagePolicyId));
|
||||
List<Long> hostIds = getUpHostsInPool(pool.getId());
|
||||
|
|
|
|||
Loading…
Reference in New Issue