use of com.emc.storageos.db.client.model.QuotaOfCinder in project coprhd-controller by CoprHD.
the class QuotaHelper method createProjectDefaultQuota.
/**
* Get default quota for provided project
*
* @prereq none
*
* @param project
* param defaultQuotaMap (comprehensive default quota map)
* @brief get project default quota
* @return quota
*/
public QuotaOfCinder createProjectDefaultQuota(Project project, HashMap<String, String> defaultQuotaMap) {
long maxQuota = 0;
if (project.getQuotaEnabled()) {
maxQuota = (long) (project.getQuota().intValue());
} else {
maxQuota = Long.valueOf(defaultQuotaMap.get(CinderConstants.ResourceQuotaDefaults.GIGABYTES.getResource()));
}
QuotaOfCinder quotaObj = new QuotaOfCinder();
quotaObj.setId(URI.create(UUID.randomUUID().toString()));
quotaObj.setProject(project.getId());
quotaObj.setVolumesLimit(Long.valueOf(defaultQuotaMap.get(CinderConstants.ResourceQuotaDefaults.VOLUMES.getResource())));
quotaObj.setSnapshotsLimit(Long.valueOf(defaultQuotaMap.get(CinderConstants.ResourceQuotaDefaults.SNAPSHOTS.getResource())));
quotaObj.setTotalQuota(maxQuota);
_log.info("Creating default quota for project");
_dbClient.createObject(quotaObj);
return quotaObj;
}
use of com.emc.storageos.db.client.model.QuotaOfCinder in project coprhd-controller by CoprHD.
the class QuotaHelper method getVPoolQuota.
/**
* Get quota for provided vpool
*
* @prereq none
*
* @param tenantId
* @param vpool
*
* @brief get vpool quota
* @return quota
*/
public QuotaOfCinder getVPoolQuota(String tenantId, VirtualPool vpool, StorageOSUser user) {
_log.debug("In getVPoolQuota");
Project project = getCinderHelper().getProject(tenantId.toString(), user);
List<URI> quotas = _dbClient.queryByType(QuotaOfCinder.class, true);
for (URI quota : quotas) {
QuotaOfCinder quotaObj = _dbClient.queryObject(QuotaOfCinder.class, quota);
URI vpoolUri = quotaObj.getVpool();
if (vpoolUri == null) {
continue;
} else if ((quotaObj.getProject() != null) && (quotaObj.getProject().toString().equalsIgnoreCase(project.getId().toString()))) {
VirtualPool pool = _dbClient.queryObject(VirtualPool.class, vpoolUri);
if ((pool != null) && (pool.getLabel().equals(vpool.getLabel())) && (vpool.getLabel() != null) && (vpool.getLabel().length() > 0)) {
return quotaObj;
}
}
}
HashMap<String, String> qMap = getCompleteDefaultConfiguration(tenantId);
return createVpoolDefaultQuota(project, vpool, qMap);
}
use of com.emc.storageos.db.client.model.QuotaOfCinder in project coprhd-controller by CoprHD.
the class QuotaHelper method getProjectQuota.
/**
* Get quota for given project/tenant
*
* @prereq none
*
* @param tenantId
*
* @brief get project quota
* @return quota
*/
public QuotaOfCinder getProjectQuota(String tenantId, StorageOSUser user) {
Project project = getCinderHelper().getProject(tenantId.toString(), user);
List<URI> quotas = _dbClient.queryByType(QuotaOfCinder.class, true);
for (URI quota : quotas) {
QuotaOfCinder quotaObj = _dbClient.queryObject(QuotaOfCinder.class, quota);
URI vpoolUri = quotaObj.getVpool();
if (vpoolUri != null) {
continue;
}
if ((quotaObj.getProject() != null) && (quotaObj.getProject().toString().equalsIgnoreCase(project.getId().toString()))) {
return quotaObj;
}
}
HashMap<String, String> qMap = getCompleteDefaultConfiguration(tenantId);
return createProjectDefaultQuota(project, qMap);
}
use of com.emc.storageos.db.client.model.QuotaOfCinder in project coprhd-controller by CoprHD.
the class VolumeService method validateVolumeCreate.
private boolean validateVolumeCreate(String openstackTenantId, VirtualPool pool, long requestedSize) {
QuotaOfCinder objQuota = null;
boolean isValidVolume = false;
if (pool == null)
objQuota = getQuotaHelper().getProjectQuota(openstackTenantId, getUserFromContext());
else
objQuota = getQuotaHelper().getVPoolQuota(openstackTenantId, pool, getUserFromContext());
if (objQuota == null) {
_log.info("Unable to retrive the Quota information");
return false;
}
Project proj = getCinderHelper().getProject(openstackTenantId, getUserFromContext());
long totalVolumesUsed = 0;
long totalSizeUsed = 0;
UsageStats stats = null;
if (pool != null)
stats = getQuotaHelper().getStorageStats(pool.getId(), proj.getId());
else
stats = getQuotaHelper().getStorageStats(null, proj.getId());
totalVolumesUsed = stats.volumes;
totalSizeUsed = stats.spaceUsed;
_log.info(String.format("VolumesLimit():%s ,TotalQuota:%s , TotalSizeUsed:%s, TotalVolumesUsed:%s, RequestedConsumption:%s", objQuota.getVolumesLimit(), objQuota.getTotalQuota(), totalSizeUsed, totalVolumesUsed, (totalSizeUsed + requestedSize / GB)));
if ((objQuota.getVolumesLimit() != QuotaService.DEFAULT_VOLUME_TYPE_VOLUMES_QUOTA) && (objQuota.getVolumesLimit() <= totalVolumesUsed)) {
return isValidVolume;
} else if ((objQuota.getTotalQuota() != QuotaService.DEFAULT_VOLUME_TYPE_TOTALGB_QUOTA) && (objQuota.getTotalQuota() <= (totalSizeUsed + requestedSize / GB))) {
return isValidVolume;
} else {
isValidVolume = true;
return isValidVolume;
}
}
use of com.emc.storageos.db.client.model.QuotaOfCinder in project coprhd-controller by CoprHD.
the class MiscService method getLimits.
/**
* Get Limits
*
* @prereq none
* @param tenant_id the URN of the tenant
* @brief Get Limits
* @return limits
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/limits")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public Response getLimits(@PathParam("tenant_id") String openstack_tenant_id, @Context HttpHeaders header) {
_log.info("START get limits");
CinderLimits limitsResp = new CinderLimits();
Project project = getCinderHelper().getProject(openstack_tenant_id.toString(), getUserFromContext());
if (project == null) {
throw APIException.badRequests.projectWithTagNonexistent(openstack_tenant_id);
}
HashMap<String, String> defaultQuotaMap = getQuotaHelper().loadDefaultsMapFromDb();
int totalSizeUsed = 0;
int maxQuota = Long.valueOf(defaultQuotaMap.get(CinderConstants.ResourceQuotaDefaults.GIGABYTES.getResource())).intValue();
int maxTotalVolumes = 0;
int maxTotalSnapshots = 0;
int totalVolumesUsed = 0;
int totalSnapshotsUsed = 0;
if (project.getQuotaEnabled()) {
maxQuota = (int) (project.getQuota().intValue());
}
UsageStats objUsageStats = new UsageStats();
objUsageStats = getQuotaHelper().getStorageStats(null, project.getId());
totalVolumesUsed = (int) objUsageStats.volumes;
totalSnapshotsUsed = (int) objUsageStats.snapshots;
totalSizeUsed = (int) objUsageStats.spaceUsed;
QuotaOfCinder projQuota = getQuotaHelper().getProjectQuota(openstack_tenant_id, getUserFromContext());
if (projQuota != null) {
maxTotalVolumes = projQuota.getVolumesLimit().intValue();
maxTotalSnapshots = (int) projQuota.getSnapshotsLimit().intValue();
} else {
QuotaOfCinder quotaObj = new QuotaOfCinder();
quotaObj.setId(URI.create(UUID.randomUUID().toString()));
quotaObj.setProject(project.getId());
quotaObj.setVolumesLimit(Long.valueOf(defaultQuotaMap.get(CinderConstants.ResourceQuotaDefaults.VOLUMES.getResource())));
quotaObj.setSnapshotsLimit(Long.valueOf(defaultQuotaMap.get(CinderConstants.ResourceQuotaDefaults.SNAPSHOTS.getResource())));
quotaObj.setTotalQuota((long) maxQuota);
_dbClient.createObject(quotaObj);
maxTotalSnapshots = quotaObj.getSnapshotsLimit().intValue();
maxTotalVolumes = quotaObj.getVolumesLimit().intValue();
}
Map<String, Integer> absoluteDetailsMap = new HashMap<String, Integer>();
absoluteDetailsMap.put("totalSnapshotsUsed", totalSnapshotsUsed);
absoluteDetailsMap.put("maxTotalVolumeGigabytes", maxQuota);
absoluteDetailsMap.put("totalGigabytesUsed", totalSizeUsed);
absoluteDetailsMap.put("maxTotalSnapshots", maxTotalSnapshots);
absoluteDetailsMap.put("totalVolumesUsed", totalVolumesUsed);
absoluteDetailsMap.put("maxTotalVolumes", maxTotalVolumes);
limitsResp.absolute = absoluteDetailsMap;
_log.info("END get limits");
return CinderApiUtils.getCinderResponse(limitsResp, header, true, CinderConstants.STATUS_OK);
}
Aggregations