use of org.onosproject.k8snetworking.api.K8sServiceService in project onos by opennetworkinglab.
the class K8sServiceListCommand method doExecute.
@Override
protected void doExecute() {
K8sServiceService service = get(K8sServiceService.class);
List<io.fabric8.kubernetes.api.model.Service> services = Lists.newArrayList(service.services());
services.sort(Comparator.comparing(s -> s.getMetadata().getName()));
String format = genFormatString(ImmutableList.of(CLI_NAME_LENGTH, CLI_IP_ADDRESS_LENGTH, CLI_PORTS_LENGTH));
if (outputJson()) {
print("%s", json(services));
} else {
print(format, "Name", "Cluster IP", "Ports");
for (io.fabric8.kubernetes.api.model.Service svc : services) {
List<String> portWithProtocol = Lists.newArrayList();
svc.getSpec().getPorts().forEach(p -> portWithProtocol.add(p.getPort() + PORT_PROTOCOL_SEPARATOR + p.getProtocol()));
print(format, StringUtils.substring(svc.getMetadata().getName(), 0, CLI_NAME_LENGTH - CLI_MARGIN_LENGTH), StringUtils.substring(svc.getSpec().getClusterIP(), 0, CLI_IP_ADDRESS_LENGTH - CLI_MARGIN_LENGTH), portWithProtocol.isEmpty() ? "" : portWithProtocol);
}
}
}
Aggregations