use of com.emc.storageos.cinder.model.CinderLimits 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