Search in sources :

Example 11 with QuotaOfCinder

use of com.emc.storageos.db.client.model.QuotaOfCinder in project coprhd-controller by CoprHD.

the class ExportService method validateVolumeExpand.

private boolean validateVolumeExpand(String openstack_tenant_id, VirtualPool pool, Volume vol, long requestedSize, Project proj) {
    QuotaOfCinder objQuota = null;
    if (pool == null)
        objQuota = getQuotaHelper().getProjectQuota(openstack_tenant_id, getUserFromContext());
    else
        objQuota = getQuotaHelper().getVPoolQuota(openstack_tenant_id, pool, getUserFromContext());
    if (objQuota == null) {
        _log.info("Unable to retrive the Quota information");
        return false;
    }
    long totalSizeUsed = 0;
    UsageStats stats = null;
    if (pool != null)
        stats = getQuotaHelper().getStorageStats(pool.getId(), proj.getId());
    else
        stats = getQuotaHelper().getStorageStats(null, proj.getId());
    totalSizeUsed = stats.spaceUsed;
    _log.info(String.format("ProvisionedCapacity:%s ,TotalQuota:%s , TotalSizeUsed:%s, RequestedSize:%s, VolCapacity:%s", (long) (vol.getProvisionedCapacity() / GB), objQuota.getTotalQuota(), totalSizeUsed, (long) (requestedSize / GB), (long) vol.getCapacity() / GB));
    if ((objQuota.getTotalQuota() != QuotaService.DEFAULT_VOLUME_TYPE_TOTALGB_QUOTA) && (objQuota.getTotalQuota() <= (totalSizeUsed + ((long) (requestedSize / GB) - (long) (vol.getProvisionedCapacity() / GB)))))
        return false;
    else
        return true;
}
Also used : QuotaOfCinder(com.emc.storageos.db.client.model.QuotaOfCinder) UsageStats(com.emc.storageos.cinder.model.UsageStats)

Example 12 with QuotaOfCinder

use of com.emc.storageos.db.client.model.QuotaOfCinder in project coprhd-controller by CoprHD.

the class QuotaHelper method createVpoolDefaultQuota.

/**
 * Create default quota for vpool
 *
 * @prereq none
 *
 * @param project
 * @param vpool
 * @param defaultQuotaMap (comprehensive default quota map)
 * @brief create default quota
 * @return quota
 */
public QuotaOfCinder createVpoolDefaultQuota(Project project, VirtualPool vpool, HashMap<String, String> defaultQuotaMap) {
    // HashMap<String, String> defaultQuotaMap = loadDefaultsMap();
    QuotaOfCinder objQuotaOfCinder = new QuotaOfCinder();
    objQuotaOfCinder.setProject(project.getId());
    objQuotaOfCinder.setVolumesLimit(Long.valueOf(defaultQuotaMap.get(CinderConstants.ResourceQuotaDefaults.VOLUMES.getResource() + "_" + vpool.getLabel())));
    objQuotaOfCinder.setSnapshotsLimit(Long.valueOf(defaultQuotaMap.get(CinderConstants.ResourceQuotaDefaults.SNAPSHOTS.getResource() + "_" + vpool.getLabel())));
    objQuotaOfCinder.setTotalQuota(Long.valueOf(defaultQuotaMap.get(CinderConstants.ResourceQuotaDefaults.GIGABYTES.getResource() + "_" + vpool.getLabel())));
    objQuotaOfCinder.setId(URI.create(UUID.randomUUID().toString()));
    objQuotaOfCinder.setVpool(vpool.getId());
    _log.info("Create vpool default quota");
    _dbClient.createObject(objQuotaOfCinder);
    return objQuotaOfCinder;
}
Also used : QuotaOfCinder(com.emc.storageos.db.client.model.QuotaOfCinder)

Example 13 with QuotaOfCinder

use of com.emc.storageos.db.client.model.QuotaOfCinder 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 14 with QuotaOfCinder

use of com.emc.storageos.db.client.model.QuotaOfCinder in project coprhd-controller by CoprHD.

the class SnapshotService method validateSnapshotCreate.

private boolean validateSnapshotCreate(String openstack_tenant_id, VirtualPool pool, long requestedSize) {
    _log.info("requestedSize {}", requestedSize);
    QuotaOfCinder objQuota = null;
    if (pool == null) {
        objQuota = getQuotaHelper().getProjectQuota(openstack_tenant_id, getUserFromContext());
    } else {
        objQuota = getQuotaHelper().getVPoolQuota(openstack_tenant_id, pool, getUserFromContext());
    }
    Project proj = getCinderHelper().getProject(openstack_tenant_id, getUserFromContext());
    if (proj == null) {
        throw APIException.badRequests.projectWithTagNonexistent(openstack_tenant_id);
    }
    long totalSnapshotsUsed = 0;
    long totalSizeUsed = 0;
    UsageStats stats = null;
    if (pool != null) {
        stats = getQuotaHelper().getStorageStats(pool.getId(), proj.getId());
    } else {
        stats = getQuotaHelper().getStorageStats(null, proj.getId());
    }
    totalSnapshotsUsed = stats.snapshots;
    totalSizeUsed = stats.spaceUsed;
    _log.info(String.format("objQuota.getVolumesLimit():%s ,objQuota.getSnapshotsLimit():%s,objQuota.getTotalQuota():%s,totalSizeUsed:%s,totalSnapshotsUsed:%s,willconsume:%s", objQuota.getVolumesLimit(), objQuota.getSnapshotsLimit(), objQuota.getTotalQuota(), totalSizeUsed, totalSnapshotsUsed, (totalSizeUsed + (long) (requestedSize / GB))));
    if ((objQuota.getSnapshotsLimit() != -1) && (objQuota.getSnapshotsLimit() <= totalSnapshotsUsed)) {
        return false;
    } else if ((objQuota.getTotalQuota() != -1) && (objQuota.getTotalQuota() <= (totalSizeUsed + (long) (requestedSize / GB)))) {
        return false;
    } else {
        return true;
    }
}
Also used : Project(com.emc.storageos.db.client.model.Project) QuotaOfCinder(com.emc.storageos.db.client.model.QuotaOfCinder) UsageStats(com.emc.storageos.cinder.model.UsageStats)

Aggregations

QuotaOfCinder (com.emc.storageos.db.client.model.QuotaOfCinder)14 Project (com.emc.storageos.db.client.model.Project)10 URI (java.net.URI)6 UsageStats (com.emc.storageos.cinder.model.UsageStats)4 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)4 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 HashMap (java.util.HashMap)2 GET (javax.ws.rs.GET)2 MapProject (com.emc.storageos.api.mapper.functions.MapProject)1 CinderLimits (com.emc.storageos.cinder.model.CinderLimits)1 CinderQuotaDetails (com.emc.storageos.cinder.model.CinderQuotaDetails)1 CinderUsage (com.emc.storageos.cinder.model.CinderUsage)1 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)1 FilePolicy (com.emc.storageos.db.client.model.FilePolicy)1 NamedURI (com.emc.storageos.db.client.model.NamedURI)1 QosSpecification (com.emc.storageos.db.client.model.QosSpecification)1 StringMap (com.emc.storageos.db.client.model.StringMap)1 VpoolProtectionVarraySettings (com.emc.storageos.db.client.model.VpoolProtectionVarraySettings)1