Search in sources :

Example 41 with KubevirtNode

use of org.onosproject.kubevirtnode.api.KubevirtNode in project onos by opennetworkinglab.

the class KubevirtNodeWebResource method stateOfNode.

/**
 * Obtains the state of the KubeVirt node.
 *
 * @param hostname hostname of the KubeVirt
 * @return the state of the KubeVirt node in Json
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("state/{hostname}")
public Response stateOfNode(@PathParam("hostname") String hostname) {
    log.trace(String.format(MESSAGE_NODE, QUERY));
    KubevirtNodeAdminService service = get(KubevirtNodeAdminService.class);
    KubevirtNode node = service.node(hostname);
    String nodeState = node != null ? node.state().toString() : NOT_EXIST;
    return ok(mapper().createObjectNode().put(STATE, nodeState)).build();
}
Also used : KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) KubevirtNodeAdminService(org.onosproject.kubevirtnode.api.KubevirtNodeAdminService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 42 with KubevirtNode

use of org.onosproject.kubevirtnode.api.KubevirtNode in project onos by opennetworkinglab.

the class KubevirtNodeWebResource method readNodeConfiguration.

private Set<KubevirtNode> readNodeConfiguration(InputStream input) {
    Set<KubevirtNode> nodeSet = Sets.newHashSet();
    try {
        JsonNode jsonTree = readTreeFromStream(mapper().enable(INDENT_OUTPUT), input);
        ArrayNode nodes = (ArrayNode) jsonTree.path(NODES);
        nodes.forEach(node -> {
            try {
                ObjectNode objectNode = node.deepCopy();
                KubevirtNode kubevirtNode = codec(KubevirtNode.class).decode(objectNode, this);
                nodeSet.add(kubevirtNode);
            } catch (Exception e) {
                log.error("Exception occurred due to {}", e);
                throw new IllegalArgumentException();
            }
        });
    } catch (Exception e) {
        throw new IllegalArgumentException(e);
    }
    return nodeSet;
}
Also used : KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 43 with KubevirtNode

use of org.onosproject.kubevirtnode.api.KubevirtNode in project onos by opennetworkinglab.

the class KubevirtNodeCodecTest method testKubevirtComputeNodeDecode.

/**
 * Tests the kubevirt compute node decoding.
 *
 * @throws IOException io exception
 */
@Test
public void testKubevirtComputeNodeDecode() throws IOException {
    KubevirtNode node = getKubevirtNode("KubevirtWorkerNode.json");
    assertThat(node.hostname(), is("worker-01"));
    assertThat(node.type().name(), is("WORKER"));
    assertThat(node.managementIp().toString(), is("172.16.130.4"));
    assertThat(node.dataIp().toString(), is("172.16.130.4"));
    assertThat(node.intgBridge().toString(), is("of:00000000000000a1"));
    assertThat(node.tunBridge().toString(), is("of:00000000000000a2"));
    assertThat(node.phyIntfs().size(), is(2));
    node.phyIntfs().forEach(intf -> {
        if (intf.network().equals("mgmtnetwork")) {
            assertThat(intf.intf(), is("eth3"));
            assertThat(intf.physBridge().toString(), is("of:00000000000000a3"));
        }
        if (intf.network().equals("oamnetwork")) {
            assertThat(intf.intf(), is("eth4"));
            assertThat(intf.physBridge().toString(), is("of:00000000000000a4"));
        }
    });
}
Also used : DefaultKubevirtNode(org.onosproject.kubevirtnode.api.DefaultKubevirtNode) KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) KubevirtNodeJsonMatcher.matchesKubevirtNode(org.onosproject.kubevirtnode.codec.KubevirtNodeJsonMatcher.matchesKubevirtNode) Test(org.junit.Test)

Example 44 with KubevirtNode

use of org.onosproject.kubevirtnode.api.KubevirtNode in project onos by opennetworkinglab.

the class KubevirtNodeCodecTest method testKubevirtGatweayNodeEncode.

/**
 * Tests the kubevirt gateway node encoding.
 */
@Test
public void testKubevirtGatweayNodeEncode() {
    KubevirtNode node = DefaultKubevirtNode.builder().hostname("gateway").type(KubevirtNode.Type.GATEWAY).state(KubevirtNodeState.INIT).managementIp(IpAddress.valueOf("10.10.10.1")).intgBridge(DeviceId.deviceId("br-int")).tunBridge(DeviceId.deviceId("br-tun")).dataIp(IpAddress.valueOf("20.20.20.2")).gatewayBridgeName("gateway").build();
    ObjectNode nodeJson = kubevirtNodeCodec.encode(node, context);
    assertThat(nodeJson, matchesKubevirtNode(node));
}
Also used : DefaultKubevirtNode(org.onosproject.kubevirtnode.api.DefaultKubevirtNode) KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) KubevirtNodeJsonMatcher.matchesKubevirtNode(org.onosproject.kubevirtnode.codec.KubevirtNodeJsonMatcher.matchesKubevirtNode) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Test(org.junit.Test)

Example 45 with KubevirtNode

use of org.onosproject.kubevirtnode.api.KubevirtNode in project onos by opennetworkinglab.

the class KubevirtNodeCodecTest method testKubevirtGatewayNodeDecode.

/**
 * Tests the kubevirt gateway node decoding.
 *
 * @throws IOException io exception
 */
@Test
public void testKubevirtGatewayNodeDecode() throws IOException {
    KubevirtNode node = getKubevirtNode("KubevirtGatewayNode.json");
    assertThat(node.hostname(), is("gateway-01"));
    assertThat(node.type().name(), is("GATEWAY"));
    assertThat(node.managementIp().toString(), is("172.16.130.4"));
    assertThat(node.dataIp().toString(), is("172.16.130.4"));
    assertThat(node.intgBridge().toString(), is("of:00000000000000a1"));
    assertThat(node.tunBridge().toString(), is("of:00000000000000a2"));
    assertThat(node.gatewayBridgeName(), is("gateway"));
}
Also used : DefaultKubevirtNode(org.onosproject.kubevirtnode.api.DefaultKubevirtNode) KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) KubevirtNodeJsonMatcher.matchesKubevirtNode(org.onosproject.kubevirtnode.codec.KubevirtNodeJsonMatcher.matchesKubevirtNode) Test(org.junit.Test)

Aggregations

KubevirtNode (org.onosproject.kubevirtnode.api.KubevirtNode)49 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)13 TrafficSelector (org.onosproject.net.flow.TrafficSelector)13 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)13 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)12 PortNumber (org.onosproject.net.PortNumber)11 KubevirtNodeAdminService (org.onosproject.kubevirtnode.api.KubevirtNodeAdminService)10 DefaultKubevirtNode (org.onosproject.kubevirtnode.api.DefaultKubevirtNode)9 Produces (javax.ws.rs.Produces)8 KubevirtNodeService (org.onosproject.kubevirtnode.api.KubevirtNodeService)8 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)6 Path (javax.ws.rs.Path)6 Test (org.junit.Test)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 Set (java.util.Set)5 GET (javax.ws.rs.GET)5 MacAddress (org.onlab.packet.MacAddress)5 DeviceId (org.onosproject.net.DeviceId)5 DeviceService (org.onosproject.net.device.DeviceService)5 Logger (org.slf4j.Logger)5