use of com.emc.storageos.cinder.model.CinderUsage in project coprhd-controller by CoprHD.
the class QuotaHelper method getUsageStatistics.
/**
* Get usage statistics in terms of quota attributes like gigabytes,snapshots, volumes.
* The details include in_use,reserved,limit.
*
* @prereq none
*
* @param tenantId
* @param quotaMap of project and vpools
* @param proj project under consideration
*
* @brief get usage statistics in terms of project and volume types.
* @return CinderUsage
*/
public CinderUsage getUsageStatistics(URI tenantId, HashMap<String, String> quotaMap, Project proj) {
CinderUsage objCinderUsage = new CinderUsage();
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)) {
UsageStats stats = getStorageStats(pool.getId(), proj.getId());
UsageAndLimits objSpaceUsage = new UsageAndLimits();
objSpaceUsage.setIn_use(stats.spaceUsed);
objSpaceUsage.setLimit(Long.parseLong(quotaMap.get("gigabytes" + "_" + pool.getLabel())));
UsageAndLimits objVolsUsage = new UsageAndLimits();
objVolsUsage.setIn_use(stats.volumes);
objVolsUsage.setLimit(Long.parseLong(quotaMap.get("volumes" + "_" + pool.getLabel())));
UsageAndLimits objSnapsUsage = new UsageAndLimits();
objSnapsUsage.setIn_use(stats.snapshots);
objSnapsUsage.setLimit(Long.parseLong(quotaMap.get("snapshots" + "_" + pool.getLabel())));
objCinderUsage.getQuota_set().put("gigabytes" + "_" + pool.getLabel(), objSpaceUsage);
objCinderUsage.getQuota_set().put("snapshots" + "_" + pool.getLabel(), objSnapsUsage);
objCinderUsage.getQuota_set().put("volumes" + "_" + pool.getLabel(), objVolsUsage);
}
}
}
// now get the usage information for the project
UsageStats stats = getStorageStats(null, proj.getId());
UsageAndLimits objSpaceUsage = new UsageAndLimits();
objSpaceUsage.setIn_use(stats.spaceUsed);
objSpaceUsage.setLimit(Long.parseLong(quotaMap.get("gigabytes")));
UsageAndLimits objVolsUsage = new UsageAndLimits();
objVolsUsage.setIn_use(stats.volumes);
objVolsUsage.setLimit(Long.parseLong(quotaMap.get("volumes")));
UsageAndLimits objSnapsUsage = new UsageAndLimits();
objSnapsUsage.setIn_use(stats.snapshots);
objSnapsUsage.setLimit(Long.parseLong(quotaMap.get("snapshots")));
objCinderUsage.getQuota_set().put("gigabytes", objSpaceUsage);
objCinderUsage.getQuota_set().put("snapshots", objSnapsUsage);
objCinderUsage.getQuota_set().put("volumes", objVolsUsage);
return objCinderUsage;
}
use of com.emc.storageos.cinder.model.CinderUsage 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);
}
Aggregations