Search in sources :

Example 6 with KeystoneTenant

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

the class KeystoneService method synchronizeOpenstackTenants.

/**
 * Synchronize CoprHD and OpenStack Tenants in CoprHD database.
 *
 * @brief Updates CoprHD OSTenant objects.
 * @return Response code 200
 * @see OSTenant
 */
@PUT
@Path("/ostenants/sync")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SECURITY_ADMIN })
public Response synchronizeOpenstackTenants() {
    List<KeystoneTenant> openstackTenantsList = listOpenstackTenants().getOpenstackTenants();
    List<OSTenant> coprhdOsTenantsList = getOsTenantsFromCoprhdDb();
    for (Iterator<KeystoneTenant> i = openstackTenantsList.iterator(); i.hasNext(); ) {
        KeystoneTenant tenant = i.next();
        for (Iterator<OSTenant> j = coprhdOsTenantsList.iterator(); j.hasNext(); ) {
            OSTenant osTenant = j.next();
            // Remove Tenant from both list once match is found.
            if (osTenant.getOsId().equals(tenant.getId())) {
                j.remove();
                i.remove();
            }
        }
    }
    // Remove OSTenant from CoprHD when related Tenant was removed in OpenStack.
    for (OSTenant osTenant : coprhdOsTenantsList) {
        _dbClient.removeObject(osTenant);
    }
    // Create OOSTenant in CoprHD for every new Tenant in OpenStack.
    for (KeystoneTenant keystoneTenant : openstackTenantsList) {
        OSTenant tenant = _keystoneUtils.mapToOsTenant(keystoneTenant);
        tenant.setId(URIUtil.createId(OSTenant.class));
        _dbClient.createObject(tenant);
    }
    return Response.ok().build();
}
Also used : KeystoneTenant(com.emc.storageos.keystone.restapi.model.response.KeystoneTenant) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 7 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