Search in sources :

Example 1 with CinderQuotaDetails

use of com.emc.storageos.cinder.model.CinderQuotaDetails in project coprhd-controller by CoprHD.

the class QuotaService method getQuotaDetails.

/**
 * Get the summary list of all Quotas for the given tenant
 *
 * @prereq none
 *
 * @param tenant_id the URN of the tenant asking for quotas
 * @param target_tenant_id
 * @brief Get the summary list of all Quotas
 * @return Quota details of target_tenant_id
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{target_tenant_id}")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public Response getQuotaDetails(@PathParam("target_tenant_id") String openstackTargetTenantId, @QueryParam("usage") String usage, @Context HttpHeaders header) {
    Project project = getCinderHelper().getProject(openstackTargetTenantId.toString(), getUserFromContext());
    if (project == null) {
        throw APIException.badRequests.projectWithTagNonexistent(openstackTargetTenantId);
    }
    HashMap<String, String> defaultQuotaMap = getQuotaHelper().getCompleteDefaultConfiguration(openstackTargetTenantId);
    List<URI> quotas = _dbClient.queryByType(QuotaOfCinder.class, true);
    Map<String, String> vpoolsMap = new HashMap<String, String>();
    boolean bDefProjQuotasExist = false;
    CinderQuotaDetails respCinderQuota = new CinderQuotaDetails();
    for (URI quota : quotas) {
        QuotaOfCinder quotaObj = _dbClient.queryObject(QuotaOfCinder.class, quota);
        if ((quotaObj.getProject() != null) && (quotaObj.getProject().toString().equalsIgnoreCase(project.getId().toString()))) {
            if (quotaObj.getVpool() != null) {
                VirtualPool pool = _dbClient.queryObject(VirtualPool.class, quotaObj.getVpool());
                respCinderQuota.quota_set.put("gigabytes" + "_" + pool.getLabel(), String.valueOf(quotaObj.getTotalQuota()));
                respCinderQuota.quota_set.put("snapshots" + "_" + pool.getLabel(), String.valueOf(quotaObj.getSnapshotsLimit()));
                respCinderQuota.quota_set.put("volumes" + "_" + pool.getLabel(), String.valueOf(quotaObj.getVolumesLimit()));
                vpoolsMap.put(pool.getLabel(), pool.getLabel());
            } else {
                respCinderQuota.quota_set.put("gigabytes", String.valueOf(quotaObj.getTotalQuota()));
                respCinderQuota.quota_set.put("snapshots", String.valueOf(quotaObj.getSnapshotsLimit()));
                respCinderQuota.quota_set.put("volumes", String.valueOf(quotaObj.getVolumesLimit().intValue()));
                bDefProjQuotasExist = true;
            }
        }
    }
    if (!bDefProjQuotasExist) {
        QuotaOfCinder objRet = getQuotaHelper().createProjectDefaultQuota(project, defaultQuotaMap);
        respCinderQuota.quota_set.put("gigabytes", String.valueOf(objRet.getTotalQuota()));
        respCinderQuota.quota_set.put("snapshots", String.valueOf(objRet.getSnapshotsLimit()));
        respCinderQuota.quota_set.put("volumes", String.valueOf(objRet.getVolumesLimit()));
    }
    StorageOSUser user = getUserFromContext();
    URI tenantId = URI.create(user.getTenantId());
    List<URI> vpools = _dbClient.queryByType(VirtualPool.class, true);
    for (URI vpool : vpools) {
        VirtualPool pool = _dbClient.queryObject(VirtualPool.class, vpool);
        _log.debug("Looking up vpool {}", pool.getLabel());
        if (pool != null && pool.getType().equalsIgnoreCase(VirtualPool.Type.block.name())) {
            if (_permissionsHelper.tenantHasUsageACL(tenantId, pool)) {
                if (vpoolsMap.containsKey(pool.getLabel())) {
                    continue;
                } else {
                    QuotaOfCinder objRet = getQuotaHelper().createVpoolDefaultQuota(project, pool, defaultQuotaMap);
                    respCinderQuota.quota_set.put("gigabytes" + "_" + pool.getLabel(), String.valueOf(objRet.getTotalQuota()));
                    respCinderQuota.quota_set.put("snapshots" + "_" + pool.getLabel(), String.valueOf(objRet.getSnapshotsLimit()));
                    respCinderQuota.quota_set.put("volumes" + "_" + pool.getLabel(), String.valueOf(objRet.getVolumesLimit()));
                }
            }
        }
    }
    if ((usage != null) && (usage.equals("True"))) {
        CinderUsage objUsage = getQuotaHelper().getUsageStatistics(URI.create(openstackTargetTenantId), (HashMap<String, String>) respCinderQuota.getQuota_set(), project);
        return getQuotaUsageFormat(header, objUsage);
    }
    return getQuotaDetailFormat(header, respCinderQuota);
}
Also used : CinderUsage(com.emc.storageos.cinder.model.CinderUsage) HashMap(java.util.HashMap) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) URI(java.net.URI) Project(com.emc.storageos.db.client.model.Project) QuotaOfCinder(com.emc.storageos.db.client.model.QuotaOfCinder) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) CinderQuotaDetails(com.emc.storageos.cinder.model.CinderQuotaDetails) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 2 with CinderQuotaDetails

use of com.emc.storageos.cinder.model.CinderQuotaDetails in project coprhd-controller by CoprHD.

the class QuotaService method getQuotaDefaults.

/**
 * Get the summary list of all Default Quotas for the given tenant
 *
 * @prereq none
 *
 * @param tenant_id the URN of the tenant asking for quotas
 * @param target_tenant_id
 * @brief List quota defaults for a tenant
 * @return Default Quota details of target_tenant_id
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{target_tenant_id}/defaults")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public Response getQuotaDefaults(@PathParam("target_tenant_id") String openstackTargetTenantId, @Context HttpHeaders header) {
    _log.info("In getQuotaDefaults");
    CinderQuotaDetails respCinderQuota = new CinderQuotaDetails();
    HashMap<String, String> defaultQuotaMap = getQuotaHelper().getCompleteDefaultConfiguration(openstackTargetTenantId);
    _log.debug("defaultQuotaMap is {}", defaultQuotaMap.toString());
    // defaultQuotaMap = getQuotaHelper().populateVolumeTypeQuotasWhenNotDefined(defaultQuotaMap , openstack_target_tenant_id, null);
    respCinderQuota.quota_set.putAll(defaultQuotaMap);
    _log.debug("respCinderQuota is {}", respCinderQuota.quota_set.toString());
    return getQuotaDetailFormat(header, respCinderQuota);
}
Also used : CinderQuotaDetails(com.emc.storageos.cinder.model.CinderQuotaDetails) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

CinderQuotaDetails (com.emc.storageos.cinder.model.CinderQuotaDetails)2 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 CinderUsage (com.emc.storageos.cinder.model.CinderUsage)1 Project (com.emc.storageos.db.client.model.Project)1 QuotaOfCinder (com.emc.storageos.db.client.model.QuotaOfCinder)1 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)1 StorageOSUser (com.emc.storageos.security.authentication.StorageOSUser)1 URI (java.net.URI)1 HashMap (java.util.HashMap)1