Search in sources :

Example 1 with K8sHostService

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());
    }
}
Also used : K8sHost(org.onosproject.k8snode.api.K8sHost) K8sHostService(org.onosproject.k8snode.api.K8sHostService) K8sNodeUtil.genFormatString(org.onosproject.k8snode.util.K8sNodeUtil.genFormatString)

Example 2 with K8sHostService

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;
        }
    }
}
Also used : Port(org.onosproject.net.Port) DefaultK8sPort(org.onosproject.k8snetworking.api.DefaultK8sPort) K8sPort(org.onosproject.k8snetworking.api.K8sPort) TpPort(org.onlab.packet.TpPort) ContainerPort(io.fabric8.kubernetes.api.model.ContainerPort) K8sHost(org.onosproject.k8snode.api.K8sHost) K8sHostService(org.onosproject.k8snode.api.K8sHostService) K8sTunnelBridge(org.onosproject.k8snode.api.K8sTunnelBridge)

Aggregations

K8sHost (org.onosproject.k8snode.api.K8sHost)2 K8sHostService (org.onosproject.k8snode.api.K8sHostService)2 ContainerPort (io.fabric8.kubernetes.api.model.ContainerPort)1 TpPort (org.onlab.packet.TpPort)1 DefaultK8sPort (org.onosproject.k8snetworking.api.DefaultK8sPort)1 K8sPort (org.onosproject.k8snetworking.api.K8sPort)1 K8sTunnelBridge (org.onosproject.k8snode.api.K8sTunnelBridge)1 K8sNodeUtil.genFormatString (org.onosproject.k8snode.util.K8sNodeUtil.genFormatString)1 Port (org.onosproject.net.Port)1