Search in sources :

Example 1 with OpenstackAuth

use of org.onosproject.openstacknode.api.OpenstackAuth in project onos by opennetworkinglab.

the class OpenstackNetworkingUtil method buildEndpoint.

/**
 * Builds up and a complete endpoint URL from gateway node.
 *
 * @param node gateway node
 * @return a complete endpoint URL
 */
private static String buildEndpoint(OpenstackNode node) {
    OpenstackAuth auth = node.keystoneConfig().authentication();
    StringBuilder endpointSb = new StringBuilder();
    endpointSb.append(auth.protocol().name().toLowerCase());
    endpointSb.append("://");
    endpointSb.append(node.keystoneConfig().endpoint());
    return endpointSb.toString();
}
Also used : OpenstackAuth(org.onosproject.openstacknode.api.OpenstackAuth)

Example 2 with OpenstackAuth

use of org.onosproject.openstacknode.api.OpenstackAuth 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 3 with OpenstackAuth

use of org.onosproject.openstacknode.api.OpenstackAuth 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 4 with OpenstackAuth

use of org.onosproject.openstacknode.api.OpenstackAuth in project onos by opennetworkinglab.

the class OpenstackNodeCodecTest method testOpenstackObsoleteControllerNodeDecode.

/**
 * Tests the openstack obsolete controller node decoding.
 */
@Test
public void testOpenstackObsoleteControllerNodeDecode() throws IOException {
    OpenstackNode node = getOpenstackNode("OpenstackObsoleteControllerNode.json");
    assertThat(node.hostname(), is("controller"));
    assertThat(node.type().name(), is("CONTROLLER"));
    assertThat(node.managementIp().toString(), is("172.16.130.10"));
    KeystoneConfig keystoneConfig = node.keystoneConfig();
    OpenstackAuth auth = keystoneConfig.authentication();
    String endpoint = keystoneConfig.endpoint();
    assertThat(auth.version(), is("v2.0"));
    assertThat(auth.protocol(), is(OpenstackAuth.Protocol.HTTP));
    assertThat(auth.username(), is("admin"));
    assertThat(auth.password(), is("nova"));
    assertThat(auth.project(), is("admin"));
    assertThat(auth.perspective(), is(OpenstackAuth.Perspective.PUBLIC));
    assertThat(endpoint, is("172.16.130.10:35357/v2.0"));
}
Also used : OpenstackAuth(org.onosproject.openstacknode.api.OpenstackAuth) DefaultOpenstackAuth(org.onosproject.openstacknode.api.DefaultOpenstackAuth) KeystoneConfig(org.onosproject.openstacknode.api.KeystoneConfig) DefaultKeystoneConfig(org.onosproject.openstacknode.api.DefaultKeystoneConfig) OpenstackNodeJsonMatcher.matchesOpenstackNode(org.onosproject.openstacknode.codec.OpenstackNodeJsonMatcher.matchesOpenstackNode) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) DefaultOpenstackNode(org.onosproject.openstacknode.api.DefaultOpenstackNode) Test(org.junit.Test)

Example 5 with OpenstackAuth

use of org.onosproject.openstacknode.api.OpenstackAuth in project onos by opennetworkinglab.

the class KeystoneConfigCodec method decode.

@Override
public KeystoneConfig decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    String endpoint = nullIsIllegal(json.get(ENDPOINT).asText(), ENDPOINT + MISSING_MESSAGE);
    // parse authentication
    JsonNode authJson = nullIsIllegal(json.get(AUTHENTICATION), AUTHENTICATION + MISSING_MESSAGE);
    final JsonCodec<OpenstackAuth> authCodec = context.codec(OpenstackAuth.class);
    OpenstackAuth auth = authCodec.decode((ObjectNode) authJson.deepCopy(), context);
    return DefaultKeystoneConfig.builder().endpoint(endpoint).authentication(auth).build();
}
Also used : OpenstackAuth(org.onosproject.openstacknode.api.OpenstackAuth) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Aggregations

OpenstackAuth (org.onosproject.openstacknode.api.OpenstackAuth)10 DefaultKeystoneConfig (org.onosproject.openstacknode.api.DefaultKeystoneConfig)4 DefaultOpenstackNode (org.onosproject.openstacknode.api.DefaultOpenstackNode)4 KeystoneConfig (org.onosproject.openstacknode.api.KeystoneConfig)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 Test (org.junit.Test)3 DefaultOpenstackAuth (org.onosproject.openstacknode.api.DefaultOpenstackAuth)3 NeutronConfig (org.onosproject.openstacknode.api.NeutronConfig)3 OpenstackNode (org.onosproject.openstacknode.api.OpenstackNode)3 OpenstackNodeJsonMatcher.matchesOpenstackNode (org.onosproject.openstacknode.codec.OpenstackNodeJsonMatcher.matchesOpenstackNode)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 DefaultNeutronConfig (org.onosproject.openstacknode.api.DefaultNeutronConfig)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 Identifier (org.openstack4j.model.common.Identifier)2 ArrayList (java.util.ArrayList)1 BridgeConfig (org.onosproject.net.behaviour.BridgeConfig)1 ControllerInfo (org.onosproject.net.behaviour.ControllerInfo)1