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);
}
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);
}
Aggregations