Search in sources :

Example 1 with KeystoneTenant

use of com.emc.storageos.keystone.restapi.model.response.KeystoneTenant in project coprhd-controller by CoprHD.

the class KeystoneService method listOpenstackTenants.

/**
 * Get a list of OpenStack Tenants.
 * Uses data from Keystone Authentication Provider to connect Keystone and retrieve Tenants information.
 *
 * @brief Show OpenStack Tenants.
 * @return OpenStack Tenants details.
 * @see TenantListRestResp
 */
@GET
@Path("/tenants")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SECURITY_ADMIN })
public TenantListRestResp listOpenstackTenants() {
    _log.debug("Keystone Service - listOpenstackTenants");
    StorageOSUser user = getUserFromContext();
    if (!_permissionsHelper.userHasGivenRoleInAnyTenant(user, Role.SECURITY_ADMIN, Role.TENANT_ADMIN)) {
        throw APIException.forbidden.insufficientPermissionsForUser(user.getName());
    }
    AuthnProvider keystoneProvider = _keystoneUtils.getKeystoneProvider();
    // Get OpenStack Tenants only when Keystone Provider exists.
    if (keystoneProvider != null) {
        KeystoneApiClient keystoneApiClient = _keystoneUtils.getKeystoneApi(keystoneProvider.getManagerDN(), keystoneProvider.getServerUrls(), keystoneProvider.getManagerPassword());
        List<KeystoneTenant> OSTenantList = new ArrayList<>(Arrays.asList(keystoneApiClient.getKeystoneTenants().getTenants()));
        TenantListRestResp response = new TenantListRestResp();
        response.setOpenstackTenants(OSTenantList);
        return response;
    }
    throw APIException.internalServerErrors.targetIsNullOrEmpty("Keystone Authentication Provider");
}
Also used : KeystoneTenant(com.emc.storageos.keystone.restapi.model.response.KeystoneTenant) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) ArrayList(java.util.ArrayList) KeystoneApiClient(com.emc.storageos.keystone.restapi.KeystoneApiClient) TenantListRestResp(com.emc.storageos.keystone.restapi.model.response.TenantListRestResp) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 2 with KeystoneTenant

use of com.emc.storageos.keystone.restapi.model.response.KeystoneTenant in project coprhd-controller by CoprHD.

the class OpenStackSynchronizationTaskTest method prepareTenants.

private void prepareTenants() {
    tenantOrg = new TenantOrg();
    tenantOrg.setId(URIUtil.createId(TenantOrg.class));
    tenantOrg.setParentTenant(new NamedURI(URIUtil.createId(TenantOrg.class), ""));
    tenantOrg.addUserMapping(PROVIDER_DOMAIN, TENANT_USER_MAPPING_STRING);
    tenantOrg.setDescription(TENANT_DESCRIPTION);
    tenantOrg.setLabel(TENANT_ORG_NAME);
    keystoneTenant = new KeystoneTenant();
    keystoneTenant.setName(TENANT_NAME);
    keystoneTenant.setDescription(TENANT_DESCRIPTION);
    keystoneTenant.setId(TENANT_OS_ID);
    keystoneTenant.setEnabled(TENANT_ENABLED_STRING);
    osTenant = new OSTenant();
    osTenant.setName(TENANT_NAME);
    osTenant.setDescription(TENANT_DESCRIPTION);
    osTenant.setOsId(TENANT_OS_ID);
    osTenant.setEnabled(TENANT_ENABLED);
    osTenant.setExcluded(TENANT_EXCLUDED);
}
Also used : KeystoneTenant(com.emc.storageos.keystone.restapi.model.response.KeystoneTenant)

Example 3 with KeystoneTenant

use of com.emc.storageos.keystone.restapi.model.response.KeystoneTenant in project coprhd-controller by CoprHD.

the class KeystoneUtilsTest method prepareTenants.

private void prepareTenants() {
    tenantOrg = new TenantOrg();
    tenantOrg.setId(URIUtil.createId(TenantOrg.class));
    tenantOrg.setParentTenant(new NamedURI(URIUtil.createId(TenantOrg.class), ""));
    tenantOrg.addUserMapping(PROVIDER_DOMAIN, TENANT_USER_MAPPING_STRING);
    keystoneTenant = new KeystoneTenant();
    keystoneTenant.setName(TENANT_NAME);
    keystoneTenant.setDescription(TENANT_DESCRIPTION);
    keystoneTenant.setId(TENANT_OS_ID);
    keystoneTenant.setEnabled(TENANT_ENABLED_STRING);
    osTenant = new OSTenant();
    osTenant.setName(TENANT_NAME);
    osTenant.setDescription(TENANT_DESCRIPTION);
    osTenant.setOsId(TENANT_OS_ID);
    osTenant.setEnabled(TENANT_ENABLED);
    osTenant.setExcluded(TENANT_EXCLUDED);
}
Also used : KeystoneTenant(com.emc.storageos.keystone.restapi.model.response.KeystoneTenant)

Example 4 with KeystoneTenant

use of com.emc.storageos.keystone.restapi.model.response.KeystoneTenant in project coprhd-controller by CoprHD.

the class AbstractRequestWrapperFilter method createTenantNProject.

/**
 * Search through request URL for PUT api call updating quota. In case of finding, get OS Tenant id from the request.
 * If the id is not null and Tenant with given id was not created in CoprHD before, then create the Tenant and Project.
 *
 * @param httpServletRequest
 */
private void createTenantNProject(HttpServletRequest httpServletRequest) {
    String requestUrl = httpServletRequest.getRequestURI();
    // We are looking only for PUT API call that updates quota.
    if (httpServletRequest.getMethod().equals(METHOD_PUT) && requestUrl.contains(OS_QUOTA_SETS) && !requestUrl.contains(DEFAULTS)) {
        // Returns target OpenStack Tenant ID from quota request, otherwise null.
        String targetTenantId = getOpenstackTenantIdFromQuotaRequest(requestUrl);
        // Try to create project and tenant in CoprHD when tenant ID is present.
        if (targetTenantId != null) {
            // Check whether Tenant already exists in CoprHD for given ID. If not, then create one.
            TenantOrg coprhdTenant = _keystoneUtils.getCoprhdTenantWithOpenstackId(targetTenantId);
            if (coprhdTenant == null) {
                // Check whether Tenant with ID from request exists in OpenStack.
                KeystoneTenant tenant = _keystoneUtils.getTenantWithId(targetTenantId);
                if (tenant == null) {
                    throw APIException.notFound.openstackTenantNotFound(targetTenantId);
                }
                // Check whether Tenant with given ID is already imported to the CoprHD.
                OSTenant osTenant = _keystoneUtils.findOpenstackTenantInCoprhd(targetTenantId);
                if (osTenant == null) {
                    createTenantNProject(tenant);
                }
            }
        }
    }
}
Also used : KeystoneTenant(com.emc.storageos.keystone.restapi.model.response.KeystoneTenant)

Example 5 with KeystoneTenant

use of com.emc.storageos.keystone.restapi.model.response.KeystoneTenant in project coprhd-controller by CoprHD.

the class OpenStackSynchronizationTask method getListOfTenantsToUpdate.

/**
 * Finds CoprHD Tenants with OpenStack ID that are different from their reflection in OpenStack.
 * Those found Tenants need to be updated.
 *
 * @param osTenantList List of OpenStack Tenants.
 * @param coprhdTenantList List of CoprHD Tenants related to OpenStack.
 * @return List of CoprHD Tenants that needs to be updated.
 */
private List<TenantOrg> getListOfTenantsToUpdate(List<KeystoneTenant> osTenantList, List<TenantOrg> coprhdTenantList) {
    List<TenantOrg> tenantsToUpdate = null;
    ListIterator<KeystoneTenant> osIter = osTenantList.listIterator();
    while (osIter.hasNext()) {
        ListIterator<TenantOrg> coprhdIter = coprhdTenantList.listIterator();
        KeystoneTenant osTenant = osIter.next();
        // Update information about this Tenant in CoprHD database.
        createOrUpdateOpenstackTenantInCoprhd(osTenant);
        while (coprhdIter.hasNext()) {
            TenantOrg coprhdTenant = coprhdIter.next();
            String tenantMapping = _keystoneUtilsService.getCoprhdTenantUserMapping(coprhdTenant);
            String tenantId = _keystoneUtilsService.getTenantIdFromUserMapping(tenantMapping);
            if (tenantId.equals(osTenant.getId())) {
                if (!areTenantsIdentical(osTenant, coprhdTenant)) {
                    coprhdTenant.setDescription(osTenant.getDescription());
                    String tenantName = OPENSTACK + " " + osTenant.getName();
                    coprhdTenant.setLabel(tenantName);
                    if (tenantsToUpdate == null) {
                        tenantsToUpdate = new ArrayList<>();
                    }
                    tenantsToUpdate.add(coprhdTenant);
                }
                coprhdIter.remove();
                osIter.remove();
            }
        }
    }
    return tenantsToUpdate;
}
Also used : KeystoneTenant(com.emc.storageos.keystone.restapi.model.response.KeystoneTenant)

Aggregations

KeystoneTenant (com.emc.storageos.keystone.restapi.model.response.KeystoneTenant)7 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)3 KeystoneApiClient (com.emc.storageos.keystone.restapi.KeystoneApiClient)1 TenantListRestResp (com.emc.storageos.keystone.restapi.model.response.TenantListRestResp)1 StorageOSUser (com.emc.storageos.security.authentication.StorageOSUser)1 ArrayList (java.util.ArrayList)1