mirror of
https://github.com/pyrohost/pyrodactyl.git
synced 2026-04-06 04:01:58 +02:00
feat: allow servers to be excluded from resource calculation
This commit is contained in:
@@ -33,6 +33,7 @@ class StoreServerRequest extends ApplicationApiRequest
|
||||
'environment' => 'present|array',
|
||||
'skip_scripts' => 'sometimes|boolean',
|
||||
'oom_disabled' => 'sometimes|boolean',
|
||||
'exclude_from_resource_calculation' => 'sometimes|boolean',
|
||||
|
||||
// Resource limitations
|
||||
'limits' => 'required|array',
|
||||
@@ -97,6 +98,7 @@ class StoreServerRequest extends ApplicationApiRequest
|
||||
'allocation_limit' => array_get($data, 'feature_limits.allocations'),
|
||||
'backup_limit' => array_get($data, 'feature_limits.backups'),
|
||||
'oom_disabled' => array_get($data, 'oom_disabled'),
|
||||
'exclude_from_resource_calculation' => array_get($data, 'exclude_from_resource_calculation', false),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -277,6 +277,10 @@ class Node extends Model
|
||||
$memoryLimit = $this->memory * (1 + ($this->memory_overallocate / 100));
|
||||
$diskLimit = $this->disk * (1 + ($this->disk_overallocate / 100));
|
||||
|
||||
return ($this->sum_memory + $memory) <= $memoryLimit && ($this->sum_disk + $disk) <= $diskLimit;
|
||||
// Calculate used resources excluding servers marked for exclusion
|
||||
$usedMemory = $this->servers()->where('exclude_from_resource_calculation', false)->sum('memory');
|
||||
$usedDisk = $this->servers()->where('exclude_from_resource_calculation', false)->sum('disk');
|
||||
|
||||
return ($usedMemory + $memory) <= $memoryLimit && ($usedDisk + $disk) <= $diskLimit;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ use Pterodactyl\Exceptions\Http\Server\ServerStateConflictException;
|
||||
* @property int $cpu
|
||||
* @property string|null $threads
|
||||
* @property bool $oom_disabled
|
||||
* @property bool $exclude_from_resource_calculation
|
||||
* @property int $allocation_id
|
||||
* @property int $nest_id
|
||||
* @property int $egg_id
|
||||
@@ -136,6 +137,7 @@ class Server extends Model
|
||||
protected $attributes = [
|
||||
'status' => self::STATUS_INSTALLING,
|
||||
'oom_disabled' => true,
|
||||
'exclude_from_resource_calculation' => false,
|
||||
'installed_at' => null,
|
||||
];
|
||||
|
||||
@@ -163,6 +165,7 @@ class Server extends Model
|
||||
'cpu' => 'required|numeric|min:0',
|
||||
'threads' => 'nullable|regex:/^[0-9-,]+$/',
|
||||
'oom_disabled' => 'sometimes|boolean',
|
||||
'exclude_from_resource_calculation' => 'sometimes|boolean',
|
||||
'disk' => 'required|numeric|min:0',
|
||||
'allocation_id' => 'required|bail|unique:servers|exists:allocations,id',
|
||||
'nest_id' => 'required|exists:nests,id',
|
||||
@@ -189,6 +192,7 @@ class Server extends Model
|
||||
'io' => 'integer',
|
||||
'cpu' => 'integer',
|
||||
'oom_disabled' => 'boolean',
|
||||
'exclude_from_resource_calculation' => 'boolean',
|
||||
'allocation_id' => 'integer',
|
||||
'nest_id' => 'integer',
|
||||
'egg_id' => 'integer',
|
||||
|
||||
@@ -117,7 +117,10 @@ class FindViableNodesService
|
||||
"$memCap - COALESCE(SUM(servers.memory), 0) AS free_memory, " .
|
||||
"$diskCap - COALESCE(SUM(servers.disk), 0) AS free_disk"
|
||||
)
|
||||
->leftJoin('servers', 'servers.node_id', '=', 'nodes.id')
|
||||
->leftJoin('servers', function ($join) {
|
||||
$join->on('servers.node_id', '=', 'nodes.id')
|
||||
->where('servers.exclude_from_resource_calculation', '=', false);
|
||||
})
|
||||
->where('nodes.public', true)
|
||||
->when(
|
||||
$this->locations !== [],
|
||||
|
||||
@@ -155,6 +155,7 @@ class ServerCreationService
|
||||
'cpu' => Arr::get($data, 'cpu'),
|
||||
'threads' => Arr::get($data, 'threads'),
|
||||
'oom_disabled' => Arr::get($data, 'oom_disabled') ?? true,
|
||||
'exclude_from_resource_calculation' => Arr::get($data, 'exclude_from_resource_calculation') ?? false,
|
||||
'allocation_id' => Arr::get($data, 'allocation_id'),
|
||||
'nest_id' => Arr::get($data, 'nest_id'),
|
||||
'egg_id' => Arr::get($data, 'egg_id'),
|
||||
|
||||
@@ -69,6 +69,7 @@ class ServerTransformer extends BaseTransformer
|
||||
'cpu' => $server->cpu,
|
||||
'threads' => $server->threads,
|
||||
'oom_disabled' => $server->oom_disabled,
|
||||
'exclude_from_resource_calculation' => $server->exclude_from_resource_calculation,
|
||||
],
|
||||
'feature_limits' => [
|
||||
'databases' => $server->database_limit,
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddExcludeFromResourceCalculationToServersTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('servers', function (Blueprint $table) {
|
||||
$table->boolean('exclude_from_resource_calculation')->default(false)->after('oom_disabled');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('servers', function (Blueprint $table) {
|
||||
$table->dropColumn('exclude_from_resource_calculation');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -230,6 +230,14 @@
|
||||
|
||||
<p class="small text-muted no-margin">Terminates the server if it breaches the memory limits. Enabling OOM killer may cause server processes to exit unexpectedly.</p>
|
||||
</div>
|
||||
<div class="form-group col-xs-12">
|
||||
<div class="checkbox checkbox-primary no-margin-bottom">
|
||||
<input type="checkbox" id="pExcludeFromResourceCalculation" name="exclude_from_resource_calculation" value="1" {{ \Pterodactyl\Helpers\Utilities::checked('exclude_from_resource_calculation', 0) }} />
|
||||
<label for="pExcludeFromResourceCalculation" class="strong">Exclude from Resource Calculation</label>
|
||||
</div>
|
||||
|
||||
<p class="small text-muted no-margin">When enabled, this server will not be included in resource calculations when provisioning new servers onto this node. Useful for testing or development servers.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user