use of org.onosproject.k8snetworking.api.K8sNetworkPolicyService 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());
}
}
}
Aggregations