Search in sources :

Example 1 with AuthenticationException

use of org.openstack4j.api.exceptions.AuthenticationException in project onos by opennetworkinglab.

the class OpenstackNetworkingUtil method getConnectedClient.

/**
 * Obtains a connected openstack client.
 *
 * @param osNode openstack node
 * @return a connected openstack client
 */
public static OSClient getConnectedClient(OpenstackNode osNode) {
    OpenstackAuth auth = osNode.keystoneConfig().authentication();
    String endpoint = buildEndpoint(osNode);
    Perspective perspective = auth.perspective();
    Config config = getSslConfig();
    try {
        if (endpoint.contains(KEYSTONE_V2)) {
            IOSClientBuilder.V2 builder = OSFactory.builderV2().endpoint(endpoint).tenantName(auth.project()).credentials(auth.username(), auth.password()).withConfig(config);
            if (perspective != null) {
                builder.perspective(getFacing(perspective));
            }
            return builder.authenticate();
        } else if (endpoint.contains(KEYSTONE_V3)) {
            Identifier project = Identifier.byName(auth.project());
            Identifier domain = Identifier.byName(DOMAIN_DEFAULT);
            IOSClientBuilder.V3 builder = OSFactory.builderV3().endpoint(endpoint).credentials(auth.username(), auth.password(), domain).scopeToProject(project, domain).withConfig(config);
            if (perspective != null) {
                builder.perspective(getFacing(perspective));
            }
            return builder.authenticate();
        } else {
            log.warn("Unrecognized keystone version type");
            return null;
        }
    } catch (AuthenticationException e) {
        log.error("Authentication failed due to {}", e);
        return null;
    }
}
Also used : OpenstackAuth(org.onosproject.openstacknode.api.OpenstackAuth) Perspective(org.onosproject.openstacknode.api.OpenstackAuth.Perspective) Identifier(org.openstack4j.model.common.Identifier) IOSClientBuilder(org.openstack4j.api.client.IOSClientBuilder) AuthenticationException(org.openstack4j.api.exceptions.AuthenticationException) Config(org.openstack4j.core.transport.Config)

Example 2 with AuthenticationException

use of org.openstack4j.api.exceptions.AuthenticationException in project onos by opennetworkinglab.

the class OpenstackNodeUtil method getConnectedClient.

/**
 * Obtains a connected openstack client.
 *
 * @param osNode openstack node
 * @return a connected openstack client
 */
public static OSClient getConnectedClient(OpenstackNode osNode) {
    OpenstackAuth auth = osNode.keystoneConfig().authentication();
    String endpoint = buildEndpoint(osNode);
    Perspective perspective = auth.perspective();
    Config config = getSslConfig();
    try {
        if (endpoint.contains(KEYSTONE_V2)) {
            IOSClientBuilder.V2 builder = OSFactory.builderV2().endpoint(endpoint).tenantName(auth.project()).credentials(auth.username(), auth.password()).withConfig(config);
            if (perspective != null) {
                builder.perspective(getFacing(perspective));
            }
            return builder.authenticate();
        } else if (endpoint.contains(KEYSTONE_V3)) {
            Identifier project = Identifier.byName(auth.project());
            Identifier domain = Identifier.byName(DOMAIN_DEFAULT);
            IOSClientBuilder.V3 builder = OSFactory.builderV3().endpoint(endpoint).credentials(auth.username(), auth.password(), domain).scopeToProject(project, domain).withConfig(config);
            if (perspective != null) {
                builder.perspective(getFacing(perspective));
            }
            return builder.authenticate();
        } else {
            log.warn("Unrecognized keystone version type");
            return null;
        }
    } catch (AuthenticationException e) {
        log.error("Authentication failed due to {}", e);
        return null;
    }
}
Also used : OpenstackAuth(org.onosproject.openstacknode.api.OpenstackAuth) Perspective(org.onosproject.openstacknode.api.OpenstackAuth.Perspective) Identifier(org.openstack4j.model.common.Identifier) IOSClientBuilder(org.openstack4j.api.client.IOSClientBuilder) AuthenticationException(org.openstack4j.api.exceptions.AuthenticationException) Config(org.openstack4j.core.transport.Config) BridgeConfig(org.onosproject.net.behaviour.BridgeConfig)

Example 3 with AuthenticationException

use of org.openstack4j.api.exceptions.AuthenticationException in project so by onap.

the class OpenstackClientFactoryImpl method createOpenstackV3Client.

@Override
public OpenstackClient createOpenstackV3Client(OpenstackAccess osAccess) throws OpenstackClientException {
    Preconditions.checkNotNull(osAccess.getUrl(), "Keystone-v3 Auth: endpoint not set.");
    Preconditions.checkNotNull(osAccess.getUser(), "Keystone-v3 Auth: username not set.");
    Preconditions.checkNotNull(osAccess.getPassword(), "Keystone-v3 Auth: password not set.");
    Preconditions.checkNotNull(osAccess.getDomainNameIdentifier(), "Keystone-v3 Auth: domain not set.");
    Preconditions.checkNotNull(osAccess.getRegion(), "Keystone-v3 Auth: region not set.");
    Preconditions.checkNotNull(osAccess.getTenantId(), "Keystone-v3 Auth: tenant-id not set.");
    OSClientV3 client;
    try {
        OSFactory.enableHttpLoggingFilter(true);
        client = OSFactory.builderV3().endpoint(osAccess.getUrl()).credentials(osAccess.getUser(), osAccess.getPassword(), osAccess.getDomainNameIdentifier()).scopeToProject(Identifier.byId(osAccess.getTenantId()), osAccess.getProjectNameIdentifier()).authenticate().useRegion(osAccess.getRegion());
        return new OpenstackV3ClientImpl(client);
    } catch (AuthenticationException exception) {
        throw new OpenstackClientException("Failed to authenticate with Keystone-v3: " + osAccess.getUrl(), exception);
    }
}
Also used : OSClientV3(org.openstack4j.api.OSClient.OSClientV3) AuthenticationException(org.openstack4j.api.exceptions.AuthenticationException) OpenstackClientException(org.onap.so.heatbridge.openstack.api.OpenstackClientException) OpenstackV3ClientImpl(org.onap.so.heatbridge.openstack.api.OpenstackV3ClientImpl)

Example 4 with AuthenticationException

use of org.openstack4j.api.exceptions.AuthenticationException in project so by onap.

the class OpenstackClientFactoryImpl method createOpenstackV2Client.

@Override
public OpenstackClient createOpenstackV2Client(OpenstackAccess osAccess) throws OpenstackClientException {
    Preconditions.checkNotNull(osAccess.getUrl(), "Keystone-v2 Auth: endpoint not set.");
    Preconditions.checkNotNull(osAccess.getUser(), "Keystone-v2 Auth: username not set.");
    Preconditions.checkNotNull(osAccess.getPassword(), "Keystone-v2 Auth: password not set.");
    Preconditions.checkNotNull(osAccess.getTenantId(), "Keystone-v2 Auth: tenant-id not set.");
    Preconditions.checkNotNull(osAccess.getRegion(), "Keystone-v2 Auth: region not set.");
    OSClientV2 client;
    try {
        OSFactory.enableHttpLoggingFilter(true);
        client = OSFactory.builderV2().endpoint(osAccess.getUrl()).credentials(osAccess.getUser(), osAccess.getPassword()).tenantId(osAccess.getTenantId()).authenticate().useRegion(osAccess.getRegion());
        return new OpenstackV2ClientImpl(client);
    } catch (AuthenticationException exception) {
        throw new OpenstackClientException("Failed to authenticate with Keystone-v2.0: " + osAccess.getUrl(), exception);
    }
}
Also used : OSClientV2(org.openstack4j.api.OSClient.OSClientV2) OpenstackV2ClientImpl(org.onap.so.heatbridge.openstack.api.OpenstackV2ClientImpl) AuthenticationException(org.openstack4j.api.exceptions.AuthenticationException) OpenstackClientException(org.onap.so.heatbridge.openstack.api.OpenstackClientException)

Aggregations

AuthenticationException (org.openstack4j.api.exceptions.AuthenticationException)4 OpenstackClientException (org.onap.so.heatbridge.openstack.api.OpenstackClientException)2 OpenstackAuth (org.onosproject.openstacknode.api.OpenstackAuth)2 Perspective (org.onosproject.openstacknode.api.OpenstackAuth.Perspective)2 IOSClientBuilder (org.openstack4j.api.client.IOSClientBuilder)2 Config (org.openstack4j.core.transport.Config)2 Identifier (org.openstack4j.model.common.Identifier)2 OpenstackV2ClientImpl (org.onap.so.heatbridge.openstack.api.OpenstackV2ClientImpl)1 OpenstackV3ClientImpl (org.onap.so.heatbridge.openstack.api.OpenstackV3ClientImpl)1 BridgeConfig (org.onosproject.net.behaviour.BridgeConfig)1 OSClientV2 (org.openstack4j.api.OSClient.OSClientV2)1 OSClientV3 (org.openstack4j.api.OSClient.OSClientV3)1