use of org.onosproject.k8snode.api.K8sHost 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;
}
}
}
use of org.onosproject.k8snode.api.K8sHost in project onos by opennetworkinglab.
the class K8sNetworkingUtil method allK8sDevices.
/**
* Returns all device identifiers belong to kubernetes nodes and hosts.
*
* @param nodeService node service
* @param hostService host service
* @return all device identifiers belong to kubernetes nodes and hosts
*/
public static Set<DeviceId> allK8sDevices(K8sNodeService nodeService, K8sHostService hostService) {
Set<DeviceId> allDevIds = new HashSet<>();
Set<DeviceId> intgDevIds = nodeService.completeNodes().stream().map(K8sNode::intgBridge).collect(Collectors.toSet());
Set<DeviceId> extDevIds = nodeService.completeNodes().stream().map(K8sNode::extBridge).collect(Collectors.toSet());
Set<DeviceId> tunDevIds = nodeService.completeNodes().stream().map(K8sNode::tunBridge).collect(Collectors.toSet());
Set<DeviceId> localDevIds = nodeService.completeNodes().stream().map(K8sNode::localBridge).collect(Collectors.toSet());
Set<DeviceId> hostTunDevIds = new HashSet<>();
Set<DeviceId> hostRouterDevIds = new HashSet<>();
for (K8sHost host : hostService.completeHosts()) {
Set<K8sTunnelBridge> hostTunBrs = host.tunBridges();
Set<K8sRouterBridge> hostRouterBrs = host.routerBridges();
hostTunDevIds.addAll(hostTunBrs.stream().map(K8sTunnelBridge::deviceId).collect(Collectors.toSet()));
hostRouterDevIds.addAll(hostRouterBrs.stream().map(K8sRouterBridge::deviceId).collect(Collectors.toSet()));
}
allDevIds.addAll(intgDevIds);
allDevIds.addAll(extDevIds);
allDevIds.addAll(tunDevIds);
allDevIds.addAll(localDevIds);
allDevIds.addAll(hostTunDevIds);
allDevIds.addAll(hostRouterDevIds);
return allDevIds;
}
use of org.onosproject.k8snode.api.K8sHost in project onos by opennetworkinglab.
the class K8sNodeWebResource method removeNodesFromHost.
/**
* Remove a set of new nodes from the existing host.
*
* @param hostIp host IP address
* @param input kubernetes node names JSON input stream
* @return 200 UPDATED if the JSON is correct, 400 BAD_REQUEST if the JSON
* is malformed
* @onos.rsModel K8sNodeNames
*/
@PUT
@Path("host/delete/nodes/{hostIp}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response removeNodesFromHost(@PathParam("hostIp") String hostIp, InputStream input) {
log.trace(String.format(MESSAGE_HOST, UPDATE));
Set<String> newNodeNames = readNodeNamesConfiguration(input);
K8sHost host = hostAdminService.host(IpAddress.valueOf(hostIp));
Set<String> existNodeNames = host.nodeNames();
existNodeNames.removeAll(newNodeNames);
K8sHost updated = host.updateNodeNames(existNodeNames);
hostAdminService.updateHost(updated);
return Response.ok().build();
}
use of org.onosproject.k8snode.api.K8sHost in project onos by opennetworkinglab.
the class K8sNodeWebResource method createHosts.
/**
* Creates a set of kubernetes hosts' config from the JSON input stream.
*
* @param input kubernetes hosts JSON input stream
* @return 201 CREATED if the JSON is correct, 400 BAD_REQUEST if the JSON
* is malformed
* @onos.rsModel K8sHosts
*/
@POST
@Path("host")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createHosts(InputStream input) {
log.trace(String.format(MESSAGE_NODE, CREATE));
readHostsConfiguration(input).forEach(host -> {
K8sHost existing = hostAdminService.host(host.hostIp());
if (existing == null) {
hostAdminService.createHost(host);
}
});
UriBuilder locationBuilder = uriInfo.getBaseUriBuilder().path(HOSTS).path(HOST_IP);
return created(locationBuilder.build()).build();
}
use of org.onosproject.k8snode.api.K8sHost in project onos by opennetworkinglab.
the class K8sNodeWebResource method deleteHost.
/**
* Removes a kubernetes host' config.
*
* @param hostIp host IP contained in kubernetes nodes configuration
* @return 204 NO_CONTENT, 400 BAD_REQUEST if the JSON is malformed, and
* 304 NOT_MODIFIED without the updated config
*/
@DELETE
@Path("host/{hostIp}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response deleteHost(@PathParam("hostIp") String hostIp) {
log.trace(String.format(MESSAGE_HOST, REMOVE));
K8sHost existing = hostAdminService.host(IpAddress.valueOf(nullIsIllegal(hostIp, HOST_IP + ERROR_MESSAGE)));
if (existing == null) {
log.warn("There is no host configuration to delete : {}", hostIp);
return Response.notModified().build();
} else {
hostAdminService.removeHost(IpAddress.valueOf(nullIsIllegal(hostIp, HOST_IP + ERROR_MESSAGE)));
}
return Response.noContent().build();
}
Aggregations