private static AllocatableResources calculateAllocatableResources(ClusterResources wantedResources,
                                                                      NodeRepository nodeRepository,
                                                                      CloudAccount cloudAccount,
                                                                      ClusterSpec clusterSpec,
                                                                      Limits applicationLimits,
                                                                      boolean exclusive,
                                                                      boolean bestCase) {
        var systemLimits = nodeRepository.nodeResourceLimits();
        var advertisedResources = nodeRepository.resourcesCalculator().realToRequest(wantedResources.nodeResources(), cloudAccount, exclusive, bestCase);
        advertisedResources = systemLimits.enlargeToLegal(advertisedResources, clusterSpec, exclusive, true); // Ask for something legal
        advertisedResources = applicationLimits.cap(advertisedResources); // Overrides other conditions, even if it will then fail
        var realResources = nodeRepository.resourcesCalculator().requestToReal(advertisedResources, cloudAccount, exclusive, bestCase); // What we'll really get
        if ( ! systemLimits.isWithinRealLimits(realResources, clusterSpec)
             && advertisedResources.storageType() == NodeResources.StorageType.any) {
            // Since local disk reserves some of the storage, try to constrain to remote disk
            advertisedResources = advertisedResources.with(NodeResources.StorageType.remote);
            realResources = nodeRepository.resourcesCalculator().requestToReal(advertisedResources, cloudAccount, exclusive, bestCase);
        }
        return new AllocatableResources(wantedResources.with(realResources),
                                        advertisedResources,
                                        wantedResources,
                                        clusterSpec);
    }
The estimated cost of changing from the given current resources to this.
node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/AllocatableResources.java