add swarm server grouping

fixes for swarm
This commit is contained in:
Andras Bacsai
2023-12-19 13:47:12 +01:00
parent ef595dd4c2
commit 798acb8ee5
8 changed files with 79 additions and 23 deletions

View File

@@ -23,8 +23,9 @@ class ByIp extends Component
public int $port = 22;
public bool $is_swarm_manager = false;
public bool $is_swarm_worker = false;
public $selected_swarm_cluster = null;
public $swarm_managers = [];
protected $rules = [
'name' => 'required|string',
'description' => 'nullable|string',
@@ -48,6 +49,10 @@ class ByIp extends Component
{
$this->name = generate_random_name();
$this->private_key_id = $this->private_keys->first()->id;
$this->swarm_managers = Server::isUsable()->get()->where('settings.is_swarm_manager', true);
if ($this->swarm_managers->count() > 0) {
$this->selected_swarm_cluster = $this->swarm_managers->first()->id;
}
}
public function setPrivateKey(string $private_key_id)
@@ -57,7 +62,7 @@ class ByIp extends Component
public function instantSave()
{
$this->dispatch('success', 'Application settings updated!');
// $this->dispatch('success', 'Application settings updated!');
}
public function submit()
@@ -67,7 +72,7 @@ class ByIp extends Component
if (is_null($this->private_key_id)) {
return $this->dispatch('error', 'You must select a private key');
}
$server = Server::create([
$payload = [
'name' => $this->name,
'description' => $this->description,
'ip' => $this->ip,
@@ -79,7 +84,11 @@ class ByIp extends Component
"type" => ProxyTypes::TRAEFIK_V2->value,
"status" => ProxyStatus::EXITED->value,
],
]);
];
if ($this->is_swarm_worker) {
$payload['swarm_cluster'] = $this->selected_swarm_cluster;
}
$server = Server::create($payload);
$server->settings->is_swarm_manager = $this->is_swarm_manager;
$server->settings->is_swarm_worker = $this->is_swarm_worker;
$server->settings->save();