[ [ 'code' => 'NoViableNodeException', 'status' => '400', 'detail' => 'No nodes satisfying the requirements specified for automatic deployment could be found.', ], ], ]; /** * Finds any nodes that are available using the given deployment criteria. This works * similarly to the server creation process, but allows you to pass the deployment object * to this endpoint and get back a list of all Nodes satisfying the requirements. * * @throws NoViableNodeException */ #[Endpoint('List deployable nodes', 'Returns nodes that can satisfy the requested memory, disk, and optional location deployment constraints.')] #[QueryParam('memory', 'integer', 'Memory required for the deployment, in megabytes.', required: true, example: 1024)] #[QueryParam('disk', 'integer', 'Disk required for the deployment, in megabytes.', required: true, example: 10240)] #[QueryParam('location_ids', 'integer[]', 'Restrict results to these location IDs.', required: false, example: [1, 2])] #[QueryParam('page', 'integer', 'Page number to return. When omitted, all viable nodes are returned without pagination metadata.', required: false, example: 1)] #[QueryParam('per_page', 'integer', 'Number of nodes to return per page when page is supplied, up to 100.', required: false, example: 50)] #[ResponseFromResource(NodeResource::class, Node::class, description: 'Deployable nodes returned.', collection: true, factoryStates: ['withLocation'], resourceKey: 'node')] #[ScribeResponse(self::NO_VIABLE_NODE_ERROR, status: 400, description: 'No nodes can satisfy the requested deployment constraints.')] public function __invoke(GetDeployableNodesRequest $request): ApiResourceCollection { $payload = $request->payload(); // No deploy tags are given here, so nodes reserved for any tag are left out. $query = Node::query() ->viableFor($payload['memory'], $payload['disk']) ->inLocations($payload['location_ids']) ->forDeployTags([]); $nodes = $payload['page'] === null ? $query->get() : $query->paginate($payload['per_page'] ?? 50, ['*'], 'page', $payload['page']); throw_if($nodes->isEmpty(), NoViableNodeException::class, trans('exceptions.deployment.no_viable_nodes')); return NodeResource::collection($nodes); } }