Search in sources :

Example 1 with KeystoneConfig

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

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

the class OpenstackNetworkingUtilTest method testGetConnectedClient.

/**
 * Tests the getConnectedClient method.
 */
@Ignore
@Test
public void testGetConnectedClient() {
    OpenstackNode.Builder osNodeBuilderV2 = DefaultOpenstackNode.builder();
    OpenstackAuth.Builder osNodeAuthBuilderV2 = DefaultOpenstackAuth.builder().version("v2.0").protocol(OpenstackAuth.Protocol.HTTP).project("admin").username("admin").password("password").perspective(OpenstackAuth.Perspective.PUBLIC);
    String endpointV2 = "1.1.1.1:35357/v2.0";
    KeystoneConfig keystoneConfigV2 = DefaultKeystoneConfig.builder().authentication(osNodeAuthBuilderV2.build()).endpoint(endpointV2).build();
    openstackControlNodeV2 = osNodeBuilderV2.hostname("controllerv2").type(OpenstackNode.NodeType.CONTROLLER).managementIp(IpAddress.valueOf("1.1.1.1")).keystoneConfig(keystoneConfigV2).state(NodeState.COMPLETE).build();
    OpenstackNode.Builder osNodeBuilderV3 = DefaultOpenstackNode.builder();
    OpenstackAuth.Builder osNodeAuthBuilderV3 = DefaultOpenstackAuth.builder().version("v2").protocol(OpenstackAuth.Protocol.HTTP).project("admin").username("admin").password("password").perspective(OpenstackAuth.Perspective.PUBLIC);
    String endpointV3 = "2.2.2.2:80/v3";
    KeystoneConfig keystoneConfigV3 = DefaultKeystoneConfig.builder().authentication(osNodeAuthBuilderV3.build()).endpoint(endpointV3).build();
    openstackControlNodeV3 = osNodeBuilderV3.hostname("controllerv3").type(OpenstackNode.NodeType.CONTROLLER).managementIp(IpAddress.valueOf("2.2.2.2")).keystoneConfig(keystoneConfigV3).state(NodeState.COMPLETE).build();
    getConnectedClient(openstackControlNodeV2);
    getConnectedClient(openstackControlNodeV3);
}
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) DefaultOpenstackNode(org.onosproject.openstacknode.api.DefaultOpenstackNode) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) Ignore(org.junit.Ignore) OpenstackNodeTest(org.onosproject.openstacknode.api.OpenstackNodeTest) Test(org.junit.Test) OpenstackFloatingIpWebResourceTest(org.onosproject.openstacknetworking.web.OpenstackFloatingIpWebResourceTest) OpenstackNetworkWebResourceTest(org.onosproject.openstacknetworking.web.OpenstackNetworkWebResourceTest)

Example 3 with KeystoneConfig

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

the class OpenstackNodeCodec method decode.

@Override
public OpenstackNode decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    String hostname = nullIsIllegal(json.get(HOST_NAME).asText(), HOST_NAME + MISSING_MESSAGE);
    String type = nullIsIllegal(json.get(TYPE).asText(), TYPE + MISSING_MESSAGE);
    String mIp = nullIsIllegal(json.get(MANAGEMENT_IP).asText(), MANAGEMENT_IP + MISSING_MESSAGE);
    DefaultOpenstackNode.Builder nodeBuilder = DefaultOpenstackNode.builder().hostname(hostname).type(OpenstackNode.NodeType.valueOf(type)).state(NodeState.INIT).managementIp(IpAddress.valueOf(mIp));
    if (type.equals(GATEWAY)) {
        nodeBuilder.uplinkPort(nullIsIllegal(json.get(UPLINK_PORT).asText(), UPLINK_PORT + MISSING_MESSAGE));
    }
    if (type.equals(CONTROLLER)) {
        JsonNode keystoneConfigJson = json.get(KEYSTONE_CONFIG);
        KeystoneConfig keystoneConfig;
        if (keystoneConfigJson != null) {
            final JsonCodec<KeystoneConfig> keystoneConfigCodec = context.codec(KeystoneConfig.class);
            keystoneConfig = keystoneConfigCodec.decode((ObjectNode) keystoneConfigJson.deepCopy(), context);
        } else {
            JsonNode authJson = json.get(AUTHENTICATION);
            final JsonCodec<OpenstackAuth> authCodec = context.codec(OpenstackAuth.class);
            OpenstackAuth auth = authCodec.decode((ObjectNode) authJson.deepCopy(), context);
            String endpoint = nullIsIllegal(json.get(ENDPOINT).asText(), ENDPOINT + MISSING_MESSAGE);
            keystoneConfig = DefaultKeystoneConfig.builder().authentication(auth).endpoint(endpoint).build();
        }
        nodeBuilder.keystoneConfig(keystoneConfig);
    }
    if (json.get(VLAN_INTF_NAME) != null) {
        nodeBuilder.vlanIntf(json.get(VLAN_INTF_NAME).asText());
    }
    if (json.get(DATA_IP) != null) {
        nodeBuilder.dataIp(IpAddress.valueOf(json.get(DATA_IP).asText()));
    }
    JsonNode intBridgeJson = json.get(INTEGRATION_BRIDGE);
    if (intBridgeJson != null) {
        nodeBuilder.intgBridge(DeviceId.deviceId(intBridgeJson.asText()));
    }
    // parse physical interfaces
    List<OpenstackPhyInterface> phyIntfs = new ArrayList<>();
    JsonNode phyIntfsJson = json.get(PHYSICAL_INTERFACES);
    if (phyIntfsJson != null) {
        final JsonCodec<OpenstackPhyInterface> phyIntfCodec = context.codec(OpenstackPhyInterface.class);
        IntStream.range(0, phyIntfsJson.size()).forEach(i -> {
            ObjectNode intfJson = get(phyIntfsJson, i);
            phyIntfs.add(phyIntfCodec.decode(intfJson, context));
        });
    }
    nodeBuilder.phyIntfs(phyIntfs);
    // parse customized controllers
    List<ControllerInfo> controllers = new ArrayList<>();
    JsonNode controllersJson = json.get(CONTROLLERS);
    if (controllersJson != null) {
        final JsonCodec<ControllerInfo> controllerCodec = context.codec(ControllerInfo.class);
        IntStream.range(0, controllersJson.size()).forEach(i -> {
            ObjectNode controllerJson = get(controllersJson, i);
            controllers.add(controllerCodec.decode(controllerJson, context));
        });
    }
    nodeBuilder.controllers(controllers);
    // parse neutron config
    JsonNode neutronConfigJson = json.get(NEUTRON_CONFIG);
    if (neutronConfigJson != null) {
        final JsonCodec<NeutronConfig> neutronConfigJsonCodec = context.codec(NeutronConfig.class);
        NeutronConfig neutronConfig = neutronConfigJsonCodec.decode((ObjectNode) neutronConfigJson.deepCopy(), context);
        nodeBuilder.neutronConfig(neutronConfig);
    }
    // parse ssh authentication
    JsonNode sshAuthJson = json.get(SSH_AUTH);
    if (sshAuthJson != null) {
        final JsonCodec<OpenstackSshAuth> sshAuthJsonCodec = context.codec(OpenstackSshAuth.class);
        OpenstackSshAuth sshAuth = sshAuthJsonCodec.decode((ObjectNode) sshAuthJson.deepCopy(), context);
        nodeBuilder.sshAuthInfo(sshAuth);
    }
    // parse DPDK configuration
    JsonNode dpdkConfigJson = json.get(DPDK_CONFIG);
    if (dpdkConfigJson != null) {
        final JsonCodec<DpdkConfig> dpdkConfigJsonCodec = context.codec(DpdkConfig.class);
        DpdkConfig dpdkConfig = dpdkConfigJsonCodec.decode((ObjectNode) dpdkConfigJson.deepCopy(), context);
        nodeBuilder.dpdkConfig(dpdkConfig);
    }
    log.trace("node is {}", nodeBuilder.build().toString());
    return nodeBuilder.build();
}
Also used : OpenstackAuth(org.onosproject.openstacknode.api.OpenstackAuth) NeutronConfig(org.onosproject.openstacknode.api.NeutronConfig) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) KeystoneConfig(org.onosproject.openstacknode.api.KeystoneConfig) DefaultKeystoneConfig(org.onosproject.openstacknode.api.DefaultKeystoneConfig) DefaultOpenstackNode(org.onosproject.openstacknode.api.DefaultOpenstackNode) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) OpenstackPhyInterface(org.onosproject.openstacknode.api.OpenstackPhyInterface) DpdkConfig(org.onosproject.openstacknode.api.DpdkConfig) OpenstackSshAuth(org.onosproject.openstacknode.api.OpenstackSshAuth) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo)

Example 4 with KeystoneConfig

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

the class OpenstackNodeCodecTest method testOpenstackControllerNodeEncode.

/**
 * Tests the openstack controller node encoding.
 */
@Test
public void testOpenstackControllerNodeEncode() {
    OpenstackAuth auth = DefaultOpenstackAuth.builder().version("v2.0").protocol(OpenstackAuth.Protocol.HTTP).project("admin").username("admin").password("nova").perspective(OpenstackAuth.Perspective.PUBLIC).build();
    String endpoint = "172.16.130.10:35357/v2.0";
    KeystoneConfig keystoneConfig = DefaultKeystoneConfig.builder().endpoint(endpoint).authentication(auth).build();
    NeutronConfig neutronConfig = DefaultNeutronConfig.builder().useMetadataProxy(true).metadataProxySecret("onos").novaMetadataIp("172.16.130.10").novaMetadataPort(8775).build();
    OpenstackNode node = DefaultOpenstackNode.builder().hostname("controller").type(OpenstackNode.NodeType.CONTROLLER).state(NodeState.INIT).managementIp(IpAddress.valueOf("172.16.130.10")).keystoneConfig(keystoneConfig).neutronConfig(neutronConfig).build();
    ObjectNode nodeJson = openstackNodeCodec.encode(node, context);
    assertThat(nodeJson, matchesOpenstackNode(node));
}
Also used : OpenstackAuth(org.onosproject.openstacknode.api.OpenstackAuth) DefaultOpenstackAuth(org.onosproject.openstacknode.api.DefaultOpenstackAuth) DefaultNeutronConfig(org.onosproject.openstacknode.api.DefaultNeutronConfig) NeutronConfig(org.onosproject.openstacknode.api.NeutronConfig) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) 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 KeystoneConfig

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

the class OpenstackNodeCodecTest method testOpenstackControllerNodeDecode.

/**
 * Tests the openstack controller node decoding.
 */
@Test
public void testOpenstackControllerNodeDecode() throws IOException {
    OpenstackNode node = getOpenstackNode("OpenstackControllerNode.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"));
    NeutronConfig neutronConfig = node.neutronConfig();
    assertThat(neutronConfig.useMetadataProxy(), is(true));
    assertThat(neutronConfig.metadataProxySecret(), is("onos"));
    assertThat(neutronConfig.novaMetadataIp(), is("172.16.130.10"));
    assertThat(neutronConfig.novaMetadataPort(), is(8775));
}
Also used : OpenstackAuth(org.onosproject.openstacknode.api.OpenstackAuth) DefaultOpenstackAuth(org.onosproject.openstacknode.api.DefaultOpenstackAuth) DefaultNeutronConfig(org.onosproject.openstacknode.api.DefaultNeutronConfig) NeutronConfig(org.onosproject.openstacknode.api.NeutronConfig) 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)

Aggregations

DefaultKeystoneConfig (org.onosproject.openstacknode.api.DefaultKeystoneConfig)5 DefaultOpenstackNode (org.onosproject.openstacknode.api.DefaultOpenstackNode)5 KeystoneConfig (org.onosproject.openstacknode.api.KeystoneConfig)5 OpenstackAuth (org.onosproject.openstacknode.api.OpenstackAuth)5 Test (org.junit.Test)4 DefaultOpenstackAuth (org.onosproject.openstacknode.api.DefaultOpenstackAuth)4 OpenstackNode (org.onosproject.openstacknode.api.OpenstackNode)4 NeutronConfig (org.onosproject.openstacknode.api.NeutronConfig)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 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayList (java.util.ArrayList)1 Ignore (org.junit.Ignore)1 ControllerInfo (org.onosproject.net.behaviour.ControllerInfo)1 OpenstackFloatingIpWebResourceTest (org.onosproject.openstacknetworking.web.OpenstackFloatingIpWebResourceTest)1 OpenstackNetworkWebResourceTest (org.onosproject.openstacknetworking.web.OpenstackNetworkWebResourceTest)1 DpdkConfig (org.onosproject.openstacknode.api.DpdkConfig)1 OpenstackNodeTest (org.onosproject.openstacknode.api.OpenstackNodeTest)1 OpenstackPhyInterface (org.onosproject.openstacknode.api.OpenstackPhyInterface)1