public boolean markNodeAvailableForNewAllocation(String hostname, Agent agent, String reason) {
        try (NodeMutex nodeMutex = lockAndGetRequired(hostname)) {
            Node node = nodeMutex.node();
            if (node.type() == NodeType.tenant) {
                if (node.state() != Node.State.dirty)
                    illegal("Cannot make " + node + " available for new allocation as it is not in state [dirty]");

                NestedTransaction transaction = new NestedTransaction();
                db.removeNodes(List.of(node), transaction);
                transaction.commit();
                return false;
            }

            if (node.state() == Node.State.ready) return false;

            Node parentHost = node.parentHostname().flatMap(this::node).orElse(node);
            List<String> failureReasons = NodeFailer.reasonsToFailHost(parentHost);
            if (!failureReasons.isEmpty())
                illegal(node + " cannot be readied because it has hard failures: " + failureReasons);

            setReady(nodeMutex, agent, reason);
            return true;
        }
    }
This method is used by the REST API to handle readying nodes for new allocations.
Tenant containers will be removed, while other nodes will be moved to the ready state.
Returns true if a node was updated, or false if the node was removed, or already was ready.
node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/Nodes.java