Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Http/Controllers/Api/Application/Nodes/NodeDeploymentController.php
10277 views
1
<?php
2
3
namespace Pterodactyl\Http\Controllers\Api\Application\Nodes;
4
5
use Pterodactyl\Services\Deployment\FindViableNodesService;
6
use Pterodactyl\Transformers\Api\Application\NodeTransformer;
7
use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
8
use Pterodactyl\Http\Requests\Api\Application\Nodes\GetDeployableNodesRequest;
9
10
class NodeDeploymentController extends ApplicationApiController
11
{
12
/**
13
* NodeDeploymentController constructor.
14
*/
15
public function __construct(private FindViableNodesService $viableNodesService)
16
{
17
parent::__construct();
18
}
19
20
/**
21
* Finds any nodes that are available using the given deployment criteria. This works
22
* similarly to the server creation process, but allows you to pass the deployment object
23
* to this endpoint and get back a list of all Nodes satisfying the requirements.
24
*
25
* @throws \Pterodactyl\Exceptions\Service\Deployment\NoViableNodeException
26
*/
27
public function __invoke(GetDeployableNodesRequest $request): array
28
{
29
$data = $request->validated();
30
$nodes = $this->viableNodesService->setLocations($data['location_ids'] ?? [])
31
->setMemory($data['memory'])
32
->setDisk($data['disk'])
33
->handle($request->query('per_page'), $request->query('page'));
34
35
return $this->fractal->collection($nodes)
36
->transformWith($this->getTransformer(NodeTransformer::class))
37
->toArray();
38
}
39
}
40
41