Search in sources :

Example 1 with NeutronConfig

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

the class NeutronConfigCodec method decode.

@Override
public NeutronConfig decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    boolean useMetadataProxy = nullIsIllegal(json.get(USE_METADATA_PROXY).asBoolean(), USE_METADATA_PROXY + MISSING_MESSAGE);
    String metadataProxySecret = nullIsIllegal(json.get(METADATA_PROXY_SECRET).asText(), METADATA_PROXY_SECRET + MISSING_MESSAGE);
    NeutronConfig.Builder builder = DefaultNeutronConfig.builder().useMetadataProxy(useMetadataProxy).metadataProxySecret(metadataProxySecret);
    JsonNode novaMetadataIp = json.get(NOVA_METADATA_IP);
    if (novaMetadataIp != null) {
        builder.novaMetadataIp(novaMetadataIp.asText());
    }
    JsonNode novaMetadataPort = json.get(NOVA_METADATA_PORT);
    if (novaMetadataPort != null) {
        builder.novaMetadataPort(novaMetadataPort.asInt());
    }
    return builder.build();
}
Also used : DefaultNeutronConfig(org.onosproject.openstacknode.api.DefaultNeutronConfig) NeutronConfig(org.onosproject.openstacknode.api.NeutronConfig) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 2 with NeutronConfig

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

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

use of org.onosproject.openstacknode.api.NeutronConfig 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

NeutronConfig (org.onosproject.openstacknode.api.NeutronConfig)4 DefaultKeystoneConfig (org.onosproject.openstacknode.api.DefaultKeystoneConfig)3 DefaultNeutronConfig (org.onosproject.openstacknode.api.DefaultNeutronConfig)3 DefaultOpenstackNode (org.onosproject.openstacknode.api.DefaultOpenstackNode)3 KeystoneConfig (org.onosproject.openstacknode.api.KeystoneConfig)3 OpenstackAuth (org.onosproject.openstacknode.api.OpenstackAuth)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 Test (org.junit.Test)2 DefaultOpenstackAuth (org.onosproject.openstacknode.api.DefaultOpenstackAuth)2 OpenstackNode (org.onosproject.openstacknode.api.OpenstackNode)2 OpenstackNodeJsonMatcher.matchesOpenstackNode (org.onosproject.openstacknode.codec.OpenstackNodeJsonMatcher.matchesOpenstackNode)2 ArrayList (java.util.ArrayList)1 ControllerInfo (org.onosproject.net.behaviour.ControllerInfo)1 DpdkConfig (org.onosproject.openstacknode.api.DpdkConfig)1 OpenstackPhyInterface (org.onosproject.openstacknode.api.OpenstackPhyInterface)1 OpenstackSshAuth (org.onosproject.openstacknode.api.OpenstackSshAuth)1