Search in sources :

Example 6 with KeystoneApiClient

use of com.emc.storageos.keystone.restapi.KeystoneApiClient in project coprhd-controller by CoprHD.

the class KeystoneUtils method deleteCinderEndpoints.

/**
 * Delete endpoints for cinder service.
 *
 * @param managerDN of an Authentication Provider.
 * @param serverUrls of an Authentication Provider
 * @param managerPassword of an Authentication Provider
 */
public void deleteCinderEndpoints(String managerDN, StringSet serverUrls, String managerPassword) {
    // Create a new KeystoneAPI.
    KeystoneApiClient keystoneApi = getKeystoneApi(managerDN, serverUrls, managerPassword);
    // Get a cinderv2 service id.
    String serviceIdV2 = findServiceId(keystoneApi, KeystoneUtils.OPENSTACK_CINDER_V2_NAME);
    // Get a cinderv1 service id.
    String serviceIdV1 = findServiceId(keystoneApi, KeystoneUtils.OPENSTACK_CINDER_V1_NAME);
    // Delete endpoint when cinderv2 service exist.
    if (serviceIdV2 != null) {
        // Delete endpoint for cinderv2 service.
        deleteKeystoneEndpoint(keystoneApi, serviceIdV2);
    }
    // Delete endpoint when cinder service exist.
    if (serviceIdV1 != null) {
        // Delete endpoint for cinder service.
        deleteKeystoneEndpoint(keystoneApi, serviceIdV1);
    }
}
Also used : KeystoneApiClient(com.emc.storageos.keystone.restapi.KeystoneApiClient)

Example 7 with KeystoneApiClient

use of com.emc.storageos.keystone.restapi.KeystoneApiClient in project coprhd-controller by CoprHD.

the class KeystoneUtils method populateKeystoneToken.

/**
 * Populate or Modify the keystone token
 * in authentication provider.
 *
 * @param managerDN of an Authentication Provider.
 * @param serverUrls of an Authentication Provider
 * @param password of an Authentication Provider
 *
 * @return StringMap containing keystone authentication keys.
 */
public StringMap populateKeystoneToken(StringSet serverUrls, String managerDN, String password) {
    URI authUri = retrieveUriFromServerUrls(serverUrls);
    StringMap usernameAndTenantMap = getUsernameAndTenant(managerDN);
    String username = usernameAndTenantMap.get(CinderConstants.USERNAME);
    String tenantName = usernameAndTenantMap.get(CinderConstants.TENANTNAME);
    KeystoneApiClient keystoneApi = getKeystoneApi(authUri, username, password, tenantName);
    keystoneApi.authenticate_keystone();
    StringMap keystoneAuthKeys = new StringMap();
    keystoneAuthKeys.put(KeystoneConstants.AUTH_TOKEN, keystoneApi.getAuthToken());
    return keystoneAuthKeys;
}
Also used : KeystoneApiClient(com.emc.storageos.keystone.restapi.KeystoneApiClient) URI(java.net.URI)

Example 8 with KeystoneApiClient

use of com.emc.storageos.keystone.restapi.KeystoneApiClient in project coprhd-controller by CoprHD.

the class KeystoneUtils method getTenantWithId.

/**
 * Retrieves OpenStack Tenant with given id.
 *
 * @param id Tenant ID.
 *
 * @return OpenStack Tenant.
 */
public KeystoneTenant getTenantWithId(String id) {
    AuthnProvider keystoneProvider = getKeystoneProvider();
    if (keystoneProvider == null) {
        throw APIException.internalServerErrors.targetIsNullOrEmpty("Keystone provider");
    }
    // Get Keystone API client.
    KeystoneApiClient keystoneApiClient = getKeystoneApi(keystoneProvider.getManagerDN(), keystoneProvider.getServerUrls(), keystoneProvider.getManagerPassword());
    for (KeystoneTenant tenant : keystoneApiClient.getKeystoneTenants().getTenants()) {
        if (tenant.getId().equals(id)) {
            return tenant;
        }
    }
    return null;
}
Also used : KeystoneApiClient(com.emc.storageos.keystone.restapi.KeystoneApiClient)

Example 9 with KeystoneApiClient

use of com.emc.storageos.keystone.restapi.KeystoneApiClient in project coprhd-controller by CoprHD.

the class KeystoneUtils method getKeystoneApi.

/**
 * Get Keystone API client.
 *
 * @param authUri URI pointing to Keystone server.
 * @param username OpenStack username.
 * @param usernamePassword OpenStack password.
 * @param tenantName OpenStack tenantname.
 * @return keystoneApi KeystoneApiClient.
 */
public KeystoneApiClient getKeystoneApi(URI authUri, String username, String usernamePassword, String tenantName) {
    // Get Keystone API Client.
    KeystoneApiClient keystoneApi = (KeystoneApiClient) _keystoneApiFactory.getRESTClient(authUri, username, usernamePassword);
    keystoneApi.setTenantName(tenantName);
    return keystoneApi;
}
Also used : KeystoneApiClient(com.emc.storageos.keystone.restapi.KeystoneApiClient)

Aggregations

KeystoneApiClient (com.emc.storageos.keystone.restapi.KeystoneApiClient)9 URI (java.net.URI)3 StringSet (com.emc.storageos.db.client.model.StringSet)1 AuthTokenResponse (com.emc.storageos.keystone.restapi.model.response.AuthTokenResponse)1 KeystoneTenant (com.emc.storageos.keystone.restapi.model.response.KeystoneTenant)1 TenantListRestResp (com.emc.storageos.keystone.restapi.model.response.TenantListRestResp)1 StorageOSUser (com.emc.storageos.security.authentication.StorageOSUser)1 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)1 SecurityException (com.emc.storageos.security.exceptions.SecurityException)1 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)1 ArrayList (java.util.ArrayList)1 AuthenticationException (org.springframework.ldap.AuthenticationException)1 CommunicationException (org.springframework.ldap.CommunicationException)1 NameNotFoundException (org.springframework.ldap.NameNotFoundException)1 PartialResultException (org.springframework.ldap.PartialResultException)1