Add peer group model

This commit is contained in:
Eduardo Silva 2025-01-20 09:55:35 -03:00
parent c79c587945
commit 797058b29b
4 changed files with 64 additions and 1 deletions

View file

@ -1,3 +1,4 @@
from django.core.exceptions import ValidationError
from django.db import models
import uuid
@ -119,4 +120,21 @@ class PeerAllowedIP(models.Model):
def __str__(self):
return str(self.allowed_ip) + '/' + str(self.netmask)
class PeerGroup(models.Model):
name = models.CharField(max_length=100, unique=True)
peer = models.ManyToManyField(Peer, blank=True)
server_instance = models.ManyToManyField(WireGuardInstance, blank=True)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
uuid = models.UUIDField(primary_key=True, editable=False)
def clean(self):
if self.peer.exists() and self.server_instance.exists():
raise ValidationError("Please choose either WireGuard Instances or Peers, not both.")
def save(self, *args, **kwargs):
self.clean()
super().save(*args, **kwargs)