Validate hostname. No duplicate ip-addresses.
This commit is contained in:
1 parent
f6247c88e8
commit
1f7696bef7
2 files changed
+9
-2
No files matched your search
+4
-2
@@ -2,6 +2,8 @@ from django.db import models
|
||||
from django.db.models.signals import post_save, pre_save, pre_delete
|
||||
from django.dispatch import receiver
|
||||
|
||||
from validators import validate_hostname
|
||||
|
||||
import ipaddr
|
||||
import datetime
|
||||
|
||||
@@ -411,7 +413,7 @@ class Host(models.Model):
|
||||
brand = models.CharField(max_length=1024)
|
||||
model = models.CharField(max_length=1024)
|
||||
owner = models.CharField(max_length=1024)
|
||||
hostname = models.CharField(max_length=64)
|
||||
hostname = models.CharField(max_length=64, validators=[validate_hostname])
|
||||
serial_number = models.CharField(max_length=256)
|
||||
description = models.CharField(max_length=1024)
|
||||
created_date = models.DateTimeField(auto_now_add=True)
|
||||
@@ -462,7 +464,7 @@ class Interface(models.Model):
|
||||
pxe_filename = models.CharField(max_length=64, blank=True)
|
||||
dhcp_client = models.BooleanField()
|
||||
host = models.ForeignKey(Host)
|
||||
ip4address = models.ForeignKey(Ip4Address, blank=True, null=True)
|
||||
ip4address = models.ForeignKey(Ip4Address, blank=True, null=True, unique=True)
|
||||
created_date = models.DateTimeField(auto_now_add=True)
|
||||
domain = models.ForeignKey(Domain)
|
||||
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
from django.core.validators import RegexValidator
|
||||
import re
|
||||
# http://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_host_names
|
||||
hostname_re = re.compile(r'^(?!-)[-a-z0-9]+(?<!-)$', re.IGNORECASE)
|
||||
validate_hostname = RegexValidator(hostname_re, u'Enter a valid hostname', 'invalid')
|
||||
Reference in new issue
Block a user