Search in sources :

Example 1 with Identifier

use of org.openstack4j.model.common.Identifier in project airavata by apache.

the class OS4JClientProvider method getOSClientV3.

/**
 * Function that authenticates to openstack using v3 APIs.
 * @param endPoint
 * @param userName
 * @param password
 * @param domain
 * @param project
 * @return OSClient object that can be used for other OpenStack operations.
 */
public static void getOSClientV3(String endPoint, String userName, String password, String domain, String project) {
    if (os == null || apiVersion == null || apiVersion != 3 || !os.getEndpoint().equals(endPoint)) {
        Identifier domainIdentifier = Identifier.byName(domain);
        Identifier projectIdentifier = Identifier.byName(project);
        os = OSFactory.builderV3().scopeToProject(projectIdentifier, domainIdentifier).endpoint(endPoint).credentials(userName, password, domainIdentifier).authenticate();
        apiVersion = 3;
    }
}
Also used : Identifier(org.openstack4j.model.common.Identifier)

Example 2 with Identifier

use of org.openstack4j.model.common.Identifier in project airavata by apache.

the class OS4JClientProvider method getOSClientV2.

/**
 * Function that authenticates to openstack using v2 APIs.
 * @param endPoint
 * @param userName
 * @param password
 * @param domain
 * @param project
 * @return OSClient object that can be used for other Openstack operations.
 */
public static void getOSClientV2(String endPoint, String userName, String password, String domain) {
    if (os == null || apiVersion == null || apiVersion != 2 || !os.getEndpoint().equals(endPoint)) {
        Identifier domainIdentifier = Identifier.byName(domain);
        // Identifier projectIdentifier = Identifier.byName(project);
        os = OSFactory.builderV3().endpoint(endPoint).credentials(userName, password, domainIdentifier).authenticate();
        apiVersion = 2;
    }
}
Also used : Identifier(org.openstack4j.model.common.Identifier)

Example 3 with Identifier

use of org.openstack4j.model.common.Identifier 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 4 with Identifier

use of org.openstack4j.model.common.Identifier 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)

Aggregations

Identifier (org.openstack4j.model.common.Identifier)4 OpenstackAuth (org.onosproject.openstacknode.api.OpenstackAuth)2 Perspective (org.onosproject.openstacknode.api.OpenstackAuth.Perspective)2 IOSClientBuilder (org.openstack4j.api.client.IOSClientBuilder)2 AuthenticationException (org.openstack4j.api.exceptions.AuthenticationException)2 Config (org.openstack4j.core.transport.Config)2 BridgeConfig (org.onosproject.net.behaviour.BridgeConfig)1