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));
}
}
}
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;
}
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();
}
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();
}
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());
}
});
});
}
Aggregations