Search in sources :

Example 1 with CLI_NAMESPACE_LENGTH

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());
        }
    }
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) CLI_TYPES_LENGTH(org.onosproject.k8snetworking.api.Constants.CLI_TYPES_LENGTH) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Command(org.apache.karaf.shell.api.action.Command) CLI_NAME_LENGTH(org.onosproject.k8snetworking.api.Constants.CLI_NAME_LENGTH) K8sNetworkingUtil.genFormatString(org.onosproject.k8snetworking.util.K8sNetworkingUtil.genFormatString) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) CLI_NAMESPACE_LENGTH(org.onosproject.k8snetworking.api.Constants.CLI_NAMESPACE_LENGTH) List(java.util.List) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) Serialization(io.fabric8.kubernetes.client.utils.Serialization) K8sNetworkPolicyService(org.onosproject.k8snetworking.api.K8sNetworkPolicyService) K8sNetworkingUtil.prettyJson(org.onosproject.k8snetworking.util.K8sNetworkingUtil.prettyJson) Service(org.apache.karaf.shell.api.action.lifecycle.Service) NetworkPolicy(io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicy) CLI_MARGIN_LENGTH(org.onosproject.k8snetworking.api.Constants.CLI_MARGIN_LENGTH) Comparator(java.util.Comparator) NetworkPolicy(io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicy) K8sNetworkingUtil.genFormatString(org.onosproject.k8snetworking.util.K8sNetworkingUtil.genFormatString) K8sNetworkPolicyService(org.onosproject.k8snetworking.api.K8sNetworkPolicyService)

Example 2 with CLI_NAMESPACE_LENGTH

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);
        }
    }
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Pod(io.fabric8.kubernetes.api.model.Pod) CLI_CONTAINERS_LENGTH(org.onosproject.k8snetworking.api.Constants.CLI_CONTAINERS_LENGTH) IOException(java.io.IOException) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Command(org.apache.karaf.shell.api.action.Command) CLI_NAME_LENGTH(org.onosproject.k8snetworking.api.Constants.CLI_NAME_LENGTH) K8sNetworkingUtil.genFormatString(org.onosproject.k8snetworking.util.K8sNetworkingUtil.genFormatString) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) CLI_NAMESPACE_LENGTH(org.onosproject.k8snetworking.api.Constants.CLI_NAMESPACE_LENGTH) List(java.util.List) CLI_IP_ADDRESS_LENGTH(org.onosproject.k8snetworking.api.Constants.CLI_IP_ADDRESS_LENGTH) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) Serialization(io.fabric8.kubernetes.client.utils.Serialization) K8sNetworkingUtil.prettyJson(org.onosproject.k8snetworking.util.K8sNetworkingUtil.prettyJson) Service(org.apache.karaf.shell.api.action.lifecycle.Service) K8sPodService(org.onosproject.k8snetworking.api.K8sPodService) CLI_MARGIN_LENGTH(org.onosproject.k8snetworking.api.Constants.CLI_MARGIN_LENGTH) Comparator(java.util.Comparator) Pod(io.fabric8.kubernetes.api.model.Pod) K8sPodService(org.onosproject.k8snetworking.api.K8sPodService) K8sNetworkingUtil.genFormatString(org.onosproject.k8snetworking.util.K8sNetworkingUtil.genFormatString)

Example 3 with CLI_NAMESPACE_LENGTH

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);
        }
    }
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) Ingress(io.fabric8.kubernetes.api.model.extensions.Ingress) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Command(org.apache.karaf.shell.api.action.Command) CLI_NAME_LENGTH(org.onosproject.k8snetworking.api.Constants.CLI_NAME_LENGTH) K8sNetworkingUtil.genFormatString(org.onosproject.k8snetworking.util.K8sNetworkingUtil.genFormatString) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) CLI_NAMESPACE_LENGTH(org.onosproject.k8snetworking.api.Constants.CLI_NAMESPACE_LENGTH) List(java.util.List) CLI_IP_ADDRESS_LENGTH(org.onosproject.k8snetworking.api.Constants.CLI_IP_ADDRESS_LENGTH) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) K8sIngressService(org.onosproject.k8snetworking.api.K8sIngressService) Serialization(io.fabric8.kubernetes.client.utils.Serialization) K8sNetworkingUtil.prettyJson(org.onosproject.k8snetworking.util.K8sNetworkingUtil.prettyJson) Service(org.apache.karaf.shell.api.action.lifecycle.Service) CLI_MARGIN_LENGTH(org.onosproject.k8snetworking.api.Constants.CLI_MARGIN_LENGTH) Comparator(java.util.Comparator) K8sIngressService(org.onosproject.k8snetworking.api.K8sIngressService) Ingress(io.fabric8.kubernetes.api.model.extensions.Ingress) K8sNetworkingUtil.genFormatString(org.onosproject.k8snetworking.util.K8sNetworkingUtil.genFormatString)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 ImmutableList (com.google.common.collect.ImmutableList)3 Lists (com.google.common.collect.Lists)3 Serialization (io.fabric8.kubernetes.client.utils.Serialization)3 IOException (java.io.IOException)3 Comparator (java.util.Comparator)3 List (java.util.List)3 StringUtils (org.apache.commons.lang.StringUtils)3 Command (org.apache.karaf.shell.api.action.Command)3 Service (org.apache.karaf.shell.api.action.lifecycle.Service)3 AbstractShellCommand (org.onosproject.cli.AbstractShellCommand)3 CLI_MARGIN_LENGTH (org.onosproject.k8snetworking.api.Constants.CLI_MARGIN_LENGTH)3 CLI_NAMESPACE_LENGTH (org.onosproject.k8snetworking.api.Constants.CLI_NAMESPACE_LENGTH)3 CLI_NAME_LENGTH (org.onosproject.k8snetworking.api.Constants.CLI_NAME_LENGTH)3 K8sNetworkingUtil.genFormatString (org.onosproject.k8snetworking.util.K8sNetworkingUtil.genFormatString)3 K8sNetworkingUtil.prettyJson (org.onosproject.k8snetworking.util.K8sNetworkingUtil.prettyJson)3 CLI_IP_ADDRESS_LENGTH (org.onosproject.k8snetworking.api.Constants.CLI_IP_ADDRESS_LENGTH)2 Pod (io.fabric8.kubernetes.api.model.Pod)1