Search in sources :

Example 11 with KubevirtNode

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

the class KubevirtListNodesCommand method json.

private String json(List<KubevirtNode> nodes) {
    ObjectMapper mapper = new ObjectMapper();
    ArrayNode result = mapper.createArrayNode();
    for (KubevirtNode node : nodes) {
        result.add(jsonForEntity(node, KubevirtNode.class));
    }
    return prettyJson(mapper, result.toString());
}
Also used : KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 12 with KubevirtNode

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

the class KubevirtSyncStateCommand method bootstrapKubevirtNodes.

private void bootstrapKubevirtNodes(KubevirtApiConfig config) {
    KubevirtNodeAdminService nodeAdminService = get(KubevirtNodeAdminService.class);
    Set<KubevirtNode> completeNodeSet = nodeAdminService.completeNodes();
    KubernetesClient k8sClient = k8sClient(config);
    if (k8sClient == null) {
        log.warn("Failed to connect to kubernetes API server");
        return;
    }
    for (Node node : k8sClient.nodes().list().getItems()) {
        KubevirtNode kubevirtNode = buildKubevirtNode(node);
        // flow rules in worker nodes
        if (kubevirtNode.type() == WORKER) {
            if (completeNodeSet.stream().map(KubevirtNode::hostname).filter(name -> name.equals(kubevirtNode.hostname())).findAny().isPresent()) {
                print("Initializing %s because the node was COMPLETE state.", kubevirtNode.hostname());
                KubevirtNode updated = kubevirtNode.updateState(INIT);
                nodeAdminService.updateNode(updated);
            } else {
                nodeAdminService.updateNode(kubevirtNode);
            }
        }
    }
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) KubevirtNodeUtil.buildKubevirtNode(org.onosproject.kubevirtnode.util.KubevirtNodeUtil.buildKubevirtNode) KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) KubevirtNodeUtil.buildKubevirtNode(org.onosproject.kubevirtnode.util.KubevirtNodeUtil.buildKubevirtNode) Node(io.fabric8.kubernetes.api.model.Node) KubevirtNodeAdminService(org.onosproject.kubevirtnode.api.KubevirtNodeAdminService)

Example 13 with KubevirtNode

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

the class KubevirtNodeManager method createNode.

@Override
public void createNode(KubevirtNode node) {
    checkNotNull(node, ERR_NULL_NODE);
    KubevirtNode intNode;
    KubevirtNode tunNode;
    if (node.intgBridge() == null) {
        String deviceIdStr = genDpidFromName(INTEGRATION_BRIDGE + "-" + node.hostname());
        checkNotNull(deviceIdStr, ERR_NULL_DEVICE_ID);
        intNode = node.updateIntgBridge(DeviceId.deviceId(deviceIdStr));
        checkArgument(!hasIntgBridge(intNode.intgBridge(), intNode.hostname()), NOT_DUPLICATED_MSG, intNode.intgBridge());
    } else {
        intNode = node;
        checkArgument(!hasIntgBridge(intNode.intgBridge(), intNode.hostname()), NOT_DUPLICATED_MSG, intNode.intgBridge());
    }
    if (node.tunBridge() == null) {
        String deviceIdStr = genDpidFromName(TUNNEL_BRIDGE + "-" + node.hostname());
        checkNotNull(deviceIdStr, ERR_NULL_DEVICE_ID);
        tunNode = intNode.updateTunBridge(DeviceId.deviceId(deviceIdStr));
        checkArgument(!hasTunBridge(tunNode.tunBridge(), tunNode.hostname()), NOT_DUPLICATED_MSG, tunNode.tunBridge());
    } else {
        tunNode = intNode;
        checkArgument(!hasTunBridge(tunNode.tunBridge(), tunNode.hostname()), NOT_DUPLICATED_MSG, tunNode.tunBridge());
    }
    nodeStore.createNode(tunNode);
    log.info(String.format(MSG_NODE, tunNode.hostname(), MSG_CREATED));
}
Also used : KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode)

Example 14 with KubevirtNode

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

the class KubevirtNodeManager method removeNode.

@Override
public KubevirtNode removeNode(String hostname) {
    checkArgument(!Strings.isNullOrEmpty(hostname), ERR_NULL_HOSTNAME);
    KubevirtNode node = nodeStore.removeNode(hostname);
    log.info(String.format(MSG_NODE, hostname, MSG_REMOVED));
    return node;
}
Also used : KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode)

Example 15 with KubevirtNode

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

the class KubevirtNodeManager method updateNode.

@Override
public void updateNode(KubevirtNode node) {
    checkNotNull(node, ERR_NULL_NODE);
    KubevirtNode intNode;
    KubevirtNode tunNode;
    KubevirtNode existingNode = nodeStore.node(node.hostname());
    checkNotNull(existingNode, ERR_NULL_NODE);
    DeviceId existIntgBridge = nodeStore.node(node.hostname()).intgBridge();
    if (node.intgBridge() == null) {
        intNode = node.updateIntgBridge(existIntgBridge);
        checkArgument(!hasIntgBridge(intNode.intgBridge(), intNode.hostname()), NOT_DUPLICATED_MSG, intNode.intgBridge());
    } else {
        intNode = node;
        checkArgument(!hasIntgBridge(intNode.intgBridge(), intNode.hostname()), NOT_DUPLICATED_MSG, intNode.intgBridge());
    }
    DeviceId existTunBridge = nodeStore.node(node.hostname()).tunBridge();
    if (intNode.tunBridge() == null) {
        tunNode = intNode.updateTunBridge(existTunBridge);
        checkArgument(!hasTunBridge(tunNode.tunBridge(), tunNode.hostname()), NOT_DUPLICATED_MSG, tunNode.tunBridge());
    } else {
        tunNode = intNode;
        checkArgument(!hasTunBridge(tunNode.tunBridge(), tunNode.hostname()), NOT_DUPLICATED_MSG, tunNode.tunBridge());
    }
    nodeStore.updateNode(tunNode);
    log.info(String.format(MSG_NODE, tunNode.hostname(), MSG_UPDATED));
}
Also used : KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) DeviceId(org.onosproject.net.DeviceId)

Aggregations

KubevirtNode (org.onosproject.kubevirtnode.api.KubevirtNode)46 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)11 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)11 KubevirtNodeAdminService (org.onosproject.kubevirtnode.api.KubevirtNodeAdminService)10 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)10 TrafficSelector (org.onosproject.net.flow.TrafficSelector)10 DefaultKubevirtNode (org.onosproject.kubevirtnode.api.DefaultKubevirtNode)9 PortNumber (org.onosproject.net.PortNumber)9 Produces (javax.ws.rs.Produces)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 GET (javax.ws.rs.GET)5 KubevirtNodeService (org.onosproject.kubevirtnode.api.KubevirtNodeService)5 KubevirtNodeJsonMatcher.matchesKubevirtNode (org.onosproject.kubevirtnode.codec.KubevirtNodeJsonMatcher.matchesKubevirtNode)5 MacAddress (org.onlab.packet.MacAddress)4 KubevirtPhyInterface (org.onosproject.kubevirtnode.api.KubevirtPhyInterface)4 Device (org.onosproject.net.Device)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3