use of org.onosproject.k8snetworking.api.Constants.CLI_NAME_LENGTH in project onos by opennetworkinglab.
the class K8sNamespaceListCommand method doExecute.
@Override
protected void doExecute() {
K8sNamespaceService service = get(K8sNamespaceService.class);
List<Namespace> namespaces = Lists.newArrayList(service.namespaces());
namespaces.sort(Comparator.comparing(n -> n.getMetadata().getName()));
String format = genFormatString(ImmutableList.of(CLI_NAME_LENGTH, CLI_PHASE_LENGTH, CLI_LABELS_LENGTH));
if (outputJson()) {
print("%s", json(namespaces));
} else {
print(format, "Name", "Phase", "Labels");
for (Namespace namespace : namespaces) {
print(format, StringUtils.substring(namespace.getMetadata().getName(), 0, CLI_NAME_LENGTH - CLI_MARGIN_LENGTH), namespace.getStatus().getPhase(), namespace.getMetadata() != null && namespace.getMetadata().getLabels() != null && !namespace.getMetadata().getLabels().isEmpty() ? StringUtils.substring(namespace.getMetadata().getLabels().toString(), 0, CLI_LABELS_LENGTH - CLI_MARGIN_LENGTH) : "");
}
}
}
use of org.onosproject.k8snetworking.api.Constants.CLI_NAME_LENGTH in project onos by opennetworkinglab.
the class K8sNetworkPolicyListCommand method doExecute.
@Override
protected void doExecute() {
K8sNetworkPolicyService service = get(K8sNetworkPolicyService.class);
List<NetworkPolicy> policies = Lists.newArrayList(service.networkPolicies());
policies.sort(Comparator.comparing(p -> p.getMetadata().getName()));
String format = genFormatString(ImmutableList.of(CLI_NAME_LENGTH, CLI_NAMESPACE_LENGTH, CLI_TYPES_LENGTH));
if (outputJson()) {
print("%s", json(policies));
} else {
print(format, "Name", "Namespace", "Types");
for (NetworkPolicy policy : policies) {
print(format, StringUtils.substring(policy.getMetadata().getName(), 0, CLI_NAME_LENGTH - CLI_MARGIN_LENGTH), StringUtils.substring(policy.getMetadata().getNamespace(), 0, CLI_NAMESPACE_LENGTH - CLI_MARGIN_LENGTH), policy.getSpec().getPolicyTypes().isEmpty() ? "" : policy.getSpec().getPolicyTypes());
}
}
}
use of org.onosproject.k8snetworking.api.Constants.CLI_NAME_LENGTH in project onos by opennetworkinglab.
the class K8sPodListCommand method doExecute.
@Override
protected void doExecute() {
K8sPodService service = get(K8sPodService.class);
List<Pod> pods = Lists.newArrayList(service.pods());
pods.sort(Comparator.comparing(p -> p.getMetadata().getName()));
String format = genFormatString(ImmutableList.of(CLI_NAME_LENGTH, CLI_NAMESPACE_LENGTH, CLI_IP_ADDRESS_LENGTH, CLI_CONTAINERS_LENGTH));
if (outputJson()) {
print("%s", json(pods));
} else {
print(format, "Name", "Namespace", "IP Address", "Containers");
for (Pod pod : pods) {
List<String> containers = Lists.newArrayList();
pod.getSpec().getContainers().forEach(c -> containers.add(c.getName()));
print(format, StringUtils.substring(pod.getMetadata().getName(), 0, CLI_NAME_LENGTH - CLI_MARGIN_LENGTH), StringUtils.substring(pod.getMetadata().getNamespace(), 0, CLI_NAMESPACE_LENGTH - CLI_MARGIN_LENGTH), StringUtils.substring(pod.getStatus().getPodIP(), 0, CLI_IP_ADDRESS_LENGTH - CLI_MARGIN_LENGTH), containers.isEmpty() ? "" : containers);
}
}
}
use of org.onosproject.k8snetworking.api.Constants.CLI_NAME_LENGTH 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);
}
}
}
use of org.onosproject.k8snetworking.api.Constants.CLI_NAME_LENGTH in project onos by opennetworkinglab.
the class K8sEndpointsListCommand method doExecute.
@Override
protected void doExecute() {
K8sEndpointsService service = get(K8sEndpointsService.class);
List<Endpoints> endpointses = Lists.newArrayList(service.endpointses());
endpointses.sort(Comparator.comparing(e -> e.getMetadata().getName()));
String format = genFormatString(ImmutableList.of(CLI_NAME_LENGTH, CLI_IP_ADDRESSES_LENGTH, CLI_PORTS_LENGTH));
if (outputJson()) {
print("%s", json(endpointses));
} else {
print(format, "Name", "IP Addresses", "Ports");
for (Endpoints endpoints : endpointses) {
List<String> ips = Lists.newArrayList();
List<String> portWithProtocol = Lists.newArrayList();
endpoints.getSubsets().forEach(e -> {
e.getAddresses().forEach(a -> ips.add(a.getIp()));
e.getPorts().forEach(p -> portWithProtocol.add(p.getPort() + PORT_PROTOCOL_SEPARATOR + p.getProtocol()));
});
print(format, StringUtils.substring(endpoints.getMetadata().getName(), 0, CLI_NAME_LENGTH - CLI_MARGIN_LENGTH), ips.isEmpty() ? "" : StringUtils.substring(ips.toString(), 0, CLI_IP_ADDRESSES_LENGTH - CLI_MARGIN_LENGTH), portWithProtocol.isEmpty() ? "" : portWithProtocol);
}
}
}
Aggregations