mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-29 01:34:45 +02:00

* Not found property rule * Make these “better” * Day 1 * Day 2 * Day 3 * Dat 4 * Remove disabled check * Day 4 continued * Run pint * Final changes hopefully * Pint fixes * Fix again * Reset these * Update app/Filament/Admin/Pages/Health.php Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com> * Update app/Traits/CheckMigrationsTrait.php Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com> --------- Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com>
36 lines
1.2 KiB
PHP
36 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Deployment;
|
|
|
|
use App\Models\Node;
|
|
use Illuminate\Support\Collection;
|
|
|
|
class FindViableNodesService
|
|
{
|
|
/**
|
|
* Returns a collection of nodes that meet the provided requirements and can then
|
|
* be passed to the AllocationSelectionService to return a single allocation.
|
|
*
|
|
* This functionality is used for automatic deployments of servers and will
|
|
* attempt to find all nodes in the defined locations that meet the memory, disk
|
|
* and cpu availability requirements. Any nodes not meeting those requirements
|
|
* are tossed out, as are any nodes marked as non-public, meaning automatic
|
|
* deployments should not be done against them.
|
|
*
|
|
* @param string[] $tags
|
|
*/
|
|
public function handle(int $memory = 0, int $disk = 0, int $cpu = 0, array $tags = []): Collection
|
|
{
|
|
$nodes = Node::query()
|
|
->withSum('servers', 'memory')
|
|
->withSum('servers', 'disk')
|
|
->withSum('servers', 'cpu')
|
|
->where('public', true)
|
|
->get();
|
|
|
|
return $nodes
|
|
->filter(fn (Node $node) => !$tags || collect($node->tags)->intersect($tags))
|
|
->filter(fn (Node $node) => $node->isViable($memory, $disk, $cpu));
|
|
}
|
|
}
|