use of org.onosproject.k8snetworking.api.K8sIpamService in project onos by opennetworkinglab.
the class K8sIpAddressListCommand method doExecute.
@Override
protected void doExecute() {
K8sIpamService ipamService = get(K8sIpamService.class);
K8sNetworkService networkService = get(K8sNetworkService.class);
if (networkIds == null || networkIds.length == 0) {
networkIds = networkService.networks().stream().map(K8sNetwork::networkId).toArray(String[]::new);
}
Map<String, Map<IpAddress, MacAddress>> ipMacs = Maps.newConcurrentMap();
if (available && reserved) {
error("Only one of list options (available | reserved) can be specified.");
return;
}
if (!(available || reserved)) {
error("At least one of list options (available | reserved) should be specified.");
return;
}
for (String networkId : networkIds) {
Map<IpAddress, MacAddress> tmpIpMacs = Maps.newConcurrentMap();
if (available) {
ipamService.availableIps(networkId).forEach(n -> tmpIpMacs.put(n, ZERO));
}
if (reserved) {
Set<K8sPort> ports = networkService.ports(networkId);
ipamService.allocatedIps(networkId).forEach(ip -> {
MacAddress mac = ports.stream().filter(p -> p.ipAddress().equals(ip)).map(K8sPort::macAddress).findAny().orElse(ZERO);
tmpIpMacs.put(ip, mac);
});
}
ipMacs.put(networkId, tmpIpMacs);
}
if (ipMacs.size() > 0) {
print(FORMAT, "Network ID", "IP Address", "MAC Address");
ipMacs.forEach((k, v) -> v.forEach((ip, mac) -> print(FORMAT, k, ip, mac)));
} else {
print("No IP addresses are available or reserved.");
}
}
Aggregations