use of org.onosproject.kubevirtnode.api.KubevirtNodeAdminService in project onos by opennetworkinglab.
the class KubevirtInitNodeCommand method doExecute.
@Override
protected void doExecute() throws Exception {
KubevirtNodeAdminService service = get(KubevirtNodeAdminService.class);
if ((!isAll && !isIncomplete && hostnames == null) || (isAll && isIncomplete) || (isIncomplete && hostnames != null) || (hostnames != null && isAll)) {
print("Please specify one of hostname, --all, and --incomplete options.");
return;
}
if (isAll) {
hostnames = service.nodes().stream().map(KubevirtNode::hostname).toArray(String[]::new);
} else if (isIncomplete) {
hostnames = service.nodes().stream().filter(node -> node.state() != COMPLETE).map(KubevirtNode::hostname).toArray(String[]::new);
}
for (String hostname : hostnames) {
KubevirtNode node = service.node(hostname);
if (node == null) {
print("Unable to find %s", hostname);
continue;
}
print("Initializing %s", hostname);
KubevirtNode updated = node.updateState(INIT);
service.updateNode(updated);
}
print("Done.");
}
use of org.onosproject.kubevirtnode.api.KubevirtNodeAdminService in project onos by opennetworkinglab.
the class KubevirtSyncStateCommand method bootstrapKubevirtNodes.
private void bootstrapKubevirtNodes(KubevirtApiConfig config) {
KubevirtNodeAdminService nodeAdminService = get(KubevirtNodeAdminService.class);
Set<KubevirtNode> completeNodeSet = nodeAdminService.completeNodes();
KubernetesClient k8sClient = k8sClient(config);
if (k8sClient == null) {
log.warn("Failed to connect to kubernetes API server");
return;
}
for (Node node : k8sClient.nodes().list().getItems()) {
KubevirtNode kubevirtNode = buildKubevirtNode(node);
// flow rules in worker nodes
if (kubevirtNode.type() == WORKER) {
if (completeNodeSet.stream().map(KubevirtNode::hostname).filter(name -> name.equals(kubevirtNode.hostname())).findAny().isPresent()) {
print("Initializing %s because the node was COMPLETE state.", kubevirtNode.hostname());
KubevirtNode updated = kubevirtNode.updateState(INIT);
nodeAdminService.updateNode(updated);
} else {
nodeAdminService.updateNode(kubevirtNode);
}
}
}
}
use of org.onosproject.kubevirtnode.api.KubevirtNodeAdminService in project onos by opennetworkinglab.
the class KubevirtNodeWebResource method createNodes.
/**
* Creates a set of KubeVirt nodes' config from the JSON input stream.
*
* @param input KubeVirt nodes JSON input stream
* @return 201 CREATED if the JSON is correct, 400 BAD_REQUEST if the JSON
* is malformed
* @onos.rsModel KubevirtNode
*/
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createNodes(InputStream input) {
log.trace(String.format(MESSAGE_NODE, CREATE));
KubevirtNodeAdminService service = get(KubevirtNodeAdminService.class);
readNodeConfiguration(input).forEach(node -> {
KubevirtNode existing = service.node(node.hostname());
if (existing == null) {
service.createNode(node);
}
});
UriBuilder locationBuilder = uriInfo.getBaseUriBuilder().path(NODES).path(NODE_ID);
return created(locationBuilder.build()).build();
}
use of org.onosproject.kubevirtnode.api.KubevirtNodeAdminService in project onos by opennetworkinglab.
the class KubevirtNodeWebResource method initAllNodes.
/**
* Initializes all KubeVirt nodes.
*
* @return 200 OK with init result, 500 server error
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("init/all")
public Response initAllNodes() {
log.trace(String.format(MESSAGE_NODE, QUERY));
KubevirtNodeAdminService service = get(KubevirtNodeAdminService.class);
service.nodes().forEach(n -> {
KubevirtNode updated = n.updateState(INIT);
service.updateNode(updated);
});
return ok(mapper().createObjectNode()).build();
}
use of org.onosproject.kubevirtnode.api.KubevirtNodeAdminService in project onos by opennetworkinglab.
the class KubevirtNodeWebResource method updateNodes.
/**
* Updates a set of KubeVirt nodes' config from the JSON input stream.
*
* @param input KubeVirt nodes JSON input stream
* @return 200 OK with the updated KubeVirt node's config, 400 BAD_REQUEST
* if the JSON is malformed, and 304 NOT_MODIFIED without the updated config
* @onos.rsModel KubevirtNode
*/
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response updateNodes(InputStream input) {
log.trace(String.format(MESSAGE_NODE, UPDATE));
KubevirtNodeAdminService service = get(KubevirtNodeAdminService.class);
Set<KubevirtNode> nodes = readNodeConfiguration(input);
for (KubevirtNode node : nodes) {
KubevirtNode existing = service.node(node.hostname());
if (existing == null) {
log.warn("There is no node configuration to update : {}", node.hostname());
return Response.notModified().build();
} else if (!existing.equals(node)) {
service.updateNode(node);
}
}
return Response.ok().build();
}
Aggregations