Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Clean up of previous commit [squash me]

  • Loading branch information...
commit 04b83da571ae6240616aa7a99aa0b04f1713bd08 1 parent ee4b447
@uberj uberj authored
Showing with 249 additions and 293 deletions.
  1. +0 −34 cyder/core/task/migrations/0001_initial.py
  2. 0  cyder/core/task/migrations/__init__.py
  3. +6 −6 cyder/core/task/models.py
  4. +16 −14 cyder/cydhcp/interface/static_intr/models.py
  5. +7 −6 cyder/cydhcp/network/models.py
  6. +19 −11 cyder/cydhcp/range/models.py
  7. +0 −4 cyder/cydhcp/site/models.py
  8. +1 −1  cyder/cydns/address_record/forms.py
  9. +33 −29 cyder/cydns/address_record/models.py
  10. +2 −1  cyder/cydns/cname/forms.py
  11. +24 −17 cyder/cydns/cname/models.py
  12. +3 −5 cyder/cydns/cybind/builder.py
  13. +0 −2  cyder/cydns/cybind/tests/build_tests.py
  14. +60 −45 cyder/cydns/cybind/zone_builder.py
  15. +7 −9 cyder/cydns/domain/models.py
  16. +1 −1  cyder/cydns/forms.py
  17. +13 −10 cyder/cydns/ip/models.py
  18. +3 −4 cyder/cydns/models.py
  19. +12 −12 cyder/cydns/mx/models.py
  20. +2 −2 cyder/cydns/nameserver/forms.py
  21. +3 −3 cyder/cydns/nameserver/models.py
  22. +1 −0  cyder/cydns/ptr/forms.py
  23. +10 −10 cyder/cydns/ptr/models.py
  24. +1 −1  cyder/cydns/srv/forms.py
  25. +1 −8 cyder/cydns/srv/models.py
  26. +0 −1  cyder/cydns/sshfp/forms.py
  27. +8 −8 cyder/cydns/sshfp/models.py
  28. +3 −0  cyder/cydns/tests/test_views.py
  29. +4 −39 cyder/cydns/tests/utils.py
  30. +1 −1  cyder/cydns/txt/forms.py
  31. +8 −8 cyder/cydns/txt/models.py
  32. +0 −1  cyder/cydns/view/forms.py
View
34 cyder/core/task/migrations/0001_initial.py
@@ -1,34 +0,0 @@
-# -*- coding: utf-8 -*-
-import datetime
-from south.db import db
-from south.v2 import SchemaMigration
-from django.db import models
-
-
-class Migration(SchemaMigration):
-
- def forwards(self, orm):
- # Adding model 'Task'
- db.create_table(u'task', (
- ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
- ('task', self.gf('django.db.models.fields.CharField')(max_length=255)),
- ('ttype', self.gf('django.db.models.fields.CharField')(max_length=255)),
- ))
- db.send_create_signal('task', ['Task'])
-
-
- def backwards(self, orm):
- # Deleting model 'Task'
- db.delete_table(u'task')
-
-
- models = {
- 'task.task': {
- 'Meta': {'ordering': "['task']", 'object_name': 'Task', 'db_table': "u'task'"},
- 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
- 'task': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
- 'ttype': ('django.db.models.fields.CharField', [], {'max_length': '255'})
- }
- }
-
- complete_apps = ['task']
View
0  cyder/core/task/migrations/__init__.py
No changes.
View
12 cyder/core/task/models.py
@@ -13,9 +13,9 @@ class Task(models.Model):
objects = models.Manager()
dns = DNSManager()
- @classmethod
- def schedule_zone_rebuild(cls, soa):
- Task(task=str(soa.pk), ttype='dns').save()
+ class Meta:
+ db_table = u'task'
+ ordering = ['task']
def __repr__(self):
return "<Task: {0}>".format(self)
@@ -26,6 +26,6 @@ def __str__(self):
def save(self):
super(Task, self).save()
- class Meta:
- db_table = u'task'
- ordering = ['task']
+ @classmethod
+ def schedule_zone_rebuild(cls, soa):
+ Task(task=str(soa.pk), ttype='dns').save()
View
30 cyder/cydhcp/interface/static_intr/models.py
@@ -99,6 +99,18 @@ class StaticInterface(BaseAddressRecord, models.Model, ObjectUrlMixin):
attrs = None
search_fields = ("mac", "ip_str", "fqdn")
+ class Meta:
+ db_table = "static_interface"
+ unique_together = ("ip_upper", "ip_lower", "label", "domain", "mac")
+
+ def __repr__(self):
+ return "<StaticInterface: {0}>".format(str(self))
+
+ def __str__(self):
+ #return "IP:{0} Full Name:{1} Mac:{2}".format(self.ip_str,
+ # self.fqdn, self.mac)
+ return self.fqdn
+
def update_attrs(self):
self.attrs = AuxAttr(StaticIntrKeyValue, self, "intr")
@@ -118,10 +130,6 @@ def details(self):
)
return data
- class Meta:
- db_table = "static_interface"
- unique_together = ("ip_upper", "ip_lower", "label", "domain", "mac")
-
@classmethod
def get_api_fields(cls):
return super(StaticInterface, cls).get_api_fields() + \
@@ -162,8 +170,10 @@ def interface_name(self):
def clean(self, *args, **kwargs):
self.mac = self.mac.lower()
if not self.system:
- raise ValidationError("An interface means nothing without it's "
- "system.")
+ raise ValidationError(
+ "An interface means nothing without it's system."
+ )
+
from cyder.cydns.ptr.models import PTR
if PTR.objects.filter(ip_str=self.ip_str, name=self.fqdn).exists():
@@ -227,14 +237,6 @@ def delete(self, *args, **kwargs):
super(StaticInterface, self).delete(validate_glue=False,
check_cname=check_cname)
- def __repr__(self):
- return "<StaticInterface: {0}>".format(str(self))
-
- def __str__(self):
- #return "IP:{0} Full Name:{1} Mac:{2}".format(self.ip_str,
- # self.fqdn, self.mac)
- return self.fqdn
-
class StaticIntrKeyValue(KeyValue):
intr = models.ForeignKey(StaticInterface, null=False)
View
13 cyder/cydhcp/network/models.py
@@ -3,7 +3,7 @@
from django.db import models
from django.core.exceptions import ValidationError
-from cyder.base.constants import IP_TYPES
+from cyder.base.constants import IP_TYPES, IP_TYPE_4, IP_TYPE_6
from cyder.base.mixins import ObjectUrlMixin
from cyder.cydhcp.keyvalue.base_option import CommonOption
from cyder.cydhcp.utils import IPFilter
@@ -30,7 +30,8 @@ class Network(models.Model, ObjectUrlMixin):
ip_lower = models.BigIntegerField(null=False, blank=True)
# This field is here so ES can search this model easier.
network_str = models.CharField(
- max_length=49, editable=True, help_text="The network address of this network.")
+ max_length=49, editable=True,
+ help_text="The network address of this network.")
prefixlen = models.PositiveIntegerField(
null=False, help_text="The number of binary 1's in the netmask.")
@@ -94,7 +95,7 @@ def save(self, *args, **kwargs):
super(Network, self).save(*args, **kwargs)
if add_routers:
- if self.ip_type == '4':
+ if self.ip_type == IP_TYPE_4:
router = str(ipaddr.IPv4Address(int(self.network.network) + 1))
else:
router = str(ipaddr.IPv6Address(int(self.network.network) + 1))
@@ -137,7 +138,7 @@ def check_valid_range(self):
fail = True
break
- if self.ip_type == '4':
+ if self.ip_type == IP_TYPE_4:
brdcst_upper, brdcst_lower = 0, int(self.network.broadcast)
else:
brdcst_upper, brdcst_lower = ipv6_to_longs(str(
@@ -200,9 +201,9 @@ def update_network(self):
if not isinstance(self.network_str, basestring):
raise ValidationError("ERROR: No network str.")
try:
- if self.ip_type == '4':
+ if self.ip_type == IP_TYPE_4:
self.network = ipaddr.IPv4Network(self.network_str)
- elif self.ip_type == '6':
+ elif self.ip_type == IP_TYPE_6:
self.network = ipaddr.IPv6Network(self.network_str)
else:
raise ValidationError("Could not determine IP type of network"
View
30 cyder/cydhcp/range/models.py
@@ -3,8 +3,10 @@
from django.http import HttpResponse
from cyder.base.mixins import ObjectUrlMixin
-from cyder.base.constants import IP_TYPES
-from cyder.cydhcp.constants import *
+from cyder.base.constants import IP_TYPES, IP_TYPE_4, IP_TYPE_6
+from cyder.cydhcp.constants import (
+ ALLOW_OPTIONS, DENY_OPTIONS, RANGE_TYPE, STATIC
+)
from cyder.cydhcp.interface.static_intr.models import StaticInterface
from cyder.cydhcp.network.models import Network
from cyder.cydhcp.utils import IPFilter, four_to_two
@@ -120,12 +122,12 @@ def clean(self):
"with a network and is not reserved".format(
self.start_str, self.end_str))
try:
- if self.ip_type == '4':
+ if self.ip_type == IP_TYPE_4:
self.start_upper, self.start_lower = 0, int(
ipaddr.IPv4Address(self.start_str))
self.end_upper, self.end_lower = 0, int(
ipaddr.IPv4Address(self.end_str))
- elif self.ip_type == '6':
+ elif self.ip_type == IP_TYPE_6:
self.start_upper, self.start_lower = ipv6_to_longs(
self.start_str)
self.end_upper, self.end_lower = ipv6_to_longs(self.end_str)
@@ -133,6 +135,7 @@ def clean(self):
raise ValidationError("ERROR: could not determine the ip type")
except ipaddr.AddressValueError, e:
raise ValidationError(str(e))
+
"""
Some notes:
start = s1 s2
@@ -161,13 +164,13 @@ def clean(self):
" or equal to the end of the range.")
if not self.is_reserved:
self.network.update_network()
- if self.network.ip_type == '4':
+ if self.network.ip_type == IP_TYPE_4:
IPClass = ipaddr.IPv4Address
else:
IPClass = ipaddr.IPv6Address
- if IPClass(self.start_str) < self.network.network.network or \
- IPClass(self.end_str) > self.network.network.broadcast:
+ if (IPClass(self.start_str) < self.network.network.network or
+ IPClass(self.end_str) > self.network.network.broadcast):
raise RangeOverflowError(
"Range {0} to {1} doesn't fit in {2}".format(
IPClass(self.start_lower),
@@ -176,11 +179,16 @@ def clean(self):
self.check_for_overlaps()
def check_for_overlaps(self):
- """This function will look at all the other ranges and make sure we
- don't overlap with any of them.
+ """
+ This function will look at all the other ranges and make sure we don't
+ overlap with any of them.
"""
self._range_ips()
- Ip = ipaddr.IPv4Address if self.ip_type == '4' else ipaddr.IPv6Address
+ if self.ip_type == IP_TYPE_4:
+ Ip = ipaddr.IPv4Address
+ else:
+ Ip = ipaddr.IPv6Address
+
for range in Range.objects.all():
if range.pk == self.pk:
continue
@@ -252,7 +260,7 @@ def find_free_ip(start, end, ip_type='4'):
:param ip_type: The type of IP you are looking for.
:type ip_type: str either '4' or '6'
"""
- if ip_type == '4':
+ if ip_type == IP_TYPE_4:
records = AddressRecord.objects.filter(ip_upper=0, ip_lower__gte=start,
ip_lower__lte=end)
ptrs = PTR.objects.filter(ip_upper=0, ip_lower__gte=start,
View
4 cyder/cydhcp/site/models.py
@@ -94,10 +94,6 @@ def compile_Q(self):
"""Compile a Django Q that will match any IP inside this site."""
return networks_to_Q(self.network_set.all())
- class Meta:
- db_table = 'site'
- unique_together = ('name', 'parent')
-
class SiteKeyValue(KeyValue):
site = models.ForeignKey(Site, null=False)
View
2  cyder/cydns/address_record/forms.py
@@ -1,6 +1,6 @@
-from cyder.cydns.forms import DNSForm
from django import forms
from cyder.cydns.address_record.models import AddressRecord
+from cyder.cydns.forms import DNSForm
class AddressRecordForm(DNSForm):
View
62 cyder/cydns/address_record/models.py
@@ -7,10 +7,12 @@
from cyder.cydns.cname.models import CNAME
from cyder.cydns.ip.models import Ip
from cyder.cydns.models import CydnsRecord, LabelDomainMixin
+from cyder.base.constants import IP_TYPE_6, IP_TYPE_4
class BaseAddressRecord(Ip, LabelDomainMixin, CydnsRecord):
- """AddressRecord is the class that generates A and AAAA records
+ """
+ AddressRecord is the class that generates A and AAAA records
>>> AddressRecord(label=label, domain=domain_object, ip_str=ip_str,
... ip_type=ip_type)
@@ -21,9 +23,16 @@ class BaseAddressRecord(Ip, LabelDomainMixin, CydnsRecord):
class Meta:
abstract = True
+ def __str__(self):
+ return "{0} {1} {2}".format(self.fqdn,
@uberj Collaborator
uberj added a note

awkward indentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ self.record_type(), str(self.ip_str))
+
+ def __repr__(self):
+ return "<Address Record '{0}'>".format(str(self))
+
@property
def rdtype(self):
- if self.ip_type == '6':
+ if self.ip_type == IP_TYPE_6:
return 'AAAA'
return 'A'
@@ -52,7 +61,7 @@ def get_api_fields(cls):
'ip_type']
def clean(self, *args, **kwargs):
- validate_glue = kwargs.pop("validate_glue", True)
+ validate_glue = kwargs.pop('validate_glue', True)
if validate_glue:
self.check_glue_status()
self.clean_ip()
@@ -63,23 +72,25 @@ def clean(self, *args, **kwargs):
self.check_for_cname()
from cyder.cydhcp.interface.static_intr.models import StaticInterface
- if not kwargs.pop("ignore_interface", False):
+ if not kwargs.pop('ignore_interface', False):
if StaticInterface.objects.filter(
fqdn=self.fqdn, ip_upper=self.ip_upper,
ip_lower=self.ip_lower).exists():
- raise ValidationError("A Static Interface has already "
- "reserved this A record.")
+ raise ValidationError(
+ "A Static Interface has already reserved this A "
+ "record.")
def delete(self, *args, **kwargs):
- """Address Records that are glue records or that are pointed to
+ """
+ Address Records that are glue records or that are pointed to
by a CNAME should not be removed from the database.
"""
- if kwargs.pop("validate_glue", True):
+ if kwargs.pop('validate_glue', True):
if self.nameserver_set.exists():
raise ValidationError(
"Cannot delete the record {0}. It is a glue "
"record.".format(self.record_type()))
- if kwargs.pop("check_cname", True):
+ if kwargs.pop('check_cname', True):
if CNAME.objects.filter(target=self.fqdn):
raise ValidationError(
"A CNAME points to this {0} record. Change the CNAME "
@@ -88,8 +99,10 @@ def delete(self, *args, **kwargs):
super(BaseAddressRecord, self).delete(*args, **kwargs)
def validate_delegation_conditions(self):
- """If our domain is delegated then an A record can only have a
- name that is the same as a nameserver in that domain (glue)."""
+ """
+ If our domain is delegated then an A record can only have a
+ name that is the same as a nameserver in that domain (glue).
+ """
if not (self.domain and self.domain.delegated):
return
if self.domain.nameserver_set.filter(server=self.fqdn).exists():
@@ -97,8 +110,9 @@ def validate_delegation_conditions(self):
else:
# Confusing error messege?
raise ValidationError(
- "You can only create A records in a "
- "delegated domain that have an NS record pointing to them.")
+ "You can only create A records in a delegated domain that "
+ "have an NS record pointing to them."
+ )
def check_glue_status(self):
"""
@@ -118,35 +132,25 @@ def check_glue_status(self):
Nameserver = cydns.nameserver.models.Nameserver
if Nameserver.objects.filter(addr_glue=self).exists():
raise ValidationError(
- "This record is a glue record for a"
- "Nameserver. Change the Nameserver to edit this record.")
+ "This record is a glue record for a Nameserver. Change the "
+ "Nameserver to edit this record."
+ )
def record_type(self):
- # If PTR didn't share this field, we would use 'A' and 'AAAA'
- # instead of '4' and '6'.
- if self.ip_type == '4':
+ if self.ip_type == IP_TYPE_4:
return 'A'
else:
return 'AAAA'
- def __str__(self):
- return "{0} {1} {2}".format(self.fqdn,
- self.record_type(), str(self.ip_str))
-
- def __repr__(self):
- return "<Address Record '{0}'>".format(str(self))
-
class AddressRecord(BaseAddressRecord):
- """AddressRecord is the class that generates A and AAAA records
+ """
+ AddressRecord is the class that generates A and AAAA records
>>> AddressRecord(label=label, domain=domain_object, ip_str=ip_str,
... ip_type=ip_type)
"""
- ############################
- # See Ip for all ip fields #
- ############################
id = models.AutoField(primary_key=True)
template = _("{bind_name:$lhs_just} {ttl} {rdclass:$rdclass_just} "
View
3  cyder/cydns/cname/forms.py
@@ -1,6 +1,7 @@
from django import forms
-from cyder.cydns.forms import DNSForm
+
from cyder.cydns.cname.models import CNAME
+from cyder.cydns.forms import DNSForm
class CNAMEForm(DNSForm):
View
41 cyder/cydns/cname/models.py
@@ -10,7 +10,8 @@
class CNAME(CydnsRecord, LabelDomainMixin):
- """CNAMES can't point to an any other records. Said another way,
+ """
+ CNAMES can't point to an any other records. Said another way,
CNAMES can't be at the samle level as any other record. This means
that when you are creating a CNAME every other record type must be
checked to make sure that the name about to be taken by the CNAME
@@ -29,6 +30,13 @@ class CNAME(CydnsRecord, LabelDomainMixin):
search_fields = ('fqdn', 'target')
+ class Meta:
+ db_table = 'cname'
+ unique_together = ('domain', 'label', 'target')
+
+ def __str__(self):
+ return "{0} CNAME {1}".format(self.fqdn, self.target)
+
def details(self):
"""For tables."""
data = super(CNAME, self).details()
@@ -45,10 +53,6 @@ def eg_metadata(self):
{'name': 'target', 'datatype': 'string', 'editable': True},
]}
- class Meta:
- db_table = 'cname'
- unique_together = ('domain', 'label', 'target')
-
@property
def rdtype(self):
return 'CNAME'
@@ -68,11 +72,9 @@ def clean(self, *args, **kwargs):
self.check_SOA_condition()
self.existing_node_check()
- def __str__(self):
- return "{0} CNAME {1}".format(self.fqdn, self.target)
-
def check_SOA_condition(self):
- """We need to check if the domain is the root domain in a zone.
+ """
+ We need to check if the domain is the root domain in a zone.
If the domain is the root domain, it will have an soa, but the
master domain will have no soa (or it will have a a different
soa).
@@ -87,11 +89,14 @@ def check_SOA_condition(self):
if root_domain is None:
return
if self.fqdn == root_domain.name:
- raise ValidationError("You cannot create a CNAME who's left hand "
- "side is at the same level as an SOA")
+ raise ValidationError(
+ "You cannot create a CNAME who's left hand side is at the "
+ "same level as an SOA"
+ )
def existing_node_check(self):
- """Make sure no other nodes exist at the level of this CNAME.
+ """
+ Make sure no other nodes exist at the level of this CNAME.
"If a CNAME RR is present at a node, no other data should be
present; this ensures that the data for
@@ -122,13 +127,15 @@ def existing_node_check(self):
qset = smart_fqdn_exists(self.fqdn, cn=False)
if qset:
objects = qset.all()
- raise ValidationError("Objects with this name already exist: {0}".
- format(objects))
+ raise ValidationError(
+ "Objects with this name already exist: {0}".format(objects)
+ )
MX = cyder.cydns.mx.models.MX
if MX.objects.filter(server=self.fqdn):
- raise ValidationError("RFC 2181 says you shouldn't point MX "
- "records at CNAMEs and an MX points to"
- " this name!")
+ raise ValidationError(
+ "RFC 2181 says you shouldn't point MX records at CNAMEs and "
+ "an MX points to this name!"
+ )
# There are preexisting records that break this rule. We can't support
# this requirement until those records are fixed
# PTR = cydns.ptr.models.PTR
View
8 cyder/cydns/cybind/builder.py
@@ -324,8 +324,8 @@ def clear_staging(self, force=False):
def lock(self):
"""
- Trys to write a lock file. Returns True if we get the lock, else return
- False.
+ Tryies to write a lock file. Returns True if we get the lock, else
+ return False.
"""
try:
if not os.path.exists(os.path.dirname(self.LOCK_FILE)):
@@ -721,7 +721,7 @@ def build_zone_files(self, soa_pks_to_rebuild):
.format(view.name, file_meta['prod_fname']),
root_domain=root_domain
)
- # run named-checkzone for good measure
+ # Run named-checkzone for good measure.
if self.STAGE_ONLY:
self.log("Not calling named-checkconf.",
root_domain=root_domain)
@@ -772,8 +772,6 @@ def stop_update_exists(self):
fail_mail(msg, subject="DNS builds have stoped")
self.log(msg)
return True
- else:
- return False
def goto_out(self):
self.log(self.format_title("Release Mutex"))
View
2  cyder/cydns/cybind/tests/build_tests.py
@@ -1,7 +1,6 @@
# These tests are similar to the ones in the scripts directory. They not ran on
# real data so the testing db needs to be filled with info.
import os
-from django.test.client import Client
from django.test import TestCase
from cyder.cydns.soa.models import SOA
@@ -23,7 +22,6 @@ def setUp(self):
self.r1, _ = Domain.objects.get_or_create(name="10.in-addr.arpa")
Domain.objects.get_or_create(name="edu")
Domain(name="oregonstate.edu")
- self.cleint = Client()
super(MockBuildScriptTests, self).setUp()
self.stop_update_file = '/tmp/fake/stop.update'
View
105 cyder/cydns/cybind/zone_builder.py
@@ -18,17 +18,22 @@
def render_soa_only(soa, root_domain):
+ kwargs = {
+ 'root_domain': root_domain.name,
+ 'primary': soa.primary,
+ 'contact': soa.contact,
+ 'refresh': str(soa.refresh),
@uberj Collaborator
uberj added a note

string coercion not necessary, it's done by format()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ 'retry': str(soa.retry),
+ 'expire': str(soa.expire),
+ 'minimum': soa.minimum
+ }
BUILD_STR = _("{root_domain}. IN SOA {primary}. {contact}. (\n"
"\t\t{{serial}} ; Serial\n"
"\t\t{refresh} ; Refresh\n"
"\t\t{retry} ; Retry\n"
"\t\t{expire} ; Expire\n"
"\t\t{minimum} ; Minimum\n"
- ")\n\n".format(
- root_domain=root_domain.name, primary=soa.primary,
- contact=soa.contact, refresh=str(soa.refresh),
- retry=str(soa.retry), expire=str(soa.expire),
- minimum=soa.minimum))
+ ")\n\n".format(**kwargs))
return BUILD_STR
@@ -58,34 +63,42 @@ def render_forward_zone(view, mega_filter):
data = _render_forward_zone(
default_ttl=DEFAULT_TTL,
- nameserver_set=Nameserver.objects.filter(mega_filter).filter(
- views__name=view.name).order_by('server'),
-
- mx_set=MX.objects.filter(mega_filter).filter(views__name=view.name
- ).order_by('server'),
-
- addressrecord_set=AddressRecord.objects.filter(mega_filter).filter(
- views__name=view.name).order_by('pk', 'ip_type', 'fqdn',
- 'ip_upper', 'ip_lower'),
-
- interface_set=StaticInterface.objects.filter(
- mega_filter, dns_enabled=True).filter(
- views__name=view.name).order_by('pk', 'ip_type', 'fqdn',
- 'ip_upper', 'ip_lower'),
-
- cname_set=CNAME.objects.filter(mega_filter).filter(
- views__name=view.name).order_by('fqdn'),
-
- srv_set=SRV.objects.filter(mega_filter).filter(views__name=view.name
- ).order_by(
- 'pk', 'fqdn'),
-
- txt_set=TXT.objects.filter(mega_filter).filter(views__name=view.name
- ).order_by(
- 'pk', 'fqdn'),
-
- sshfp_set=SSHFP.objects.filter(mega_filter).filter(
- views__name=view.name).order_by('pk', 'fqdn'),
+ nameserver_set=Nameserver.objects
+ .filter(mega_filter)
+ .filter(views__name=view.name).order_by('server'),
+
+ mx_set=MX.objects
+ .filter(mega_filter)
+ .filter(views__name=view.name).order_by('server'),
+
+ addressrecord_set=AddressRecord.objects
+ .filter(mega_filter).filter(views__name=view.name)
+ .order_by('pk', 'ip_type', 'fqdn', 'ip_upper', 'ip_lower'),
+
+ interface_set=StaticInterface.objects
+ .filter(mega_filter, dns_enabled=True)
+ .filter(views__name=view.name)
+ .order_by('pk', 'ip_type', 'fqdn', 'ip_upper', 'ip_lower'),
+
+ cname_set=CNAME.objects
+ .filter(mega_filter)
+ .filter(views__name=view.name)
+ .order_by('fqdn'),
+
+ srv_set=SRV.objects
+ .filter(mega_filter)
+ .filter(views__name=view.name)
+ .order_by('pk', 'fqdn'),
+
+ txt_set=TXT.objects
+ .filter(mega_filter)
+ .filter(views__name=view.name)
+ .order_by('pk', 'fqdn'),
+
+ sshfp_set=SSHFP.objects
+ .filter(mega_filter)
+ .filter(views__name=view.name)
+ .order_by('pk', 'fqdn'),
)
return data
@@ -123,21 +136,23 @@ def build_zone_data(view, root_domain, soa, logf=None):
This function does the heavy lifting of building a zone. It coordinates
getting all of the data out of the db into BIND format.
- :param soa: The SOA corresponding to the zone being built.
- :type soa: SOA
+ :param soa: The SOA corresponding to the zone being built.
+ :type soa: SOA
- :param root_domain: The root domain of this zone.
- :type root_domain: str
+ :param root_domain: The root domain of this zone.
+ :type root_domain: str
- :returns public_file_path: The path to the zone file in the STAGEING dir
- :type public_file_path: str
- :returns public_data: The data that should be written to public_file_path
- :type public_data: str
+ :returns public_file_path: The path to the zone file in the STAGEING
+ dir
+ :type public_file_path: str
+ :returns public_data: The data that should be written to
+ public_file_path
+ :type public_data: str
- :returns view_zone_file: The path to the zone file in the STAGEING dir
- :type view_zone_file: str
- :param view_data: The data that should be written to view_zone_file
- :type view_data: str
+ :returns view_zone_file: The path to the zone file in the STAGEING dir
+ :type view_zone_file: str
+ :param view_data: The data that should be written to view_zone_file
+ :type view_data: str
"""
ztype = 'reverse' if root_domain.is_reverse else 'forward'
if (soa.has_record_set(view=view, exclude_ns=True) and
View
16 cyder/cydns/domain/models.py
@@ -66,7 +66,7 @@ class Domain(models.Model, ObjectUrlMixin):
then doing a longest prefix match against all domains that have
is_reverse set to True.
- This last point is worth looking at furthur. When adding a new reverse
+ This last point is worth looking at further. When adding a new reverse
domain, all records in the PTR table should be checked for a more
appropriate domain. Also, when a domain is deleted, all PTR objects should
be passed down to the parent domain.
@@ -96,6 +96,12 @@ class Domain(models.Model, ObjectUrlMixin):
class Meta:
db_table = 'domain'
+ def __str__(self):
+ return "{0}".format(self.name)
+
+ def __repr__(self):
+ return "<Domain '{0}'>".format(self.name)
+
@property
def rdtype(self):
return 'DOMAIN'
@@ -191,12 +197,6 @@ def clean(self):
raise ValidationError("Child domains rely on this domain's "
"name remaining the same.")
- def __str__(self):
- return "{0}".format(self.name)
-
- def __repr__(self):
- return "<Domain '{0}'>".format(self.name)
-
def check_for_children(self):
if self.domain_set.exists():
raise ValidationError("Before deleting this domain, please "
@@ -227,8 +227,6 @@ def has_record_set(self, view=None, exclude_ns=False):
self.nameserver_set.filter(views=view).exists()):
return True
- return False
-
### Reverse Domain Functions
def reassign_ptr_delete(self):
"""This function serves as a pretty subtle workaround.
View
2  cyder/cydns/forms.py
@@ -27,7 +27,7 @@ def save(self, commit=True):
def delete_instance(self, instance):
instance.delete(call_prune_tree=False)
- # I coppied this form django.forms.models because it's default behavior
+ # Overrode form in django.forms.models because it's default behavior
# wasn't calling any sort of validators for m2m objects
def save_instance(self, instance, fields=None, fail_message='saved',
commit=True, exclude=None, construct=True):
View
23 cyder/cydns/ip/models.py
@@ -1,7 +1,7 @@
from django.db import models
from django.core.exceptions import ValidationError
-from cyder.base.constants import IP_TYPES
+from cyder.base.constants import IP_TYPES, IP_TYPE_6, IP_TYPE_4
from cyder.cydns.domain.models import name_to_domain
from cyder.cydns.ip.utils import ip_to_domain_name, nibbilize
@@ -81,6 +81,11 @@ class but do not need their :class:`Ip`'s to be tied back to a reverse
class Meta:
abstract = True
+ def __int__(self):
+ if self.ip_type == IP_TYPE_4:
+ return self.ip_lower
+ return (self.ip_upper * (2 ** 64)) + self.ip_lower
+
def clean_ip(self, update_reverse_domain=True):
"""
The clean method in Ip is different from the rest. It needs
@@ -90,9 +95,9 @@ def clean_ip(self, update_reverse_domain=True):
"""
# TODO, it's a fucking hack. Car babies.
self.validate_ip_str()
- if self.ip_type == '4':
+ if self.ip_type == IP_TYPE_4:
Klass = ipaddr.IPv4Address
- elif self.ip_type == '6':
+ elif self.ip_type == IP_TYPE_6:
Klass = ipaddr.IPv6Address
else:
raise ValidationError("Invalid ip type {0}".format(self.ip_type))
@@ -102,14 +107,17 @@ def clean_ip(self, update_reverse_domain=True):
except ipaddr.AddressValueError:
raise ValidationError("Invalid Ip address {0}".format(self.ip_str))
- if self.ip_type == '4':
+ if self.ip_type == IP_TYPE_4:
self.ip_upper, self.ip_lower = 0, int(ip)
else: # We already gaurded again't a non '6' ip_type
self.ip_upper, self.ip_lower = ipv6_to_longs(int(ip))
def update_reverse_domain(self):
# We are assuming that self.clean_ip has been called already
- rvname = nibbilize(self.ip_str) if self.ip_type == '6' else self.ip_str
+ if self.ip_type == IP_TYPE_6:
+ rvname = nibbilize(self.ip_str)
+ else:
+ rvname = self.ip_str
rvname = ip_to_domain_name(rvname, ip_type=self.ip_type)
self.reverse_domain = name_to_domain(rvname)
if (self.reverse_domain is None or self.reverse_domain.name in
@@ -117,11 +125,6 @@ def update_reverse_domain(self):
raise ValidationError("No reverse Domain found for {0} "
.format(self.ip_str))
- def __int__(self):
- if self.ip_type == '4':
- return self.ip_lower
- return (self.ip_upper * (2 ** 64)) + self.ip_lower
-
def validate_ip_str(self):
if not isinstance(self.ip_str, basestring):
raise ValidationError("Plase provide the string representation"
View
7 cyder/cydns/models.py
@@ -97,7 +97,9 @@ class CydnsRecord(BaseModel, ViewMixin, DisplayMixin, ObjectUrlMixin):
help_text="Time to Live of this record")
description = models.CharField(max_length=1000, blank=True, null=True,
help_text="A description of this record.")
- # fqdn = label + domain.name <--- see set_fqdn
+
+ class Meta:
+ abstract = True
def __str__(self):
self.set_fqdn()
@@ -106,9 +108,6 @@ def __str__(self):
def __repr__(self):
return "<{0} '{1}'>".format(self.rdtype, str(self))
- class Meta:
- abstract = True
-
@classmethod
def get_api_fields(cls):
"""
View
24 cyder/cydns/mx/models.py
@@ -30,6 +30,18 @@ class MX(CydnsRecord, LabelDomainMixin):
"{server:$rhs_just}.")
search_fields = ('fqdn', 'server')
+ class Meta:
+ db_table = 'mx'
+ # label and domain in CydnsRecord
+ unique_together = ('domain', 'label', 'server', 'priority')
+
+ def __str__(self):
+ return "{0} {1} {3} {4} {5}".format(self.fqdn, self.ttl, 'IN', 'MX',
+ self.priority, self.server)
+
+ def __repr__(self):
+ return "<MX '{0}'>".format(str(self))
+
def details(self):
"""For tables."""
data = super(MX, self).details()
@@ -50,11 +62,6 @@ def eg_metadata(self):
{'name': 'ttl', 'datatype': 'integer', 'editable': True},
]}
- class Meta:
- db_table = 'mx'
- # label and domain in CydnsRecord
- unique_together = ('domain', 'label', 'server', 'priority')
-
@property
def rdtype(self):
return 'MX'
@@ -72,13 +79,6 @@ def clean(self, *args, **kwargs):
super(MX, self).check_for_cname()
self.no_point_to_cname()
- def __str__(self):
- return "{0} {1} {3} {4} {5}".format(self.fqdn, self.ttl, 'IN', 'MX',
- self.priority, self.server)
-
- def __repr__(self):
- return "<MX '{0}'>".format(str(self))
-
def no_point_to_cname(self):
"""MX records should not point to CNAMES."""
# TODO, cite an RFC.
View
4 cyder/cydns/nameserver/forms.py
@@ -1,8 +1,8 @@
from django import forms
-from cyder.cydns.forms import DNSForm
-from cyder.cydns.nameserver.models import Nameserver
from cyder.cydns.address_record.models import AddressRecord
+from cyder.cydns.forms import DNSForm
+from cyder.cydns.nameserver.models import Nameserver
from cyder.cydhcp.interface.static_intr.models import StaticInterface
View
6 cyder/cydns/nameserver/models.py
@@ -47,13 +47,13 @@ class Nameserver(CydnsRecord):
search_fields = ("server", "domain__name")
- def __str__(self):
- return self.bind_render_record()
-
class Meta:
db_table = "nameserver"
unique_together = ("domain", "server")
+ def __str__(self):
+ return self.bind_render_record()
+
@classmethod
def get_api_fields(cls):
return ['ttl', 'description', 'server', 'domain', 'views']
View
1  cyder/cydns/ptr/forms.py
@@ -1,4 +1,5 @@
from django import forms
+
from cyder.cydns.forms import DNSForm
from cyder.cydns.ptr.models import PTR
View
20 cyder/cydns/ptr/models.py
@@ -31,6 +31,16 @@ class PTR(Ip, ViewMixin, ObjectUrlMixin, DisplayMixin):
"{rdtype:$rdtype_just} {name:1}.")
search_fields = ('ip_str', 'name')
+ class Meta:
+ db_table = 'ptr'
+ unique_together = ('ip_str', 'ip_type', 'name')
+
+ def __str__(self):
+ return "{0} {1} {2}".format(str(self.ip_str), 'PTR', self.name)
+
+ def __repr__(self):
+ return "<{0}>".format(str(self))
+
@classmethod
def get_api_fields(cls):
return ['ip_str', 'ip_type', 'name', 'ttl', 'description']
@@ -51,10 +61,6 @@ def eg_metadata(self):
{'name': 'ip_str', 'datatype': 'string', 'editable': True},
]}
- class Meta:
- db_table = 'ptr'
- unique_together = ('ip_str', 'ip_type', 'name')
-
@property
def rdtype(self):
return 'PTR'
@@ -117,12 +123,6 @@ def clean(self, *args, **kwargs):
self.update_reverse_domain()
self.check_no_ns_soa_condition(self.reverse_domain)
- def __str__(self):
- return "{0} {1} {2}".format(str(self.ip_str), 'PTR', self.name)
-
- def __repr__(self):
- return "<{0}>".format(str(self))
-
def dns_name(self):
"""
Return the cononical name of this ptr that can be placed in a
View
2  cyder/cydns/srv/forms.py
@@ -1,6 +1,6 @@
from django import forms
-from cyder.cydns.forms import DNSForm
+from cyder.cydns.forms import DNSForm
from cyder.cydns.srv.models import SRV
View
9 cyder/cydns/srv/models.py
@@ -9,13 +9,6 @@
)
from cyder.cydns.models import CydnsRecord
-# import reversion
-
-# Rhetorical Question: Why is SRV not a common record? SRV records have
-# a '_' in their label. Most domain names do not allow this. Cydns
-# record has a validator that would raise an exception when validating
-# it's label. TODO, verify this.
-
class SRV(CydnsRecord):
"""
@@ -74,7 +67,7 @@ def eg_metadata(self):
]}
class Meta:
- db_table = "srv"
+ db_table = 'srv'
unique_together = ("label", "domain", "target", "port")
@classmethod
View
1  cyder/cydns/sshfp/forms.py
@@ -1,5 +1,4 @@
from cyder.cydns.forms import DNSForm
-
from cyder.cydns.sshfp.models import SSHFP
View
16 cyder/cydns/sshfp/models.py
@@ -47,6 +47,14 @@ class SSHFP(CydnsRecord, LabelDomainMixin):
search_fields = ("fqdn", "key")
+ class Meta:
+ db_table = 'sshfp'
+ # unique_together = ('domain', 'label', 'txt_data')
+ # TODO
+ # _mysql_exceptions.OperationalError: (1170, "BLOB/TEXT column
+ # 'txt_data' used in key specification without a key length")
+ # Fix that ^
+
def details(self):
"""For tables."""
data = super(SSHFP, self).details()
@@ -76,11 +84,3 @@ def get_api_fields(cls):
@property
def rdtype(self):
return 'SSHFP'
-
- class Meta:
- db_table = "sshfp"
- # unique_together = ('domain', 'label', 'txt_data')
- # TODO
- # _mysql_exceptions.OperationalError: (1170, "BLOB/TEXT column
- # 'txt_data' used in key specification without a key length")
- # Fix that ^
View
3  cyder/cydns/tests/test_views.py
@@ -68,15 +68,18 @@ def test_no_ns_in_view(self):
start_obj_count = self.test_class.objects.all().count()
post_data['views'] = [self.public_view.pk]
+
# Create the object then get the object
resp = self.client.post(self.test_class.get_create_url(),
post_data, follow=True)
self.assertEqual(resp.status_code, 200)
new_obj_count = self.test_class.objects.all().count()
+
# Nothing should have been created
self.assertEqual(start_obj_count, new_obj_count)
ns.views.add(self.public_view)
+
# Okay, we should be able to add to the public view now
start_obj_count = self.test_class.objects.all().count()
resp = self.client.post(self.test_class.get_create_url(),
View
43 cyder/cydns/tests/utils.py
@@ -4,8 +4,7 @@
import string
import time
-from django.core.exceptions import ObjectDoesNotExist, ValidationError
-from django.shortcuts import render
+from django.core.exceptions import ValidationError
from django.http import HttpResponse
from django.test import RequestFactory
@@ -13,7 +12,7 @@
from cyder.cydns.nameserver.models import Nameserver
from cyder.cydns.soa.models import SOA
from cyder.cydns.view.models import View
-from cyder.cydns.utils import get_zones, ensure_domain, prune_tree
+from cyder.cydns.utils import ensure_domain, prune_tree
def get_post_data(random_str, suffix):
@@ -36,7 +35,8 @@ def create_fake_zone(random_str, suffix=".mozilla.com"):
def create_zone_ajax(request):
- """This view tries to create a new zone and returns an JSON with either
+ """
+ This view tries to create a new zone and returns an JSON with either
'success' = True or 'success' = False and some errors. By default all
records are created and added to the public view.
@@ -154,41 +154,6 @@ def _clean_domain_tree(domain):
prune_tree(domain) # prune_tree will delete this domain
-def create_zone(request):
- template_zone = request.GET.get('template_zone', '').strip('"')
-
- context = None
- message = ''
- zones = get_zones()
- if template_zone:
- try:
- root_domain = zones.get(name=template_zone)
- context = {
- 'message': 'Using {0} as a template.'.format(template_zone),
- 'root_domain': root_domain.name,
- 'contact': root_domain.soa.contact,
- 'primary': root_domain.soa.primary,
- 'nss': root_domain.nameserver_set.all(),
- 'zones': json.dumps(
- sorted([z.name for z in get_zones()], reverse=True))
- }
- except ObjectDoesNotExist:
- message = gt('When trying to use {0} as a template, no zone '
- 'named {0} was found.'.format(template_zone))
- if not context:
- context = {
- 'message': message,
- 'root_domain': '',
- 'contact': '',
- 'primary': '',
- 'nss': [],
- 'zones': json.dumps(
- sorted([z.name for z in get_zones()], reverse=True))
- }
-
- return render(request, 'create_zone/create_zone.html', context)
-
-
def random_label():
"""
Utility function to generate a random *valid* label.
View
2  cyder/cydns/txt/forms.py
@@ -1,6 +1,6 @@
-from cyder.cydns.forms import DNSForm
from django import forms
+from cyder.cydns.forms import DNSForm
from cyder.cydns.txt.models import TXT
View
16 cyder/cydns/txt/models.py
@@ -20,6 +20,14 @@ class TXT(CydnsRecord, LabelDomainMixin):
template = _("{bind_name:$lhs_just} {ttl} {rdclass:$rdclass_just} "
"{rdtype:$rdtype_just} \"{txt_data:$rhs_just}\"")
+ class Meta:
+ db_table = 'txt'
+ # unique_together = ("domain", "label", "txt_data")
+ # TODO
+ # _mysql_exceptions.OperationalError: (1170, "BLOB/TEXT column
+ # "txt_data" used in key specification without a key length")
+ # Fix that ^
+
def details(self):
"""For tables."""
data = super(TXT, self).details()
@@ -44,11 +52,3 @@ def get_api_fields(cls):
@property
def rdtype(self):
return 'TXT'
-
- class Meta:
- db_table = "txt"
- # unique_together = ("domain", "label", "txt_data")
- # TODO
- # _mysql_exceptions.OperationalError: (1170, "BLOB/TEXT column
- # "txt_data" used in key specification without a key length")
- # Fix that ^
View
1  cyder/cydns/view/forms.py
@@ -1,5 +1,4 @@
from cyder.cydns.forms import DNSForm
-
from cyder.cydns.view.models import View
Please sign in to comment.
Something went wrong with that request. Please try again.