Search in sources :

Example 86 with StorageOSUser

use of com.emc.storageos.security.authentication.StorageOSUser in project coprhd-controller by CoprHD.

the class ExportService method getHost.

private Host getHost(String hostname, String tenant_id) {
    Host host = searchHostInDb(hostname);
    if (host == null) {
        _log.info("Creating new Host, hostname = {}", hostname);
        host = new Host();
        host.setId(URIUtil.createId(Host.class));
        StorageOSUser user = getUserFromContext();
        host.setTenant(URI.create(user.getTenantId()));
        host.setHostName(hostname);
        host.setLabel(hostname);
        host.setDiscoverable(false);
        Project proj = getCinderHelper().getProject(tenant_id, getUserFromContext());
        if (proj != null) {
            host.setProject(proj.getId());
        } else {
            throw APIException.badRequests.projectWithTagNonexistent(tenant_id);
        }
        host.setType(Host.HostType.Other.name());
        _dbClient.createObject(host);
    }
    return host;
}
Also used : Project(com.emc.storageos.db.client.model.Project) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) Host(com.emc.storageos.db.client.model.Host)

Example 87 with StorageOSUser

use of com.emc.storageos.security.authentication.StorageOSUser 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 88 with StorageOSUser

use of com.emc.storageos.security.authentication.StorageOSUser in project coprhd-controller by CoprHD.

the class TypeService method getVolumeType.

/**
 * Get information about a specified volume type
 *
 * @prereq none
 *
 * @param tenant_id the URN of the tenant
 * @param volume_type_id the URN of the volume type
 *
 * @brief Show volume type
 * @return Volume type details
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{volume_type_id}")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public Response getVolumeType(@PathParam("tenant_id") URI openstacktenant_id, @PathParam("volume_type_id") URI volume_type_id, @Context HttpHeaders header) {
    _log.debug("START get volume types {}", volume_type_id);
    // Here we ignore the openstack tenant id
    VolumeType volType = new VolumeType();
    VirtualPool pool = _dbClient.queryObject(VirtualPool.class, volume_type_id);
    if (pool != null) {
        if (pool.getType().equalsIgnoreCase(VirtualPool.Type.block.name())) {
            _log.debug("Found matching vpool {}", pool.getLabel());
            StorageOSUser user = getUserFromContext();
            URI tenantId = URI.create(user.getTenantId());
            if (_permissionsHelper.tenantHasUsageACL(tenantId, pool)) {
                _log.debug("Has permissions for vpool {}", pool.getLabel());
                volType.id = pool.getId().toString();
                volType.name = pool.getLabel();
                volType.extra_specs = new HashMap<String, String>();
            }
        }
    }
    _log.debug("END get volume types {}", volume_type_id);
    return CinderApiUtils.getCinderResponse(volType, header, true, CinderConstants.STATUS_OK);
}
Also used : VolumeType(com.emc.storageos.cinder.model.VolumeType) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) URI(java.net.URI) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 89 with StorageOSUser

use of com.emc.storageos.security.authentication.StorageOSUser in project coprhd-controller by CoprHD.

the class QosService method hasTenantUsageAclOnQos.

/**
 * Checks whether user's tenant has usage ACL on QoS
 *
 * @param qos Quality of Service
 * @return true if tenant has usage ACL, false otherwise
 */
private boolean hasTenantUsageAclOnQos(QosSpecification qos) {
    StorageOSUser user = getUserFromContext();
    URI tenantId = URI.create(user.getTenantId());
    VirtualPool virtualPool = _dbClient.queryObject(VirtualPool.class, qos.getVirtualPoolId());
    return _permissionsHelper.tenantHasUsageACL(tenantId, virtualPool);
}
Also used : StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) URI(java.net.URI)

Example 90 with StorageOSUser

use of com.emc.storageos.security.authentication.StorageOSUser in project coprhd-controller by CoprHD.

the class MigrationService method pauseMigration.

/**
 * Pause a migration that is in progress.
 *
 * @prereq The migration is in progress
 *
 * @param id the URN of a ViPR migration.
 *
 * @brief Pause a migration.
 * @return A TaskResourceRep
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/pause")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public TaskResourceRep pauseMigration(@PathParam("id") URI id) {
    ArgValidator.checkFieldUriType(id, Migration.class, "id");
    Migration migration = queryResource(id);
    if (!BulkList.MigrationFilter.isUserAuthorizedForMigration(migration, getUserFromContext(), _permissionsHelper)) {
        StorageOSUser user = getUserFromContext();
        throw APIException.forbidden.insufficientPermissionsForUser(user.getName());
    }
    String status = migration.getMigrationStatus();
    String migrationName = migration.getLabel();
    if (status == null || status.isEmpty() || migrationName == null || migrationName.isEmpty()) {
        throw APIException.badRequests.migrationHasntStarted(id.toString());
    }
    if (status.equalsIgnoreCase(VPlexMigrationInfo.MigrationStatus.COMPLETE.getStatusValue()) || status.equalsIgnoreCase(VPlexMigrationInfo.MigrationStatus.ERROR.getStatusValue()) || status.equalsIgnoreCase(VPlexMigrationInfo.MigrationStatus.COMMITTED.getStatusValue()) || status.equalsIgnoreCase(VPlexMigrationInfo.MigrationStatus.CANCELLED.getStatusValue())) {
        throw APIException.badRequests.migrationCantBePaused(migrationName, status);
    }
    URI volId = migration.getVolume();
    Volume vplexVol = _dbClient.queryObject(Volume.class, volId);
    // Create a unique task id.
    String taskId = UUID.randomUUID().toString();
    // Create a task for the volume and set the
    // initial task state to pending.
    Operation op = _dbClient.createTaskOpStatus(Volume.class, volId, taskId, ResourceOperationTypeEnum.PAUSE_MIGRATION);
    TaskResourceRep task = toTask(vplexVol, taskId, op);
    if (status.equalsIgnoreCase(VPlexMigrationInfo.MigrationStatus.PAUSED.getStatusValue())) {
        // it has been paused.
        s_logger.info("Migration {} has been paused", id);
        op.ready();
        vplexVol.getOpStatus().createTaskStatus(taskId, op);
        _dbClient.persistObject(vplexVol);
        return task;
    }
    try {
        VPlexController controller = _vplexBlockServiceApi.getController();
        controller.pauseMigration(vplexVol.getStorageController(), id, taskId);
    } catch (InternalException e) {
        s_logger.error("Error", e);
        String errMsg = String.format("Error: %s", e.getMessage());
        task.setState(Operation.Status.error.name());
        task.setMessage(errMsg);
        op.error(e);
        vplexVol.getOpStatus().updateTaskStatus(taskId, op);
        _dbClient.persistObject(vplexVol);
    }
    return task;
}
Also used : VPlexController(com.emc.storageos.vplexcontroller.VPlexController) Volume(com.emc.storageos.db.client.model.Volume) Migration(com.emc.storageos.db.client.model.Migration) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) Operation(com.emc.storageos.db.client.model.Operation) URI(java.net.URI) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

StorageOSUser (com.emc.storageos.security.authentication.StorageOSUser)105 Produces (javax.ws.rs.Produces)59 Path (javax.ws.rs.Path)53 URI (java.net.URI)50 GET (javax.ws.rs.GET)36 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)31 Consumes (javax.ws.rs.Consumes)24 POST (javax.ws.rs.POST)15 ArrayList (java.util.ArrayList)13 Order (com.emc.storageos.db.client.model.uimodels.Order)12 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)12 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)11 NamedURI (com.emc.storageos.db.client.model.NamedURI)10 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)10 PUT (javax.ws.rs.PUT)10 Operation (com.emc.storageos.db.client.model.Operation)9 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)9 HashSet (java.util.HashSet)9 StringSet (com.emc.storageos.db.client.model.StringSet)8 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)8