use of org.onosproject.k8snode.api.K8sHostService in project onos by opennetworkinglab.
the class K8sHostListCommand method doExecute.
@Override
protected void doExecute() {
K8sHostService hostService = get(K8sHostService.class);
List<K8sHost> hosts = Lists.newArrayList(hostService.hosts());
hosts.sort(Comparator.comparing(K8sHost::hostIp));
String format = genFormatString(ImmutableList.of(HOST_IP_LENGTH, TUNBRS_LENGTH, RTRBRS_LENGTH, STATUS_LENGTH));
if (outputJson()) {
print("%s", json(hosts));
} else {
print(format, "Host IP", "Tunnel Bridges", "Router Bridges", "State");
for (K8sHost host : hosts) {
print(format, host.hostIp().toString(), host.tunBridges().stream().map(K8sTunnelBridge::name).collect(Collectors.toSet()).toString(), host.routerBridges().stream().map(K8sRouterBridge::name).collect(Collectors.toSet()).toString(), host.state().toString());
}
print("Total %s hosts", hosts.size());
}
}
use of org.onosproject.k8snode.api.K8sHostService in project onos by opennetworkinglab.
the class K8sNetworkingUtil method tunnelPortNumByNetType.
/**
* Returns the tunnel port number with specified net type and kubernetes node.
*
* @param netType network type
* @param node kubernetes node
* @return tunnel port number
*/
public static PortNumber tunnelPortNumByNetType(K8sNetwork.Type netType, K8sNode node) {
if (node.mode() == PASSTHROUGH) {
K8sHostService hostService = DefaultServiceDirectory.getService(K8sHostService.class);
Port port = null;
for (K8sHost host : hostService.hosts()) {
if (host.nodeNames().contains(node.hostname())) {
for (K8sTunnelBridge bridge : host.tunBridges()) {
if (bridge.tunnelId() == node.segmentId()) {
String portName = netType.name().toLowerCase() + "-" + node.segmentId();
port = port(bridge.deviceId(), portName);
}
}
}
}
if (port == null) {
return null;
} else {
return port.number();
}
} else {
switch(netType) {
case VXLAN:
return node.vxlanPortNum();
case GRE:
return node.grePortNum();
case GENEVE:
return node.genevePortNum();
default:
return null;
}
}
}
Aggregations