From d5ffc7fca3d6f26c67b59850d5e485d74b77552e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Martin=20Sl=C3=A5en?= Date: Mon, 4 Apr 2011 01:25:16 +0200 Subject: [PATCH] changes to reflect dhcp configuration exports --- mdb/admin.py | 12 +++++++++++- mdb/models.py | 46 ++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/mdb/admin.py b/mdb/admin.py index a98a07e..33eb74e 100644 --- a/mdb/admin.py +++ b/mdb/admin.py @@ -34,9 +34,17 @@ class Ip4AddressInline(admin.TabularInline): extra = 0 readonly_fields = ['address'] +class DhcpOptionInline(admin.TabularInline): + model = DhcpOption + extra = 0 + +class DhcpCustomFieldInline(admin.TabularInline): + model = DhcpCustomField + extra = 0 + class SubnetAdmin(admin.ModelAdmin): list_display = ['name', 'network', 'netmask', 'num_addresses', 'broadcast_address', 'first_address', 'last_address'] - inlines = [Ip4AddressInline] + inlines = [DhcpOptionInline,DhcpCustomFieldInline,Ip4AddressInline] class DomainSrvRecordInline(admin.TabularInline): model = DomainSrvRecord @@ -66,3 +74,5 @@ admin.site.register(MailExchange) admin.site.register(OperatingSystem) admin.site.register(OsArchitecture) admin.site.register(HostType, HostTypeAdmin) +admin.site.register(DhcpConfig) +admin.site.register(DhcpOption) diff --git a/mdb/models.py b/mdb/models.py index 2c6d49c..369f926 100644 --- a/mdb/models.py +++ b/mdb/models.py @@ -133,6 +133,18 @@ class DomainCnameRecord(models.Model): def __unicode__(self): return self.name + " IN CNAME " + self.target +class DhcpConfig(models.Model): + serial = models.IntegerField() + name = models.CharField(max_length=255) + authoritative = models.BooleanField() + ddns_update_style = models.CharField(max_length=63) + default_lease_time = models.IntegerField(default=600) + max_lease_time = models.IntegerField(default=7200) + log_facility = models.CharField(max_length=255) + + def __unicode__(self): + return self.name + class Ip4Subnet(models.Model): name = models.CharField(max_length=256) netmask = models.IPAddressField() @@ -149,6 +161,11 @@ class Ip4Subnet(models.Model): domain_minimum_ttl = models.IntegerField(default=86400) domain_admin = models.EmailField() domain_filename = models.CharField(max_length=256) + + dhcp_dynamic = models.BooleanField(default=False) + dhcp_dynamic_start = models.IPAddressField(null=True, blank=True) + dhcp_dynamic_end = models.IPAddressField(null=True, blank=True) + dhcp_config = models.ForeignKey(DhcpConfig) def __unicode__(self): return self.network + " (" + self.name + ")" @@ -215,6 +232,18 @@ class Ip4Subnet(models.Model): return content +class DhcpOption(models.Model): + key = models.CharField(max_length=255) + value = models.CharField(max_length=255) + ip4subnet = models.ForeignKey(Ip4Subnet) + + def __unicode__(self): + return self.key + " " + self.value + +class DhcpCustomField(models.Model): + value = models.CharField(max_length=255) + ip4subnet = models.ForeignKey(Ip4Subnet) + class Ip4Address(models.Model): subnet = models.ForeignKey(Ip4Subnet) address = models.IPAddressField() @@ -328,11 +357,17 @@ def delete_ips_for_subnet(sender, instance, **kwargs): @receiver(pre_save, sender=Ip4Subnet) def set_domain_name_for_subnet(sender, instance, **kwargs): # we assume that the reverse domain_name does not change - if len(instance.domain_name) > 0: - return - ipspl = instance.network.split(".") - rev = "%s.%s.%s" % (ipspl[2], ipspl[1], ipspl[0]) - instance.domain_name = "%s.in-addr.arpa" % rev + if len(instance.domain_name) == 0: + ipspl = instance.network.split(".") + rev = "%s.%s.%s" % (ipspl[2], ipspl[1], ipspl[0]) + instance.domain_name = "%s.in-addr.arpa" % rev + + # lets update the serial of the dhcp config + # when the subnet is changed + if instance.dhcp_config: + instance.dhcp_config.serial = instance.dhcp_config.serial + 1 + instance.dhcp_config.save() + @receiver(post_save, sender=Interface) def update_domain_serial_when_change_to_interface(sender, instance, created, **kwargs): @@ -358,4 +393,3 @@ def update_domain_serial_when_interface_deleted(sender, instance, **kwargs): subnet.domain_serial = subnet.domain_serial + 1 subnet.save() -