2021-01-10 21:08:43 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Controllers\Api\Application\Nodes;
|
|
|
|
|
|
|
|
use Pterodactyl\Services\Deployment\FindViableNodesService;
|
|
|
|
use Pterodactyl\Transformers\Api\Application\NodeTransformer;
|
|
|
|
use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
|
|
|
|
use Pterodactyl\Http\Requests\Api\Application\Nodes\GetDeployableNodesRequest;
|
|
|
|
|
|
|
|
class NodeDeploymentController extends ApplicationApiController
|
|
|
|
{
|
2021-03-05 17:03:12 +00:00
|
|
|
private FindViableNodesService $viableNodesService;
|
2021-01-10 21:08:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* NodeDeploymentController constructor.
|
|
|
|
*/
|
|
|
|
public function __construct(FindViableNodesService $viableNodesService)
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->viableNodesService = $viableNodesService;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
2021-03-05 17:03:12 +00:00
|
|
|
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
2021-01-10 21:08:43 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Service\Deployment\NoViableNodeException
|
|
|
|
*/
|
|
|
|
public function __invoke(GetDeployableNodesRequest $request): array
|
|
|
|
{
|
|
|
|
$data = $request->validated();
|
|
|
|
$nodes = $this->viableNodesService->setLocations($data['location_ids'] ?? [])
|
|
|
|
->setMemory($data['memory'])
|
|
|
|
->setDisk($data['disk'])
|
2021-03-26 16:03:51 +00:00
|
|
|
->handle($request->query('per_page'), $request->query('page'));
|
2021-01-10 21:08:43 +00:00
|
|
|
|
|
|
|
return $this->fractal->collection($nodes)
|
|
|
|
->transformWith($this->getTransformer(NodeTransformer::class))
|
|
|
|
->toArray();
|
|
|
|
}
|
|
|
|
}
|