Search in sources :

Example 1 with KubevirtNodeService

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

the class DefaultKubevirtPort method tenantDeviceId.

@Override
public DeviceId tenantDeviceId() {
    KubevirtNetworkService networkService = DefaultServiceDirectory.getService(KubevirtNetworkService.class);
    KubevirtNodeService nodeService = DefaultServiceDirectory.getService(KubevirtNodeService.class);
    KubevirtNetwork network = networkService.network(networkId);
    KubevirtNode node = nodeService.node(deviceId);
    if (network == null || node == null) {
        return null;
    } else {
        return network.tenantDeviceId(node.hostname());
    }
}
Also used : KubevirtNodeService(org.onosproject.kubevirtnode.api.KubevirtNodeService) KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode)

Example 2 with KubevirtNodeService

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

the class KubevirtHostnameCompleter method complete.

@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    StringsCompleter delegate = new StringsCompleter();
    KubevirtNodeService nodeService = get(KubevirtNodeService.class);
    Set<String> hostnames = nodeService.nodes().stream().map(KubevirtNode::hostname).collect(Collectors.toSet());
    SortedSet<String> strings = delegate.getStrings();
    strings.addAll(hostnames);
    return delegate.complete(session, commandLine, candidates);
}
Also used : KubevirtNodeService(org.onosproject.kubevirtnode.api.KubevirtNodeService) StringsCompleter(org.apache.karaf.shell.support.completers.StringsCompleter)

Example 3 with KubevirtNodeService

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

the class KubevirtCheckNodeCommand method doExecute.

@Override
protected void doExecute() throws Exception {
    KubevirtNodeService nodeService = get(KubevirtNodeService.class);
    DeviceService deviceService = get(DeviceService.class);
    KubevirtNode node = nodeService.node(hostname);
    if (node == null) {
        print("Cannot find %s from registered nodes", hostname);
        return;
    }
    print("[Integration Bridge Status]");
    Device intgBridge = deviceService.getDevice(node.intgBridge());
    if (intgBridge != null) {
        print("%s %s=%s available=%s %s", deviceService.isAvailable(intgBridge.id()) ? MSG_PASS : MSG_FAIL, INTEGRATION_BRIDGE, intgBridge.id(), deviceService.isAvailable(intgBridge.id()), intgBridge.annotations());
    }
    print("");
    print("[Tunnel Bridge Status]");
    Device tunBridge = deviceService.getDevice(node.tunBridge());
    if (tunBridge != null) {
        print("%s %s=%s available=%s %s", deviceService.isAvailable(tunBridge.id()) ? MSG_PASS : MSG_FAIL, TUNNEL_BRIDGE, tunBridge.id(), deviceService.isAvailable(tunBridge.id()), tunBridge.annotations());
        if (node.dataIp() != null) {
            printPortState(deviceService, node.tunBridge(), VXLAN);
            printPortState(deviceService, node.tunBridge(), GRE);
            printPortState(deviceService, node.tunBridge(), GENEVE);
        }
    }
}
Also used : KubevirtNodeService(org.onosproject.kubevirtnode.api.KubevirtNodeService) KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService)

Example 4 with KubevirtNodeService

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

the class KubevirtListNodesCommand method doExecute.

@Override
protected void doExecute() throws Exception {
    KubevirtNodeService nodeService = get(KubevirtNodeService.class);
    List<KubevirtNode> nodes = Lists.newArrayList(nodeService.nodes());
    nodes.sort(Comparator.comparing(KubevirtNode::hostname));
    String format = genFormatString(ImmutableList.of(HOSTNAME_LENGTH, TYPE_LENGTH, MANAGEMENT_IP_LENGTH, DATA_IP_LENGTH, STATUS));
    if (outputJson()) {
        print("%s", json(nodes));
    } else {
        print(format, "Hostname", "Type", "Management IP", "Data IP", "State");
        for (KubevirtNode node : nodes) {
            print(format, StringUtils.substring(node.hostname(), 0, HOSTNAME_LENGTH - MARGIN_LENGTH), node.type(), StringUtils.substring(node.managementIp().toString(), 0, MANAGEMENT_IP_LENGTH - MARGIN_LENGTH), node.dataIp() != null ? StringUtils.substring(node.dataIp().toString(), 0, DATA_IP_LENGTH - MARGIN_LENGTH) : "", node.state());
        }
        print("Total %s nodes", nodeService.nodes().size());
    }
}
Also used : KubevirtNodeService(org.onosproject.kubevirtnode.api.KubevirtNodeService) KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) KubevirtNodeUtil.genFormatString(org.onosproject.kubevirtnode.util.KubevirtNodeUtil.genFormatString)

Example 5 with KubevirtNodeService

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

the class KubevirtNodeWebResource method healthz.

/**
 * Returns the health check result.
 *
 * @return 200 OK with health check result, 404 not found
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("healthz")
public Response healthz() {
    KubevirtApiConfigService configService = get(KubevirtApiConfigService.class);
    KubevirtNodeService nodeService = get(KubevirtNodeService.class);
    // TODO: we need to add more health check items
    boolean allInit = true;
    KubevirtApiConfig config = configService.apiConfig();
    if (nodeService.nodes().size() == 0) {
        allInit = false;
    } else {
        for (KubevirtNode node : nodeService.nodes()) {
            if (node.state() != INIT) {
                allInit = false;
            }
        }
    }
    String result = ERROR;
    if (config != null && !allInit) {
        result = OK;
    }
    ObjectNode jsonResult = mapper().createObjectNode();
    jsonResult.put(API_CONFIG, result);
    return ok(jsonResult).build();
}
Also used : KubevirtNodeService(org.onosproject.kubevirtnode.api.KubevirtNodeService) KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) KubevirtApiConfig(org.onosproject.kubevirtnode.api.KubevirtApiConfig) KubevirtApiConfigService(org.onosproject.kubevirtnode.api.KubevirtApiConfigService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

KubevirtNodeService (org.onosproject.kubevirtnode.api.KubevirtNodeService)5 KubevirtNode (org.onosproject.kubevirtnode.api.KubevirtNode)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 StringsCompleter (org.apache.karaf.shell.support.completers.StringsCompleter)1 KubevirtApiConfig (org.onosproject.kubevirtnode.api.KubevirtApiConfig)1 KubevirtApiConfigService (org.onosproject.kubevirtnode.api.KubevirtApiConfigService)1 KubevirtNodeUtil.genFormatString (org.onosproject.kubevirtnode.util.KubevirtNodeUtil.genFormatString)1 Device (org.onosproject.net.Device)1 DeviceService (org.onosproject.net.device.DeviceService)1