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