Search in sources :

Example 1 with KubevirtNetworkService

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

the class KubevirtListIpAddressCommand method doExecute.

@Override
protected void doExecute() throws Exception {
    KubevirtNetworkService service = get(KubevirtNetworkService.class);
    if (networkId == null) {
        error("No network identifier was specified");
        return;
    }
    KubevirtNetwork network = service.network(networkId);
    if (network == null) {
        print("No network was found with the given network ID");
        return;
    }
    KubevirtIpPool pool = network.ipPool();
    if (pool == null) {
        print("No IP pool was found with the given network ID");
        return;
    }
    String format = genFormatString(ImmutableList.of(CLI_IP_ADDRESS_LENGTH, CLI_IP_ADDRESS_AVAILABILITY));
    print(format, "IP Address", "Availability");
    List<IpAddress> sortedAllocatedIps = new ArrayList<>(pool.allocatedIps());
    Collections.sort(sortedAllocatedIps);
    for (IpAddress ip : sortedAllocatedIps) {
        print(format, ip.toString(), "[ X ]");
    }
    List<IpAddress> sortedAvailableIps = new ArrayList<>(pool.availableIps());
    Collections.sort(sortedAvailableIps);
    for (IpAddress ip : sortedAvailableIps) {
        print(format, ip.toString(), "[ O ]");
    }
}
Also used : KubevirtNetworkService(org.onosproject.kubevirtnetworking.api.KubevirtNetworkService) KubevirtNetwork(org.onosproject.kubevirtnetworking.api.KubevirtNetwork) ArrayList(java.util.ArrayList) IpAddress(org.onlab.packet.IpAddress) KubevirtIpPool(org.onosproject.kubevirtnetworking.api.KubevirtIpPool) KubevirtNetworkingUtil.genFormatString(org.onosproject.kubevirtnetworking.util.KubevirtNetworkingUtil.genFormatString)

Example 2 with KubevirtNetworkService

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

the class KubevirtNetworkIdCompleter method complete.

@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    StringsCompleter delegate = new StringsCompleter();
    KubevirtNetworkService networkService = get(KubevirtNetworkService.class);
    Set<String> netIds = networkService.networks().stream().map(KubevirtNetwork::networkId).collect(Collectors.toSet());
    SortedSet<String> strings = delegate.getStrings();
    strings.addAll(netIds);
    return delegate.complete(session, commandLine, candidates);
}
Also used : StringsCompleter(org.apache.karaf.shell.support.completers.StringsCompleter) KubevirtNetworkService(org.onosproject.kubevirtnetworking.api.KubevirtNetworkService)

Example 3 with KubevirtNetworkService

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

the class KubevirtListNetworkCommand method doExecute.

@Override
protected void doExecute() throws Exception {
    KubevirtNetworkService service = get(KubevirtNetworkService.class);
    List<KubevirtNetwork> networks = Lists.newArrayList(service.networks());
    networks.sort(Comparator.comparing(KubevirtNetwork::name));
    String format = genFormatString(ImmutableList.of(CLI_ID_LENGTH, CLI_NAME_LENGTH, CLI_TYPE_LENGTH, CLI_SEG_ID_LENGTH, CLI_IP_ADDRESS_LENGTH));
    if (outputJson()) {
        print("%s", json(networks));
    } else {
        print(format, "ID", "Name", "Type", "SegId", "Gateway");
        for (KubevirtNetwork net : networks) {
            print(format, StringUtils.substring(net.networkId(), 0, CLI_ID_LENGTH - CLI_MARGIN_LENGTH), StringUtils.substring(net.name(), 0, CLI_NAME_LENGTH - CLI_MARGIN_LENGTH), net.type().toString(), net.segmentId() == null ? "N/A" : net.segmentId(), net.gatewayIp() == null ? "N/A" : net.gatewayIp().toString());
        }
    }
}
Also used : KubevirtNetworkService(org.onosproject.kubevirtnetworking.api.KubevirtNetworkService) KubevirtNetwork(org.onosproject.kubevirtnetworking.api.KubevirtNetwork) KubevirtNetworkingUtil.genFormatString(org.onosproject.kubevirtnetworking.util.KubevirtNetworkingUtil.genFormatString)

Aggregations

KubevirtNetworkService (org.onosproject.kubevirtnetworking.api.KubevirtNetworkService)3 KubevirtNetwork (org.onosproject.kubevirtnetworking.api.KubevirtNetwork)2 KubevirtNetworkingUtil.genFormatString (org.onosproject.kubevirtnetworking.util.KubevirtNetworkingUtil.genFormatString)2 ArrayList (java.util.ArrayList)1 StringsCompleter (org.apache.karaf.shell.support.completers.StringsCompleter)1 IpAddress (org.onlab.packet.IpAddress)1 KubevirtIpPool (org.onosproject.kubevirtnetworking.api.KubevirtIpPool)1