Add load balancer (#453)

This commit is contained in:
Saeed Vaziry
2025-01-30 23:52:51 +01:00
committed by GitHub
parent 53e20cbc2a
commit 6966f06b1a
54 changed files with 3128 additions and 1833 deletions

View File

@ -0,0 +1,44 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* @property int $load_balancer_id
* @property string $ip
* @property int $port
* @property int $weight
* @property bool $backup
* @property Site $loadBalancer
*/
class LoadBalancerServer extends AbstractModel
{
use HasFactory;
protected $fillable = [
'load_balancer_id',
'ip',
'port',
'weight',
'backup',
];
protected $casts = [
'load_balancer_id' => 'integer',
'port' => 'integer',
'weight' => 'integer',
'backup' => 'boolean',
];
public function loadBalancer(): BelongsTo
{
return $this->belongsTo(Site::class, 'load_balancer_id');
}
public function server(): ?Server
{
return $this->loadBalancer->project->servers()->where('local_ip', $this->ip)->first();
}
}

View File

@ -16,6 +16,7 @@
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
/**
@ -47,6 +48,7 @@
* @property ?Ssl $activeSsl
* @property string $ssh_key_name
* @property ?SourceControl $sourceControl
* @property Collection<LoadBalancerServer> $loadBalancerServers
*
* @TODO: Add nodejs_version column
*/
@ -332,4 +334,9 @@ public function webserver(): Webserver
return $webserver;
}
public function loadBalancerServers(): HasMany
{
return $this->hasMany(LoadBalancerServer::class, 'load_balancer_id');
}
}