Cluster settings update

This commit is contained in:
Eduardo Silva
2025-12-29 18:13:07 -03:00
parent 002bf11d63
commit c2f7c2e36d
4 changed files with 59 additions and 33 deletions

View File

@@ -10,7 +10,7 @@ from .models import ClusterSettings, Worker
class WorkerForm(forms.ModelForm): class WorkerForm(forms.ModelForm):
class Meta: class Meta:
model = Worker model = Worker
fields = ['name', 'enabled', 'ip_lock', 'ip_address', 'country', 'city', 'hostname'] fields = ['name', 'enabled', 'ip_lock', 'ip_address', 'country', 'city', 'hostname', 'token']
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
@@ -21,6 +21,7 @@ class WorkerForm(forms.ModelForm):
self.fields['country'].label = _("Country") self.fields['country'].label = _("Country")
self.fields['city'].label = _("City") self.fields['city'].label = _("City")
self.fields['hostname'].label = _("Hostname") self.fields['hostname'].label = _("Hostname")
self.fields['token'].label = _("Token")
back_label = _("Back") back_label = _("Back")
delete_label = _("Delete") delete_label = _("Delete")
@@ -35,18 +36,29 @@ class WorkerForm(forms.ModelForm):
self.helper.layout = Layout( self.helper.layout = Layout(
Row( Row(
Column('name', css_class='form-group col-md-6 mb-0'), Column('name', css_class='form-group col-md-6 mb-0'),
Column('enabled', css_class='form-group col-md-6 mb-0'), Column('hostname', css_class='form-group col-md-6 mb-0'),
css_class='form-row' css_class='form-row'
), ),
Row( Row(
Column('ip_lock', css_class='form-group col-md-6 mb-0'), Column('country', css_class='form-group col-md-6 mb-0'),
Column('city', css_class='form-group col-md-6 mb-0'),
),
Row(
Column('token', css_class='form-group col-md-12 mb-0'),
css_class='form-row'
),
Row(
Column(css_class='form-group col-md-6 mb-0'),
Column('ip_address', css_class='form-group col-md-6 mb-0'), Column('ip_address', css_class='form-group col-md-6 mb-0'),
css_class='form-row' css_class='form-row'
), ),
Row( Row(
Column('country', css_class='form-group col-md-4 mb-0'),
Column('city', css_class='form-group col-md-4 mb-0'), Column('enabled', css_class='form-group col-md-6 mb-0'),
Column('hostname', css_class='form-group col-md-4 mb-0'), Column('ip_lock', css_class='form-group col-md-6 mb-0'),
css_class='form-row' css_class='form-row'
), ),
Row( Row(
@@ -67,7 +79,7 @@ class WorkerForm(forms.ModelForm):
if Worker.objects.filter(name=name).exclude(pk=self.instance.pk if self.instance else None).exists(): if Worker.objects.filter(name=name).exclude(pk=self.instance.pk if self.instance else None).exists():
raise ValidationError(_("A worker with that name already exists.")) raise ValidationError(_("A worker with that name already exists."))
if ip_lock and not ip_address: if ip_lock and not ip_address:
raise ValidationError(_("IP Address is required when IP Lock is enabled.")) raise ValidationError(_("IP Address is required when IP Lock is enabled."))
@@ -78,7 +90,7 @@ class ClusterSettingsForm(forms.ModelForm):
class Meta: class Meta:
model = ClusterSettings model = ClusterSettings
fields = [ fields = [
'enabled', 'primary_enable_wireguard', 'stats_sync_interval', 'enabled', 'primary_enable_wireguard', 'stats_sync_interval',
'stats_cache_interval', 'cluster_mode', 'restart_mode', 'worker_display' 'stats_cache_interval', 'cluster_mode', 'restart_mode', 'worker_display'
] ]
@@ -91,11 +103,11 @@ class ClusterSettingsForm(forms.ModelForm):
self.fields['cluster_mode'].label = _("Cluster Mode") self.fields['cluster_mode'].label = _("Cluster Mode")
self.fields['restart_mode'].label = _("Restart Mode") self.fields['restart_mode'].label = _("Restart Mode")
self.fields['worker_display'].label = _("Worker Display") self.fields['worker_display'].label = _("Worker Display")
back_label = _("Back") back_label = _("Back")
self.helper = FormHelper() self.helper = FormHelper()
self.helper.form_method = 'post' self.helper.form_method = 'post'
self.helper.layout = Layout( self.helper.layout = Layout(
Row( Row(
Column('enabled', css_class='form-group col-md-6 mb-0'), Column('enabled', css_class='form-group col-md-6 mb-0'),
@@ -130,10 +142,10 @@ class ClusterSettingsForm(forms.ModelForm):
stats_sync_interval = cleaned_data.get('stats_sync_interval') stats_sync_interval = cleaned_data.get('stats_sync_interval')
stats_cache_interval = cleaned_data.get('stats_cache_interval') stats_cache_interval = cleaned_data.get('stats_cache_interval')
if stats_sync_interval and stats_sync_interval < 10: if stats_sync_interval and stats_sync_interval < 60:
raise ValidationError(_("Stats sync interval must be at least 10 seconds.")) raise ValidationError(_("Stats sync interval must be at least 60 seconds."))
if stats_cache_interval and stats_cache_interval < 10: if stats_cache_interval and stats_cache_interval < 60:
raise ValidationError(_("Stats cache interval must be at least 10 seconds.")) raise ValidationError(_("Stats cache interval must be at least 60 seconds."))
return cleaned_data return cleaned_data

View File

@@ -0,0 +1,20 @@
# Generated by Django 5.2.9 on 2025-12-29 20:59
import uuid
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('cluster', '0004_alter_clustersettings_cluster_mode'),
]
operations = [
migrations.AlterField(
model_name='worker',
name='token',
field=models.UUIDField(default=uuid.uuid4, unique=True),
),
]

View File

@@ -30,7 +30,7 @@ class ClusterSettings(models.Model):
class Worker(models.Model): class Worker(models.Model):
name = models.CharField(max_length=100, unique=True) name = models.CharField(max_length=100, unique=True)
enabled = models.BooleanField(default=True) enabled = models.BooleanField(default=True)
token = models.UUIDField(default=uuid.uuid4) token = models.UUIDField(default=uuid.uuid4, unique=True)
ip_lock = models.BooleanField(default=False) ip_lock = models.BooleanField(default=False)
ip_address = models.GenericIPAddressField(blank=True, null=True) ip_address = models.GenericIPAddressField(blank=True, null=True)

View File

@@ -8,10 +8,10 @@
<th>{% trans 'Name' %}</th> <th>{% trans 'Name' %}</th>
<th>{% trans 'Status' %}</th> <th>{% trans 'Status' %}</th>
<th>{% trans 'IP Address' %}</th> <th>{% trans 'IP Address' %}</th>
<th>{% trans 'Location' %}</th> <th><i class="fas fa-map-marker-alt" title="{% trans 'Location' %}"></i></th>
<th>{% trans 'Last Seen' %}</th> <th><i class="far fa-clock" title="{% trans 'Last Seen' %}"></i></th>
<th>{% trans 'Config Version' %}</th> <th><i class="fas fa-cogs" title="{% trans 'Config Version' %}"></i></th>
<th colspan="2">{% trans 'Options' %}</th>
<th><i class="far fa-edit"></i></th> <th><i class="far fa-edit"></i></th>
</tr> </tr>
</thead> </thead>
@@ -21,9 +21,9 @@
<td>{{ worker.name }}</td> <td>{{ worker.name }}</td>
<td style="width: 1%; white-space: nowrap;"> <td style="width: 1%; white-space: nowrap;">
{% if worker.enabled %} {% if worker.enabled %}
<span class="badge badge-success">{% trans 'Enabled' %}</span> <i class="fas fa-check text-green"></i>
{% else %} {% else %}
<span class="badge badge-secondary">{% trans 'Disabled' %}</span> <i class="fas fa-times text-gray"></i>
{% endif %} {% endif %}
</td> </td>
<td> <td>
@@ -57,26 +57,20 @@
<i class="fas fa-clock text-warning" title="{% trans 'Config Pending' %}"></i> <i class="fas fa-clock text-warning" title="{% trans 'Config Pending' %}"></i>
{% endif %} {% endif %}
{% else %} {% else %}
<span class="text-muted">0</span>
{% endif %}
</td>
<td style="width: 1%; white-space: nowrap;">
{% if worker.force_reload %}
<i class="fas fa-sync-alt text-info" title="{% trans 'Force Reload' %}"></i>
{% endif %}
</td>
<td style="width: 1%; white-space: nowrap;">
{% if worker.force_restart %}
<i class="fas fa-power-off text-danger" title="{% trans 'Force Restart' %}"></i>
{% endif %} {% endif %}
</td> </td>
<td style="width: 1%; white-space: nowrap;"> <td style="width: 1%; white-space: nowrap;">
<i class="fas fa-sync-alt text-info" title="{% trans 'Force Reload' %}"></i>
<i class="fas fa-power-off text-danger" title="{% trans 'Force Restart' %}"></i>
<a href="/cluster/worker/manage/?uuid={{ worker.uuid }}" title="{% trans 'Edit' %}"><i class="far fa-edit"></i></a> <a href="/cluster/worker/manage/?uuid={{ worker.uuid }}" title="{% trans 'Edit' %}"><i class="far fa-edit"></i></a>
</td> </td>
</tr> </tr>
{% empty %} {% empty %}
<tr> <tr>
<td colspan="9" class="text-center text-muted">{% trans 'No workers configured' %}</td> <td colspan="8" class="text-center text-muted">{% trans 'No workers configured' %}</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>