Add validation when setting peers

- cannot peer to self
- cannot peer to instance that is already peered to self

Other changes:
- ReceptorAddress protocol field restricted to choices: tcp, ws, wss
- fix awx-manage list_instances when instance.last_seen is None
- InstanceLink make source and target unique together
- Add help text to the ReceptorAddress fields

Signed-off-by: Seth Foster <fosterbseth@gmail.com>
This commit is contained in:
Seth Foster
2023-11-13 11:58:05 -05:00
committed by Seth Foster
parent 7d7503279d
commit 5385eb0fb3
5 changed files with 59 additions and 18 deletions

View File

@@ -1,4 +1,4 @@
# Generated by Django 4.2.6 on 2023-11-09 19:11
# Generated by Django 4.2.6 on 2023-11-13 16:10
import django.core.validators
from django.db import migrations, models
@@ -15,17 +15,30 @@ class Migration(migrations.Migration):
name='ReceptorAddress',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('address', models.CharField(max_length=255)),
('address', models.CharField(help_text='Routable address for this instance.', max_length=255)),
(
'port',
models.IntegerField(
default=27199, validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(65535)]
default=27199,
help_text='Port for the address.',
validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(65535)],
),
),
('protocol', models.CharField(default='tcp', max_length=10)),
('websocket_path', models.CharField(blank=True, default='', max_length=255)),
('is_internal', models.BooleanField(default=False)),
('peers_from_control_nodes', models.BooleanField(default=False)),
(
'protocol',
models.CharField(
choices=[('tcp', 'TCP'), ('ws', 'WS'), ('wss', 'WSS')],
default='tcp',
help_text="Protocol to use when connecting, 'tcp' or 'ws'.",
max_length=10,
),
),
('websocket_path', models.CharField(blank=True, default='', help_text='Websocket path.', max_length=255)),
('is_internal', models.BooleanField(default=False, help_text='If True, only routable inside of the Kubernetes cluster.')),
(
'peers_from_control_nodes',
models.BooleanField(default=False, help_text='If True, control plane cluster nodes should automatically peer to it.'),
),
],
),
migrations.RemoveConstraint(
@@ -45,6 +58,10 @@ class Migration(migrations.Migration):
name='source',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='main.instance'),
),
migrations.AddConstraint(
model_name='instancelink',
constraint=models.UniqueConstraint(fields=('source', 'target'), name='source_target_unique_together'),
),
migrations.AddField(
model_name='receptoraddress',
name='instance',