summaryrefslogtreecommitdiff
path: root/mirrors/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'mirrors/models.py')
-rw-r--r--mirrors/models.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/mirrors/models.py b/mirrors/models.py
index e41f6b22..d8ac7952 100644
--- a/mirrors/models.py
+++ b/mirrors/models.py
@@ -6,6 +6,7 @@ from django.db import models
from django.db.models.signals import pre_save
from django_countries import CountryField
+from .fields import IPNetworkField
from main.utils import set_created_field
@@ -91,7 +92,7 @@ class MirrorUrl(models.Model):
families = self.address_families()
self.has_ipv4 = socket.AF_INET in families
self.has_ipv6 = socket.AF_INET6 in families
- except socket.error as e:
+ except socket.error:
# We don't fail in this case; we'll just set both to False
self.has_ipv4 = False
self.has_ipv6 = False
@@ -105,7 +106,7 @@ class MirrorUrl(models.Model):
class MirrorRsync(models.Model):
# max length is 40 chars for full-form IPv6 addr + subnet
- ip = models.CharField("IP", max_length=44)
+ ip = IPNetworkField("IP")
mirror = models.ForeignKey(Mirror, related_name="rsync_ips")
created = models.DateTimeField(editable=False)
@@ -136,6 +137,15 @@ class CheckLocation(models.Model):
families = [x[0] for x in info]
return families[0]
+ @property
+ def ip_version(self):
+ '''Returns integer '4' or '6'.'''
+ if self.family == socket.AF_INET6:
+ return 6
+ if self.family == socket.AF_INET:
+ return 4
+ return None
+
class MirrorLog(models.Model):
url = models.ForeignKey(MirrorUrl, related_name="logs")