mirror of
https://github.com/pelican-dev/panel.git
synced 2025-06-23 00:31:07 +02:00
Revert this
This commit is contained in:
parent
a97341f6f2
commit
459d90e8d1
@ -2,8 +2,10 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Casts\EndpointCollection;
|
||||
use App\Enums\ServerState;
|
||||
use App\Exceptions\Http\Connection\DaemonConnectionException;
|
||||
use App\Models\Objects\Endpoint;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
@ -128,11 +130,6 @@ class Server extends Model
|
||||
'installed_at' => null,
|
||||
];
|
||||
|
||||
/**
|
||||
* The default relationships to load for all server models.
|
||||
*/
|
||||
protected $with = ['allocation'];
|
||||
|
||||
/**
|
||||
* Fields that are not mass assignable.
|
||||
*/
|
||||
@ -152,7 +149,6 @@ class Server extends Model
|
||||
'threads' => 'nullable|regex:/^[0-9-,]+$/',
|
||||
'oom_killer' => 'sometimes|boolean',
|
||||
'disk' => 'required|numeric|min:0',
|
||||
'allocation_id' => 'required|bail|unique:servers|exists:allocations,id',
|
||||
'egg_id' => 'required|exists:eggs,id',
|
||||
'startup' => 'required|string',
|
||||
'skip_scripts' => 'sometimes|boolean',
|
||||
@ -175,27 +171,33 @@ class Server extends Model
|
||||
'io' => 'integer',
|
||||
'cpu' => 'integer',
|
||||
'oom_killer' => 'boolean',
|
||||
'allocation_id' => 'integer',
|
||||
'egg_id' => 'integer',
|
||||
'database_limit' => 'integer',
|
||||
'allocation_limit' => 'integer',
|
||||
'backup_limit' => 'integer',
|
||||
self::CREATED_AT => 'datetime',
|
||||
self::UPDATED_AT => 'datetime',
|
||||
'deleted_at' => 'datetime',
|
||||
'installed_at' => 'datetime',
|
||||
'docker_labels' => 'array',
|
||||
'ports' => EndpointCollection::class,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the format for server allocations when communicating with the Daemon.
|
||||
*/
|
||||
public function getAllocationMappings(): array
|
||||
public function getPortMappings(): array
|
||||
{
|
||||
return $this->allocations->where('node_id', $this->node_id)->groupBy('ip')->map(function ($item) {
|
||||
return $item->pluck('port');
|
||||
})->toArray();
|
||||
$defaultIp = '0.0.0.0';
|
||||
|
||||
$ports = collect($this->ports)
|
||||
->map(fn ($port) => str_contains($port, ':') ? $port : "$defaultIp:$port")
|
||||
->mapToGroups(function ($port) {
|
||||
[$ip, $port] = explode(':', $port);
|
||||
|
||||
return [$ip => (int) $port];
|
||||
});
|
||||
|
||||
return $ports->all();
|
||||
}
|
||||
|
||||
public function isInstalled(): bool
|
||||
@ -394,4 +396,17 @@ class Server extends Model
|
||||
|
||||
return cache()->get("servers.$this->uuid.container.status") ?? 'missing';
|
||||
}
|
||||
|
||||
public function getPrimaryEndpoint(): ?Endpoint
|
||||
{
|
||||
$endpoint = $this->ports->first();
|
||||
|
||||
$portEggVariable = $this->variables->firstWhere('env_variable', 'SERVER_PORT');
|
||||
if ($portEggVariable) {
|
||||
$portServerVariable = $this->serverVariables->firstWhere('variable_id', $portEggVariable->id);
|
||||
$endpoint = new Endpoint($portServerVariable->variable_value);
|
||||
}
|
||||
|
||||
return $endpoint;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user