Search in sources :

Example 1 with KubevirtRouterService

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));
        }
    }
}
Also used : KubevirtRouter(org.onosproject.kubevirtnetworking.api.KubevirtRouter) KubevirtRouterService(org.onosproject.kubevirtnetworking.api.KubevirtRouterService) KubevirtNetworkingUtil.genFormatString(org.onosproject.kubevirtnetworking.util.KubevirtNetworkingUtil.genFormatString)

Example 2 with KubevirtRouterService

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));
        }
    }
}
Also used : KubevirtFloatingIp(org.onosproject.kubevirtnetworking.api.KubevirtFloatingIp) KubevirtRouterService(org.onosproject.kubevirtnetworking.api.KubevirtRouterService) KubevirtNetworkingUtil.genFormatString(org.onosproject.kubevirtnetworking.util.KubevirtNetworkingUtil.genFormatString)

Example 3 with KubevirtRouterService

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

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();
}
Also used : KubevirtRouter(org.onosproject.kubevirtnetworking.api.KubevirtRouter) KubevirtRouterService(org.onosproject.kubevirtnetworking.api.KubevirtRouterService) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

KubevirtRouterService (org.onosproject.kubevirtnetworking.api.KubevirtRouterService)4 GET (javax.ws.rs.GET)2 Produces (javax.ws.rs.Produces)2 KubevirtFloatingIp (org.onosproject.kubevirtnetworking.api.KubevirtFloatingIp)2 KubevirtRouter (org.onosproject.kubevirtnetworking.api.KubevirtRouter)2 KubevirtNetworkingUtil.genFormatString (org.onosproject.kubevirtnetworking.util.KubevirtNetworkingUtil.genFormatString)2