mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 14:36:17 +00:00
Add load balancer (#453)
This commit is contained in:
44
app/Models/LoadBalancerServer.php
Normal file
44
app/Models/LoadBalancerServer.php
Normal 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();
|
||||
}
|
||||
}
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user