Permalink
Browse files

backporting stuff from inventory.

Conflicts:
	cyder/cydhcp/interface/static_intr/models.py
	cyder/cydns/address_record/models.py
	cyder/cydns/tests/test_views.py
	cyder/settings/base.py
  • Loading branch information...
uberj committed Mar 18, 2013
1 parent 61c1ee8 commit c1dbb66ffb011de247d5a5b1402fb5977f59d8b1
Showing with 2,557 additions and 1,348 deletions.
  1. +2 −0 README.md
  2. 0 cyder/core/task/__init__.py
  3. +31 −0 cyder/core/task/models.py
  4. +51 −0 cyder/core/utils.py
  5. +57 −68 cyder/cydhcp/interface/static_intr/models.py
  6. +13 −16 cyder/cydhcp/lib/tests/free_ip.py
  7. +20 −23 cyder/cydhcp/lib/tests/intr_from_range.py
  8. +5 −5 cyder/cydhcp/network/models.py
  9. +19 −11 cyder/cydhcp/range/models.py
  10. +0 −4 cyder/cydhcp/site/models.py
  11. +2 −2 cyder/cydns/address_record/forms.py
  12. +59 −108 cyder/cydns/address_record/models.py
  13. +4 −3 cyder/cydns/cname/forms.py
  14. +36 −31 cyder/cydns/cname/models.py
  15. +25 −26 cyder/cydns/cname/tests/test_models.py
  16. +466 −201 cyder/cydns/cybind/builder.py
  17. +1 −0 cyder/cydns/cybind/test_models.py
  18. +107 −49 cyder/cydns/cybind/tests/build_tests.py
  19. +114 −80 cyder/cydns/cybind/tests/dirty_soa.py
  20. 0 cyder/cydns/cybind/tests/{all.py → test_models.py}
  21. +90 −85 cyder/cydns/cybind/zone_builder.py
  22. +64 −48 cyder/cydns/domain/models.py
  23. +16 −19 cyder/cydns/domain/tests/auto_delete.py
  24. +3 −8 cyder/cydns/domain/tests/auto_update.py
  25. +64 −35 cyder/cydns/domain/tests/full_name.py
  26. +81 −0 cyder/cydns/forms.py
  27. +40 −48 cyder/cydns/ip/models.py
  28. +1 −0 cyder/cydns/ip/tests/test_models.py
  29. +10 −8 cyder/cydns/ip/utils.py
  30. +139 −86 cyder/cydns/models.py
  31. +2 −2 cyder/cydns/mx/forms.py
  32. +8 −12 cyder/cydns/mx/models.py
  33. +3 −4 cyder/cydns/nameserver/forms.py
  34. +63 −61 cyder/cydns/nameserver/models.py
  35. +275 −0 cyder/cydns/nameserver/tests/test_models.py
  36. +5 −2 cyder/cydns/ptr/forms.py
  37. +38 −33 cyder/cydns/ptr/models.py
  38. +45 −25 cyder/cydns/soa/models.py
  39. +3 −3 cyder/cydns/srv/forms.py
  40. +20 −107 cyder/cydns/srv/models.py
  41. +27 −12 cyder/cydns/srv/tests/test_models.py
  42. +3 −4 cyder/cydns/sshfp/forms.py
  43. +23 −27 cyder/cydns/sshfp/models.py
  44. +13 −15 cyder/cydns/sshfp/tests/test_models.py
  45. +128 −30 cyder/cydns/tests/test_views.py
  46. +171 −0 cyder/cydns/tests/utils.py
  47. +3 −3 cyder/cydns/txt/forms.py
  48. +4 −21 cyder/cydns/txt/models.py
  49. +4 −12 cyder/cydns/txt/tests/test_models.py
  50. +6 −2 cyder/cydns/utils.py
  51. +1 −1 cyder/cydns/validation.py
  52. +2 −3 cyder/cydns/view/forms.py
  53. 0 cyder/scripts/__init__.py
  54. 0 cyder/scripts/dnsbuilds/__init__.py
  55. 0 cyder/{cydns/cybind → scripts}/dnsbuilds/main.py
  56. 0 cyder/scripts/dnsbuilds/tests/__init__.py
  57. +165 −0 cyder/scripts/dnsbuilds/tests/build_tests.py
  58. +5 −4 cyder/settings/base.py
  59. +20 −1 cyder/settings/dnsbuilds.py
View
@@ -24,6 +24,8 @@ Installation
Install dependencies. (virtualenv recommended)
+#TODO sudo yum install openldap-devel on fedora
+
```
sudo apt-get install python-dev libldap2-dev libsasl2-dev libssl-dev
git submodule update --init --recursive
No changes.
View
@@ -0,0 +1,31 @@
+from django.db import models
+
+
+class DNSManager(models.Manager):
+ def get_queryset(self):
+ return super(DNSManager, self).get_queryset().filter(ttype='dns')
+
+
+class Task(models.Model):
+ task = models.CharField(max_length=255, blank=False)
+ ttype = models.CharField(max_length=255, blank=False)
+
+ objects = models.Manager()
+ dns = DNSManager()
+
+ class Meta:
+ db_table = u'task'
+ ordering = ['task']
+
+ def __repr__(self):
+ return "<Task: {0}>".format(self)
+
+ def __str__(self):
+ return "{0} {1}".format(self.ttype, self.task)
+
+ def save(self):
+ super(Task, self).save()
+
+ @classmethod
+ def schedule_zone_rebuild(cls, soa):
+ Task(task=str(soa.pk), ttype='dns').save()
View
@@ -0,0 +1,51 @@
+from email.mime.text import MIMEText
+import smtplib
+
+
+# Reference http://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html
+# TODO, use this on all views touching DNS stuff
+def locked_function(lock_name, timeout=10):
+ """
+ This is a decorator that should be used around any view or function that
+ modifies, creates, or deletes a DNS model.
+ It's purpose is to prevent this case:
+
+ http://people.mozilla.com/~juber/public/t1_t2_scenario.txt
+
+ """
+ def decorator(f):
+ def new_function(*args, **kwargs):
+ from django.db import connection
+ cursor = connection.cursor()
+ cursor.execute(
+ "SELECT GET_LOCK('{lock_name}', {timeout});".format(
+ lock_name=lock_name, timeout=timeout
+ )
+ )
+ ret = f(*args, **kwargs)
+ cursor.execute(
+ "SELECT RELEASE_LOCK('{lock_name}');".format(
+ lock_name=lock_name
+ )
+ )
+ return ret
+ return new_function
+ return decorator
+
+# TODO, move this into a config file and decide on an email to send errors to.
+people_who_need_to_know_about_failures = ''
+inventorys_email = ''
+
+
+def fail_mail(content, subject='Inventory is having issues.',
+ to=people_who_need_to_know_about_failures,
+ from_=inventorys_email):
+ """Send email about a failure."""
+ return # TODO, enable this in production
+ msg = MIMEText(content)
+ msg['Subject'] = subject
+ msg['From'] = inventorys_email
+ # msg['To'] = to
+ s = smtplib.SMTP('localhost')
+ s.sendmail(from_, to, msg.as_string())
+ s.quit()
@@ -17,11 +17,8 @@
from cyder.cydns.address_record.models import AddressRecord, BaseAddressRecord
from cyder.cydns.ip.utils import ip_to_dns_form
-from cyder.cydns.view.models import View
from cyder.cydns.domain.models import Domain
-# import reversion
-
class StaticInterface(BaseAddressRecord, models.Model, ObjectUrlMixin):
"""The StaticInterface Class.
@@ -84,47 +81,55 @@ class StaticInterface(BaseAddressRecord, models.Model, ObjectUrlMixin):
"""
id = models.AutoField(primary_key=True)
mac = models.CharField(max_length=17, validators=[validate_mac],
- help_text="Mac address in format XX:XX:XX:XX:XX:XX")
+ help_text='Mac address in format XX:XX:XX:XX:XX:XX')
reverse_domain = models.ForeignKey(Domain, null=True, blank=True,
- related_name="staticintrdomain_set")
+ related_name='staticintrdomain_set')
system = models.ForeignKey(
System, null=True, blank=True,
- help_text="System to associate the interface with")
+ help_text='System to associate the interface with')
vrf = models.ForeignKey(Vrf, null=True, blank=True)
workgroup = models.ForeignKey(Workgroup, null=True, blank=True)
dhcp_enabled = models.BooleanField(
- default=True, help_text="Enable dhcp for this interface?")
+ default=True, help_text='Enable dhcp for this interface?')
dns_enabled = models.BooleanField(
- default=True, help_text="Enable dns for this interface?")
+ default=True, help_text='Enable dns for this interface?')
attrs = None
- search_fields = ("mac", "ip_str", "fqdn")
+ 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")
+ self.attrs = AuxAttr(StaticIntrKeyValue, self, 'intr')
def details(self):
data = super(StaticInterface, self).details()
data['data'] = (
- ("Name", 'fqdn', self),
- ("IP", 'ip_str', str(self.ip_str)),
- ("MAC", 'mac', self.mac),
- ("Vrf", 'vrf', self.vrf),
- ("Workgroup", 'workgroup', self.workgroup),
- ("DHCP Enabled", "dhcp_enabled",
- "True" if self.dhcp_enabled else "False"),
- ("DNS Enabled", "dns_enabled",
- "True" if self.dns_enabled else "False"),
- ("DNS Type", '', "A/PTR"),
+ ('Name', 'fqdn', self),
+ ('IP', 'ip_str', str(self.ip_str)),
+ ('MAC', 'mac', self.mac),
+ ('Vrf', 'vrf', self.vrf),
+ ('Workgroup', 'workgroup', self.workgroup),
+ ('DHCP Enabled', 'dhcp_enabled',
+ 'True' if self.dhcp_enabled else 'False'),
+ ('DNS Enabled', 'dns_enabled',
+ 'True' if self.dns_enabled else 'False'),
+ ('DNS Type', '', 'A/PTR'),
)
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() + \
@@ -144,25 +149,24 @@ def interface_name(self):
except AttributeError:
pass
if itype == '' or primary == '':
- return "None"
+ return 'None'
elif alias == '':
- return "{0}{1}".format(itype, primary)
+ return '{0}{1}'.format(itype, primary)
else:
- return "{0}{1}.{2}".format(itype, primary, alias)
-
+ return '{0}{1}.{2}'.format(itype, primary, alias)
def build_host(self):
- join_args = lambda x: "\n".join(map(lambda y: "\t\t{0};".format(y)))
- build_str = "\thost {0} {{\n".format(self.fqdn)
- build_str += "\t\thardware ethernet {0};\n".format(self.mac)
- build_str += "\t\tfixed-address {0};\n".format(self.ip_str)
+ join_args = lambda x: '\n'.join(map(lambda y: '\t\t{0};'.format(y)))
+ build_str = '\thost {0} {{\n'.format(self.fqdn)
+ build_str += '\t\thardware ethernet {0};\n'.format(self.mac)
+ build_str += '\t\tfixed-address {0};\n'.format(self.ip_str)
options = self.static_intr_key_value_set.filter(is_option=True)
statements = self.statc_intr_key_value_set.filter(is_statement=True)
- build_str += "\t\t# Host Options\n"
+ build_str += '\t\t# Host Options\n'
build_str += join_args(options)
- build_str += "\t\t# Host Statements\n"
+ build_str += '\t\t# Host Statements\n'
build_str += join_args(statements)
- build_str += "\t}\n\n"
+ build_str += '\t}\n\n'
return build_str
@@ -172,35 +176,28 @@ def build_subclass(self, contained_range, allowed):
def clean(self, *args, **kwargs):
- #if not isinstance(self.mac, basestring):
- # raise ValidationError("Mac Address not of valid type.")
- #self.mac = self.mac.lower()
+ self.mac = self.mac.lower()
+ if not self.system:
+ raise ValidationError(
+ "An interface means nothing without it's system."
+ )
+
from cyder.cydns.ptr.models import PTR
- if not self.system:
- raise ValidationError("An interface means nothing without it's "
- "system.")
if PTR.objects.filter(ip_str=self.ip_str, name=self.fqdn).exists():
- raise ValidationError("A PTR already uses this Name and IP")
- if AddressRecord.objects.filter(
- ip_str=self.ip_str, fqdn=self.fqdn).exists():
- raise ValidationError("An A record already uses this Name and IP")
+ raise ValidationError('A PTR already uses this Name and IP')
+ if AddressRecord.objects.filter(ip_str=self.ip_str, fqdn=self.fqdn
+ ).exists():
+ raise ValidationError('An A record already uses this Name and IP')
- if kwargs.pop("validate_glue", True):
+ if kwargs.pop('validate_glue', True):
self.check_glue_status()
+ self.update_reverse_domain()
+ self.check_no_ns_soa_condition(self.reverse_domain)
super(StaticInterface, self).clean(validate_glue=False,
- update_reverse_domain=True,
ignore_interface=True)
- if self.pk and self.ip_str.startswith("10."):
- p = View.objects.filter(name="private")
- if p:
- self.views.add(p[0])
- super(StaticInterface, self).clean(validate_glue=False,
- update_reverse_domain=True,
- ignore_interface=True)
-
def check_glue_status(self):
"""If this interface is a 'glue' record for a Nameserver instance,
do not allow modifications to this record. The Nameserver will
@@ -236,30 +233,22 @@ def bind_render_record(self, pk=False, **kwargs):
return super(StaticInterface, self).bind_render_record(pk=pk, **kwargs)
def obj_type(self):
- return "A/PTR"
+ return 'A/PTR'
def delete(self, *args, **kwargs):
- if kwargs.pop("validate_glue", True):
+ if kwargs.pop('validate_glue', True):
if self.intrnameserver_set.exists():
raise ValidationError("Cannot delete the record {0}. "
"It is a glue record.".format(
self.obj_type()))
- check_cname = kwargs.pop("check_cname", True)
+ check_cname = kwargs.pop('check_cname', True)
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(CommonOption):
intr = models.ForeignKey(StaticInterface, null=False)
class Meta:
- db_table = "static_intr_key_value"
- unique_together = ("key", "value", "intr")
+ db_table = 'static_intr_key_value'
+ unique_together = ('key', 'value', 'intr')
@@ -8,35 +8,32 @@
from cyder.cydhcp.lib.utils import calc_free_ips_str
from cyder.cydhcp.lib.utils import create_ipv4_intr_from_range
from cyder.cydns.domain.models import Domain
-from cyder.cydns.soa.models import SOA
from cyder.core.system.models import System
+from cyder.cydns.tests.utils import create_fake_zone
+
class LibTestsFreeIP(TestCase):
def setUp(self):
self.system = System()
- Domain.objects.get_or_create(name="com")
- d1, _ = Domain.objects.get_or_create(name="mozilla.com")
- soa, _ = SOA.objects.get_or_create(
- primary="fo.bar", contact="foo.bar.com",
- description="foo bar")
- self.s = soa
- d1.soa = soa
- d1.save()
+ self.system.save()
+
+ d1 = create_fake_zone("oregonstate.com", suffix="")
+ soa = d1.soa
v, _ = Vlan.objects.get_or_create(name="private", number=3)
s, _ = Site.objects.get_or_create(name="phx1")
s1, _ = Site.objects.get_or_create(name="corp", parent=s)
- d, _ = Domain.objects.get_or_create(name="phx1.mozilla.com")
+ d, _ = Domain.objects.get_or_create(name="phx1.oregonstate.com")
d.soa = soa
d.save()
- d1, _ = Domain.objects.get_or_create(name="corp.phx1.mozilla.com")
+ d1, _ = Domain.objects.get_or_create(name="corp.phx1.oregonstate.com")
d1.soa = soa
d1.save()
d2, _ = Domain.objects.get_or_create(
- name="private.corp.phx1.mozilla.com")
+ name="private.corp.phx1.oregonstate.com")
d2.soa = soa
d2.save()
@@ -62,7 +59,7 @@ def test1_free_ip_count(self):
count = calc_free_ips_str("15.0.0.200", "15.0.0.204")
self.assertEqual(count, 4)
intr, errors = create_ipv4_intr_from_range("foo",
- "private.corp.phx1.mozilla.com", self.system,
+ "private.corp.phx1.oregonstate.com", self.system,
"11:22:33:44:55:66", "15.0.0.200", "15.0.0.204")
intr.save()
self.assertEqual(errors, None)
@@ -72,7 +69,7 @@ def test1_free_ip_count(self):
self.assertEqual(count, 3)
intr, errors = create_ipv4_intr_from_range("foo",
- "private.corp.phx1.mozilla.com", self.system,
+ "private.corp.phx1.oregonstate.com", self.system,
"11:22:33:44:55:66", "15.0.0.200", "15.0.0.204")
intr.save()
self.assertEqual(errors, None)
@@ -82,7 +79,7 @@ def test1_free_ip_count(self):
self.assertEqual(count, 2)
intr, errors = create_ipv4_intr_from_range("foo",
- "private.corp.phx1.mozilla.com", self.system,
+ "private.corp.phx1.oregonstate.com", self.system,
"11:22:33:44:55:66", "15.0.0.200", "15.0.0.204")
intr.save()
self.assertEqual(errors, None)
@@ -92,7 +89,7 @@ def test1_free_ip_count(self):
self.assertEqual(count, 1)
intr, errors = create_ipv4_intr_from_range("foo",
- "private.corp.phx1.mozilla.com", self.system,
+ "private.corp.phx1.oregonstate.com", self.system,
"11:22:33:44:55:66", "15.0.0.200", "15.0.0.204")
intr.save()
self.assertEqual(errors, None)
Oops, something went wrong.

0 comments on commit c1dbb66

Please sign in to comment.