use of org.onosproject.kubevirtnetworking.api.KubevirtRouterService in project onos by opennetworkinglab.
the class KubevirtListRouterCommand method doExecute.
@Override
protected void doExecute() throws Exception {
KubevirtRouterService service = get(KubevirtRouterService.class);
List<KubevirtRouter> routers = Lists.newArrayList(service.routers());
routers.sort(Comparator.comparing(KubevirtRouter::name));
String format = genFormatString(ImmutableList.of(CLI_NAME_LENGTH, CLI_FLAG_LENGTH, CLI_IP_ADDRESSES_LENGTH, CLI_IP_ADDRESS_LENGTH, CLI_NAME_LENGTH));
if (outputJson()) {
print("%s", json(routers));
} else {
print(format, "Name", "SNAT", "Internal", "External", "GatewayNode");
for (KubevirtRouter router : routers) {
Set<String> internalNetworks = router.internal();
String externalNetwork = router.external().values().stream().findAny().orElse(null);
String internal = internalNetworks.size() == 0 ? "[]" : internalNetworks.toString();
String external = externalNetwork == null ? "[]" : externalNetwork;
String gwNode = router.electedGateway() == null ? "N/A" : router.electedGateway();
print(format, StringUtils.substring(router.name(), 0, CLI_NAME_LENGTH - CLI_MARGIN_LENGTH), StringUtils.substring(String.valueOf(router.enableSnat()), 0, CLI_FLAG_LENGTH - CLI_MARGIN_LENGTH), StringUtils.substring(internal, 0, CLI_IP_ADDRESSES_LENGTH - CLI_MARGIN_LENGTH), StringUtils.substring(external, 0, CLI_IP_ADDRESS_LENGTH - CLI_MARGIN_LENGTH), StringUtils.substring(gwNode, 0, CLI_NAME_LENGTH - CLI_MARGIN_LENGTH));
}
}
}
use of org.onosproject.kubevirtnetworking.api.KubevirtRouterService 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.KubevirtRouterService 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.KubevirtRouterService in project onos by opennetworkinglab.
the class KubevirtRouterWebResource method getRouters.
/**
* Returns set of all routers.
*
* @return 200 OK with set of all routers
* @onos.rsModel KubevirtRouters
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getRouters() {
KubevirtRouterService service = get(KubevirtRouterService.class);
final Iterable<KubevirtRouter> routers = service.routers();
return ok(encodeArray(KubevirtRouter.class, ROUTERS, routers)).build();
}
Aggregations