Search in sources :

Example 1 with KubevirtFloatingIp

use of org.onosproject.kubevirtnetworking.api.KubevirtFloatingIp in project onos by opennetworkinglab.

the class KubevirtListFloatingIpCommand method doExecute.

@Override
protected void doExecute() throws Exception {
    KubevirtRouterService service = get(KubevirtRouterService.class);
    List<KubevirtFloatingIp> fips = Lists.newArrayList(service.floatingIps());
    fips.sort(Comparator.comparing(KubevirtFloatingIp::networkName));
    String format = genFormatString(ImmutableList.of(CLI_NAME_LENGTH, CLI_IP_ADDRESS_LENGTH, CLI_NAME_LENGTH, CLI_NAME_LENGTH, CLI_IP_ADDRESS_LENGTH));
    if (outputJson()) {
        print("%s", json(fips));
    } else {
        print(format, "Network Name", "Floating IP", "POD Name", "VM Name", "Fixed IP");
        for (KubevirtFloatingIp fip : fips) {
            String fixedIp = fip.fixedIp() == null ? "N/A" : fip.fixedIp().toString();
            String podName = fip.podName() == null ? "N/A" : fip.podName();
            String vmName = fip.vmName() == null ? "N/A" : fip.vmName();
            print(format, StringUtils.substring(fip.networkName(), 0, CLI_NAME_LENGTH - CLI_MARGIN_LENGTH), StringUtils.substring(fip.floatingIp().toString(), 0, CLI_IP_ADDRESS_LENGTH - CLI_MARGIN_LENGTH), StringUtils.substring(podName, 0, CLI_NAME_LENGTH - CLI_MARGIN_LENGTH), StringUtils.substring(vmName, 0, CLI_NAME_LENGTH - CLI_MARGIN_LENGTH), StringUtils.substring(fixedIp, 0, CLI_IP_ADDRESS_LENGTH - CLI_MARGIN_LENGTH));
        }
    }
}
Also used : KubevirtFloatingIp(org.onosproject.kubevirtnetworking.api.KubevirtFloatingIp) KubevirtRouterService(org.onosproject.kubevirtnetworking.api.KubevirtRouterService) KubevirtNetworkingUtil.genFormatString(org.onosproject.kubevirtnetworking.util.KubevirtNetworkingUtil.genFormatString)

Example 2 with KubevirtFloatingIp

use of org.onosproject.kubevirtnetworking.api.KubevirtFloatingIp in project onos by opennetworkinglab.

the class KubevirtFloatingIpWatcher method parseKubevirtFloatingIp.

private KubevirtFloatingIp parseKubevirtFloatingIp(String resource) {
    try {
        ObjectMapper mapper = new ObjectMapper();
        JsonNode json = mapper.readTree(resource);
        ObjectNode spec = (ObjectNode) json.get("spec");
        return codec(KubevirtFloatingIp.class).decode(spec, this);
    } catch (IOException e) {
        log.error("Failed to parse kubevirt floating IP object");
    }
    return null;
}
Also used : KubevirtFloatingIp(org.onosproject.kubevirtnetworking.api.KubevirtFloatingIp) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with KubevirtFloatingIp

use of org.onosproject.kubevirtnetworking.api.KubevirtFloatingIp in project onos by opennetworkinglab.

the class KubevirtFloatingIpsWebResource method getFloatingIps.

/**
 * Returns set of all floating IPs.
 *
 * @return 200 OK with set of all floating IPs
 * @onos.rsModel KubevirtFloatingIps
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getFloatingIps() {
    KubevirtRouterService service = get(KubevirtRouterService.class);
    final Iterable<KubevirtFloatingIp> fips = service.floatingIps();
    return ok(encodeArray(KubevirtFloatingIp.class, FLOATING_IPS, fips)).build();
}
Also used : KubevirtFloatingIp(org.onosproject.kubevirtnetworking.api.KubevirtFloatingIp) KubevirtRouterService(org.onosproject.kubevirtnetworking.api.KubevirtRouterService) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 4 with KubevirtFloatingIp

use of org.onosproject.kubevirtnetworking.api.KubevirtFloatingIp in project onos by opennetworkinglab.

the class KubevirtMm5WebResource method getFloatingIp.

/**
 * Obtains the floating ip in Json array.
 *
 * @return floating ip information in Json
 */
@GET
@Path("fip")
@Produces(MediaType.APPLICATION_JSON)
public Response getFloatingIp() {
    log.trace(String.format(RECEIVED_REQUEST, QUERY_GET_FIP));
    KubevirtRouterService service = get(KubevirtRouterService.class);
    final Iterable<KubevirtFloatingIp> fips = service.floatingIps();
    return ok(encodeArray(KubevirtFloatingIp.class, FLOATING_IPS, fips)).build();
}
Also used : KubevirtFloatingIp(org.onosproject.kubevirtnetworking.api.KubevirtFloatingIp) KubevirtRouterService(org.onosproject.kubevirtnetworking.api.KubevirtRouterService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 5 with KubevirtFloatingIp

use of org.onosproject.kubevirtnetworking.api.KubevirtFloatingIp in project onos by opennetworkinglab.

the class KubevirtPrometheusAssuranceManager method publishFipMetrics.

private void publishFipMetrics() {
    if (prometheusExporter == null) {
        log.error("Prometheus Server isn't ready.");
        return;
    }
    String[] fipLabelValues = new String[5];
    nodeService.completeNodes(GATEWAY).forEach(node -> {
        flowRuleService.getFlowEntries(node.intgBridge()).forEach(flowEntry -> {
            if (((IndexTableId) flowEntry.table()).id() == GW_ENTRY_TABLE && flowEntry.priority() == PRIORITY_FLOATING_IP_UPSTREAM_RULE) {
                KubevirtFloatingIp floatingIp = floatingIpByUpstreamFlowEntry(flowEntry);
                if (floatingIp == null || floatingIp.vmName() == null) {
                    return;
                }
                fipLabelValues[0] = floatingIp.id();
                fipLabelValues[1] = floatingIp.floatingIp().toString();
                fipLabelValues[2] = node.hostname();
                fipLabelValues[3] = floatingIp.vmName();
                fipLabelValues[4] = floatingIp.networkName();
                pktFIPTx.labels(fipLabelValues).set(flowEntry.packets());
                byteFIPTx.labels(fipLabelValues).set(flowEntry.bytes());
            } else if (((IndexTableId) flowEntry.table()).id() == GW_ENTRY_TABLE && flowEntry.priority() == PRIORITY_FLOATING_IP_DOWNSTREAM_RULE) {
                KubevirtFloatingIp floatingIp = floatingIpByDownstreamFlowEntry(flowEntry);
                if (floatingIp == null || floatingIp.vmName() == null) {
                    return;
                }
                fipLabelValues[0] = floatingIp.id();
                fipLabelValues[1] = floatingIp.floatingIp().toString();
                fipLabelValues[2] = node.hostname();
                fipLabelValues[3] = floatingIp.vmName();
                fipLabelValues[4] = floatingIp.networkName();
                pktFIPRx.labels(fipLabelValues).set(flowEntry.packets());
                byteFIPRx.labels(fipLabelValues).set(flowEntry.bytes());
            }
        });
    });
}
Also used : KubevirtFloatingIp(org.onosproject.kubevirtnetworking.api.KubevirtFloatingIp) IndexTableId(org.onosproject.net.flow.IndexTableId)

Aggregations

KubevirtFloatingIp (org.onosproject.kubevirtnetworking.api.KubevirtFloatingIp)10 DefaultKubevirtFloatingIp (org.onosproject.kubevirtnetworking.api.DefaultKubevirtFloatingIp)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 KubevirtRouterService (org.onosproject.kubevirtnetworking.api.KubevirtRouterService)3 KubevirtFloatingIpJsonMatcher.matchesKubevirtFloatingIp (org.onosproject.kubevirtnetworking.codec.KubevirtFloatingIpJsonMatcher.matchesKubevirtFloatingIp)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 GET (javax.ws.rs.GET)2 Produces (javax.ws.rs.Produces)2 Test (org.junit.Test)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Path (javax.ws.rs.Path)1 KubevirtNetworkingUtil.genFormatString (org.onosproject.kubevirtnetworking.util.KubevirtNetworkingUtil.genFormatString)1 IndexTableId (org.onosproject.net.flow.IndexTableId)1