Search in sources :

Example 1 with CinderLimits

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);
}
Also used : Project(com.emc.storageos.db.client.model.Project) QuotaOfCinder(com.emc.storageos.db.client.model.QuotaOfCinder) HashMap(java.util.HashMap) UsageStats(com.emc.storageos.cinder.model.UsageStats) CinderLimits(com.emc.storageos.cinder.model.CinderLimits) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

CinderLimits (com.emc.storageos.cinder.model.CinderLimits)1 UsageStats (com.emc.storageos.cinder.model.UsageStats)1 Project (com.emc.storageos.db.client.model.Project)1 QuotaOfCinder (com.emc.storageos.db.client.model.QuotaOfCinder)1 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)1 HashMap (java.util.HashMap)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1