Search in sources :

Example 1 with KubevirtPortService

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

Aggregations

KubevirtPort (org.onosproject.kubevirtnetworking.api.KubevirtPort)1 KubevirtPortService (org.onosproject.kubevirtnetworking.api.KubevirtPortService)1 KubevirtNetworkingUtil.genFormatString (org.onosproject.kubevirtnetworking.util.KubevirtNetworkingUtil.genFormatString)1