use of org.onosproject.kubevirtnetworking.api.KubevirtPortService in project onos by opennetworkinglab.
the class KubevirtListPortCommand method doExecute.
@Override
protected void doExecute() throws Exception {
KubevirtPortService service = get(KubevirtPortService.class);
List<KubevirtPort> ports = Lists.newArrayList(service.ports());
ports.sort(Comparator.comparing(KubevirtPort::networkId));
String format = genFormatString(ImmutableList.of(CLI_NAME_LENGTH, CLI_NAME_LENGTH, CLI_MAC_ADDRESS_LENGTH, CLI_IP_ADDRESSES_LENGTH));
if (!Strings.isNullOrEmpty(networkId)) {
ports.removeIf(port -> !port.networkId().equals(networkId));
}
if (outputJson()) {
print("%s", json(ports));
} else {
print(format, "VM Name", "Network", "MAC Address", "Fixed IPs");
for (KubevirtPort port : ports) {
print(format, StringUtils.substring(port.vmName(), 0, CLI_NAME_LENGTH - CLI_MARGIN_LENGTH), StringUtils.substring(port.networkId(), 0, CLI_NAME_LENGTH - CLI_MARGIN_LENGTH), StringUtils.substring(port.macAddress().toString(), 0, CLI_MAC_ADDRESS_LENGTH - CLI_MARGIN_LENGTH), port.ipAddress() == null ? "" : port.ipAddress());
}
}
}
Aggregations