use of org.onosproject.k8snetworking.api.Constants.CLI_NAMESPACE_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_NAMESPACE_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_NAMESPACE_LENGTH in project onos by opennetworkinglab.
the class K8sIngressListCommand method doExecute.
@Override
protected void doExecute() {
K8sIngressService service = get(K8sIngressService.class);
List<Ingress> ingresses = Lists.newArrayList(service.ingresses());
ingresses.sort(Comparator.comparing(p -> p.getMetadata().getName()));
String format = genFormatString(ImmutableList.of(CLI_NAME_LENGTH, CLI_NAMESPACE_LENGTH, CLI_IP_ADDRESS_LENGTH));
if (outputJson()) {
print("%s", json(ingresses));
} else {
print(format, "Name", "Namespace", "LB Addresses");
for (Ingress ingress : ingresses) {
List<String> lbIps = Lists.newArrayList();
ingress.getStatus().getLoadBalancer().getIngress().forEach(i -> lbIps.add(i.getIp()));
print(format, StringUtils.substring(ingress.getMetadata().getName(), 0, CLI_NAME_LENGTH - CLI_MARGIN_LENGTH), StringUtils.substring(ingress.getMetadata().getNamespace(), 0, CLI_NAMESPACE_LENGTH - CLI_MARGIN_LENGTH), lbIps.isEmpty() ? "" : lbIps);
}
}
}
Aggregations