-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #201 from innogames/powerdns_managed_models
Add Domain and Record models
- Loading branch information
Showing
3 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,55 @@ | ||
from django.db import models | ||
|
||
# Create your models here. | ||
|
||
class Domain(models.Model): | ||
"""PowerDNS Domain | ||
Model to access domain in the PowerDNS db. | ||
See https://doc.powerdns.com/authoritative/backends/generic-postgresql.html#default-schema | ||
""" | ||
TYPES = [ | ||
('MASTER', 'MASTER'), | ||
('SLAVE', 'SLAVE'), | ||
('NATIVE', 'NATIVE'), | ||
] | ||
|
||
id = models.IntegerField(primary_key=True) | ||
name = models.CharField(max_length=255, null=False) | ||
master = models.CharField(max_length=128, default=None) | ||
type = models.CharField(max_length=6, null=False, choices=TYPES) | ||
|
||
class Meta: | ||
managed = False | ||
db_table = 'domains' | ||
|
||
|
||
class Record(models.Model): | ||
"""PowerDNS Record | ||
Model to access records in the PowerDNS db. | ||
See https://doc.powerdns.com/authoritative/backends/generic-postgresql.html#default-schema | ||
""" | ||
TYPES = [ | ||
('A', 'A'), | ||
('AAAA', 'AAAA'), | ||
('CNAME', 'CNAME'), | ||
('TXT', 'TXT'), | ||
('SSHFP', 'SSHFP'), | ||
('SOA', 'SOA'), | ||
('MX', 'MX'), | ||
('PTR', 'PTR'), | ||
('NS', 'NS'), | ||
] | ||
|
||
id = models.BigIntegerField(primary_key=True) | ||
domain_id = models.ForeignKey('Domain', on_delete=models.CASCADE) | ||
name = models.CharField(max_length=255, default=None) | ||
type = models.CharField(max_length=10, default=None, choices=TYPES) | ||
content = models.CharField(max_length=65535, default=None) | ||
ttl = models.IntegerField() | ||
|
||
class Meta: | ||
managed = False | ||
db_table = 'records' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class PowerDNSRouter: | ||
""" | ||
A router to control all database operations on models in the | ||
auth and contenttypes applications. | ||
""" | ||
route_app_labels = {'powerdns'} | ||
|
||
def db_for_read(self, model, **hints): | ||
""" | ||
Attempts to read powerdns models go to the pdns db. | ||
""" | ||
if model._meta.app_label in self.route_app_labels: | ||
return 'pdns' | ||
return None | ||
|
||
def db_for_write(self, model, **hints): | ||
""" | ||
Attempts to write powerdns models go to the pdns db. | ||
""" | ||
if model._meta.app_label in self.route_app_labels: | ||
return 'pdns' | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters