Compare commits
14
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9dc195fd46 | ||
|
|
d5d63b4dca | ||
|
|
47b69a9ea7 | ||
|
|
7de3e4008c | ||
|
|
54180d6bb5 | ||
|
|
49183fb646 | ||
|
|
cf6b1ad13d | ||
|
|
51b595a11d | ||
|
|
093fae0fea | ||
|
|
b79fdafaa1 | ||
|
|
8fe8a1b311 | ||
|
|
935e38d224 | ||
|
|
2fd8001ba5 | ||
|
|
ca76aaa80b |
No files matched your search
@@ -0,0 +1,20 @@
|
||||
[[source]]
|
||||
url = "https://pypi.org/simple"
|
||||
verify_ssl = true
|
||||
name = "pypi"
|
||||
|
||||
[packages]
|
||||
django = "==2.0.8"
|
||||
django-auth-ldap = "==1.7.0"
|
||||
django-extensions = "==2.1.0"
|
||||
djangorestframework = "==3.8.2"
|
||||
gunicorn = "==19.9.0"
|
||||
ipaddress = "==1.0.22"
|
||||
mysqlclient = "==1.3.13"
|
||||
raven = "==6.9.0"
|
||||
django-suit = "*"
|
||||
|
||||
[dev-packages]
|
||||
|
||||
[requires]
|
||||
python_version = "3.6"
|
||||
Generated
+147
@@ -0,0 +1,147 @@
|
||||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "2280ffc42c9d702c0cfeba59fdb86215b1a8cad743ae3dc49fd6790aa00cf885"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {
|
||||
"python_version": "3.6"
|
||||
},
|
||||
"sources": [
|
||||
{
|
||||
"name": "pypi",
|
||||
"url": "https://pypi.org/simple",
|
||||
"verify_ssl": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"default": {
|
||||
"django": {
|
||||
"hashes": [
|
||||
"sha256:0c5b65847d00845ee404bbc0b4a85686f15eb3001ffddda3db4e9baa265bf136",
|
||||
"sha256:68aeea369a8130259354b6ba1fa9babe0c5ee6bced505dea4afcd00f765ae38b"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==2.0.8"
|
||||
},
|
||||
"django-auth-ldap": {
|
||||
"hashes": [
|
||||
"sha256:72848b3b036d299114be3c6ef38b12f83f6cf1cf1696c5f92e06fe45a1b8e27b",
|
||||
"sha256:f96398ce957bb8aaaee2e9d93e3eaf9955ab95a6d342303b5519350eb834f5d1"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==1.7.0"
|
||||
},
|
||||
"django-extensions": {
|
||||
"hashes": [
|
||||
"sha256:c3c8524056ab1174c6fc769b0599e60f7e7797ce34f38db2effc48885a0a982c",
|
||||
"sha256:e279344c6d825adb27694755aa924702d3cc401f8fad5ad9ef2d577948778a5f"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==2.1.0"
|
||||
},
|
||||
"django-suit": {
|
||||
"hashes": [
|
||||
"sha256:19ed865a478dfca81cb5f50a70317700dd70da92c465093251d0e14330a2b92b"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==0.2.26"
|
||||
},
|
||||
"djangorestframework": {
|
||||
"hashes": [
|
||||
"sha256:b6714c3e4b0f8d524f193c91ecf5f5450092c2145439ac2769711f7eba89a9d9",
|
||||
"sha256:c375e4f95a3a64fccac412e36fb42ba36881e52313ec021ef410b40f67cddca4"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==3.8.2"
|
||||
},
|
||||
"gunicorn": {
|
||||
"hashes": [
|
||||
"sha256:aa8e0b40b4157b36a5df5e599f45c9c76d6af43845ba3b3b0efe2c70473c2471",
|
||||
"sha256:fa2662097c66f920f53f70621c6c58ca4a3c4d3434205e608e121b5b3b71f4f3"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==19.9.0"
|
||||
},
|
||||
"ipaddress": {
|
||||
"hashes": [
|
||||
"sha256:64b28eec5e78e7510698f6d4da08800a5c575caa4a286c93d651c5d3ff7b6794",
|
||||
"sha256:b146c751ea45cad6188dd6cf2d9b757f6f4f8d6ffb96a023e6f2e26eea02a72c"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==1.0.22"
|
||||
},
|
||||
"mysqlclient": {
|
||||
"hashes": [
|
||||
"sha256:ff8ee1be84215e6c30a746b728c41eb0701a46ca76e343af445b35ce6250644f"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==1.3.13"
|
||||
},
|
||||
"pyasn1": {
|
||||
"hashes": [
|
||||
"sha256:0ad0fe0593dde1e599cac0bf65bb1a4ec663032f0bc68ee44850db4251e8c501",
|
||||
"sha256:13794d835643ee970b2c059dbfe4eb5d751e16c693c8baee61c526abd209e5c7",
|
||||
"sha256:49a8ed515f26913049113820b462f698e6ed26df62c389dafb6fa3685ddca8de",
|
||||
"sha256:74ac8521a0480f228549be20bea555ae35678f0e754c2fbc6f1576b0959bec43",
|
||||
"sha256:89399ca8ecd4524f974e926d4ef9e7a787903e01f0a9cdff3131ad1361792fe5",
|
||||
"sha256:8f291e0338d519a1a0d07f0b9d03c9265f6be26eb32fdd21af6d3259d14ea49c",
|
||||
"sha256:b9d3abc5031e61927c82d4d96c1cec1e55676c1a991623cfed28faea73cdd7ca",
|
||||
"sha256:d3bbd726c1a760d4ca596a4d450c380b81737612fe0182f5bb3caebc17461fd9",
|
||||
"sha256:dea873d6c907c1cf1341fd88742a61efce33227d7743cb37564ab7d7e77dd9fd",
|
||||
"sha256:ded5eea5cb88bc1ce9aa074b5a3092f95ce4741887e317e9b49c7ece75d7ea0e",
|
||||
"sha256:e8b69ea2200d42201cbedd486eedb8980f320d4534f83ce2fb468e96aa5545d0",
|
||||
"sha256:edad117649643230493aeb4955456ce19ab4b12e94489dde6f7094cdb5a3c87e",
|
||||
"sha256:f58f2a3d12fd754aa123e9fa74fb7345333000a035f3921dbdaa08597aa53137"
|
||||
],
|
||||
"version": "==0.4.4"
|
||||
},
|
||||
"pyasn1-modules": {
|
||||
"hashes": [
|
||||
"sha256:077250b34432520430bc1c80dcbda4e354090785567c33ded35faa6df8d24753",
|
||||
"sha256:0da2f947e8ad2697e86fe5fd0e55a4093a2fd79d839c9e19c34e28097db7002c",
|
||||
"sha256:35ff894a0b5df8e28b700126b2869c7dcfb2b2db5bc82e5d5e82547069241553",
|
||||
"sha256:44688b94841349648b1e1a5a7a3d96e6596d5d4f21d0b59a82307e153c4dc74b",
|
||||
"sha256:833716dde880a7f2f2ccdeea9a096842626981ff2a477d8b318c0906367ac11b",
|
||||
"sha256:a0cf3e1842e7c60fde97cb22d275eb6f9524f5c5250489e292529de841417547",
|
||||
"sha256:a38a8811ea784c0136abfdba73963876328f66172db21a05a82f9515909bfb4e",
|
||||
"sha256:a728bb9502d1fdc104c66f24a176b6a70a32e89d1d8a5b55c959233ed51c67be",
|
||||
"sha256:c30a098435ea0989c37005a971843e9d3966c7f6d056ddbf052e5061c06e3291",
|
||||
"sha256:c355a45b32c5bc1d9893eceb704b0cfcd1126f91b5a7b9ee64c1c05383283381",
|
||||
"sha256:e64679de1940f41ead5170fce364d54e7b9e2e862f064727b6bcb5cee753b7a2",
|
||||
"sha256:ed71d20225c356881c29f0b1d7a0d6521563a389d9478e8f95d798cc5ba07b88",
|
||||
"sha256:f183f0940b9f5ed2ad9d04c80cab2451440fa9af4fc959d85113fadd2e777962"
|
||||
],
|
||||
"version": "==0.2.2"
|
||||
},
|
||||
"python-ldap": {
|
||||
"hashes": [
|
||||
"sha256:41975e79406502c092732c57ef0c2c2eb318d91e8e765f81f5d4ab6c1db727c5"
|
||||
],
|
||||
"version": "==3.1.0"
|
||||
},
|
||||
"pytz": {
|
||||
"hashes": [
|
||||
"sha256:a061aa0a9e06881eb8b3b2b43f05b9439d6583c206d0a6c340ff72a7b6669053",
|
||||
"sha256:ffb9ef1de172603304d9d2819af6f5ece76f2e85ec10692a524dd876e72bf277"
|
||||
],
|
||||
"version": "==2018.5"
|
||||
},
|
||||
"raven": {
|
||||
"hashes": [
|
||||
"sha256:3fd787d19ebb49919268f06f19310e8112d619ef364f7989246fc8753d469888",
|
||||
"sha256:95f44f3ea2c1b176d5450df4becdb96c15bf2632888f9ab193e9dd22300ce46a"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==6.9.0"
|
||||
},
|
||||
"six": {
|
||||
"hashes": [
|
||||
"sha256:70e8a77beed4562e7f14fe23a786b54f6296e34344c23bc42f07b15018ff98e9",
|
||||
"sha256:832dc0e10feb1aa2c68dcc57dbb658f1c7e65b9b61af69048abc87a2db00a0eb"
|
||||
],
|
||||
"version": "==1.11.0"
|
||||
}
|
||||
},
|
||||
"develop": {}
|
||||
}
|
||||
+9
-16
@@ -48,29 +48,26 @@ class HostAdmin(admin.ModelAdmin):
|
||||
)
|
||||
actions = ['set_installable']
|
||||
|
||||
@staticmethod
|
||||
def mac_addresses(host):
|
||||
def mac_addresses(self, host):
|
||||
addresses = host.interface_set.filter(macaddr__isnull=False).values_list('macaddr', flat=True)
|
||||
return ", ".join(addresses)
|
||||
|
||||
@staticmethod
|
||||
def ip_addresses(host):
|
||||
def ip_addresses(self, host):
|
||||
addresses = host.interface_set.filter(ip4address__isnull=False).values_list('ip4address__address', flat=True)
|
||||
return ", ".join(addresses)
|
||||
|
||||
@staticmethod
|
||||
def in_domain(host):
|
||||
def in_domain(self, host):
|
||||
domains = host.interface_set.values_list('domain__domain_name', flat=True)
|
||||
return ",".join(domains)
|
||||
|
||||
in_domain.short_description = "in domains"
|
||||
|
||||
@staticmethod
|
||||
def ipv6_enabled(host):
|
||||
def ipv6_enabled(self, host):
|
||||
ipv6_ifs = host.interface_set.annotate(num_ipv6=Count('ip6address')).filter(num_ipv6__gt=0)
|
||||
return ipv6_ifs.exists()
|
||||
|
||||
ipv6_enabled.boolean = True
|
||||
# FIXME: custom filter to sort custom field
|
||||
|
||||
@staticmethod
|
||||
def _get_host_warning_message(host, ifs):
|
||||
@@ -121,23 +118,19 @@ class SubnetAdmin(admin.ModelAdmin):
|
||||
list_display = ['name', 'network', 'netmask', 'num_addresses', 'broadcast_address', 'first_address', 'last_address']
|
||||
inlines = [DhcpOptionInline, DhcpCustomFieldInline, Ip4AddressInline]
|
||||
|
||||
@staticmethod
|
||||
def num_addresses(ip4subnet):
|
||||
def num_addresses(self, ip4subnet):
|
||||
subnet = ipaddress.IPv4Network(ip4subnet.network + "/" + ip4subnet.netmask)
|
||||
return subnet.num_addresses
|
||||
|
||||
@staticmethod
|
||||
def broadcast_address(ip4subnet):
|
||||
def broadcast_address(self, ip4subnet):
|
||||
subnet = ipaddress.IPv4Network(ip4subnet.network + "/" + ip4subnet.netmask)
|
||||
return subnet.broadcast_address
|
||||
|
||||
@staticmethod
|
||||
def first_address(ip4subnet):
|
||||
def first_address(self, ip4subnet):
|
||||
subnet = ipaddress.IPv4Network(ip4subnet.network + "/" + ip4subnet.netmask)
|
||||
return next(subnet.hosts())
|
||||
|
||||
@staticmethod
|
||||
def last_address(ip4subnet):
|
||||
def last_address(self, ip4subnet):
|
||||
subnet = ipaddress.IPv4Network(ip4subnet.network + "/" + ip4subnet.netmask)
|
||||
return list(subnet.hosts())[-1]
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
from __future__ import unicode_literals
|
||||
from rest_framework import serializers
|
||||
from rest_framework.exceptions import ValidationError
|
||||
|
||||
@@ -34,7 +33,9 @@ class HostPXEValidateSerializer(serializers.Serializer):
|
||||
raise ValidationError('Host \'{}\' has no pxe_key.'.format(attrs['certname']))
|
||||
|
||||
if host.pxe_key != attrs['pxe_key']:
|
||||
raise ValidationError('Supplied pxe_key does not match host \'{}\'.'.format(attrs['certname']))
|
||||
raise ValidationError('Supplied pxe_key \'{}\' does not match host \'{}\'.'.format(
|
||||
attrs['pxe_key'],
|
||||
attrs['certname']))
|
||||
|
||||
self.host = host
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from django import forms
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.forms import ModelChoiceField
|
||||
|
||||
from mdb.models import Interface, Ip4Address
|
||||
@@ -15,6 +16,15 @@ class Ip4ModelChoiceField(ModelChoiceField):
|
||||
class InterfaceForm(forms.ModelForm):
|
||||
model = Interface
|
||||
|
||||
def clean(self):
|
||||
macaddr = self.cleaned_data['macaddr']
|
||||
ip4address = self.cleaned_data['ip4address']
|
||||
|
||||
for interface in Interface.objects.filter(macaddr=macaddr):
|
||||
subnet = interface.ip4address.subnet
|
||||
if subnet == ip4address.subnet and interface != self.instance:
|
||||
raise ValidationError('Macaddr already in this subnet')
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(InterfaceForm, self).__init__(*args, **kwargs)
|
||||
|
||||
|
||||
@@ -1,15 +1,9 @@
|
||||
from __future__ import with_statement
|
||||
|
||||
import os
|
||||
import sys
|
||||
from difflib import context_diff
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.core.mail import mail_admins
|
||||
from optparse import make_option
|
||||
try:
|
||||
from subprocess import getstatusoutput
|
||||
except ImportError:
|
||||
from commands import getstatusoutput
|
||||
from subprocess import getstatusoutput
|
||||
|
||||
from mdb.models import DhcpConfig
|
||||
|
||||
@@ -18,29 +12,28 @@ class Command(BaseCommand):
|
||||
args = '--output <path> [--force] [--restart]'
|
||||
help = 'Generates the DHCP configuration'
|
||||
|
||||
option_list = BaseCommand.option_list + (
|
||||
make_option('--output',
|
||||
action='store',
|
||||
dest='output',
|
||||
default=None,
|
||||
help='Path to dhcpd.conf, defaults to stdout'),
|
||||
make_option('--force',
|
||||
action='store_true',
|
||||
dest='force',
|
||||
default=False,
|
||||
help='Write configuration even if serial is unchanged.'),
|
||||
make_option('--restart',
|
||||
action='store_true',
|
||||
dest='restart',
|
||||
default=False,
|
||||
help='Restart dhcp3-server if serial is changed'),
|
||||
)
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('--output',
|
||||
action='store',
|
||||
dest='output',
|
||||
default=None,
|
||||
help='Path to dhcpd.conf, defaults to stdout'),
|
||||
parser.add_argument('--force',
|
||||
action='store_true',
|
||||
dest='force',
|
||||
default=False,
|
||||
help='Write configuration even if serial is unchanged.'),
|
||||
parser.add_argument('--restart',
|
||||
action='store_true',
|
||||
dest='restart',
|
||||
default=False,
|
||||
help='Restart dhcp3-server if serial is changed'),
|
||||
|
||||
def handle(self, *args, **options):
|
||||
output = options['output'] if options['output'] else sys.stdout
|
||||
force = options['force']
|
||||
restart = options['restart']
|
||||
restart_command = "service isc-dhcp-server restart"
|
||||
restart_command = "/usr/sbin/service isc-dhcp-server restart"
|
||||
|
||||
config = DhcpConfig.objects.filter(name="default").get()
|
||||
|
||||
@@ -67,13 +60,7 @@ class Command(BaseCommand):
|
||||
with open(output, 'w') as f:
|
||||
f.write(new)
|
||||
|
||||
# calculate diff
|
||||
diff = "\n".join(context_diff(
|
||||
a=old.splitlines(),
|
||||
b=new.splitlines(),
|
||||
fromfile=config.active_serial,
|
||||
tofile=config.serial,
|
||||
lineterm=''))
|
||||
diff = self.calculate_diff(config, new, old)
|
||||
|
||||
print(diff)
|
||||
|
||||
@@ -104,3 +91,11 @@ class Command(BaseCommand):
|
||||
message=message,
|
||||
html_message='<pre>%s</pre>' % message)
|
||||
sys.exit(0)
|
||||
|
||||
def calculate_diff(self, config, new, old):
|
||||
return "\n".join(context_diff(
|
||||
a=old.splitlines(),
|
||||
b=new.splitlines(),
|
||||
fromfile=str(config.active_serial),
|
||||
tofile=str(config.serial),
|
||||
lineterm=''))
|
||||
@@ -1,16 +1,10 @@
|
||||
from __future__ import with_statement
|
||||
|
||||
import os
|
||||
import sys
|
||||
from itertools import chain
|
||||
from difflib import context_diff
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.core.mail import mail_admins
|
||||
from optparse import make_option
|
||||
try:
|
||||
from subprocess import getstatusoutput
|
||||
except ImportError:
|
||||
from commands import getstatusoutput
|
||||
from subprocess import getstatusoutput
|
||||
|
||||
from mdb.models import Domain, Ip4Subnet, Ip6Subnet
|
||||
|
||||
@@ -19,50 +13,43 @@ class Command(BaseCommand):
|
||||
args = '[--force] [--debug]'
|
||||
help = 'Generates the bind configuration'
|
||||
|
||||
option_list = BaseCommand.option_list + (
|
||||
make_option('--debug',
|
||||
action='store_true',
|
||||
dest='debug',
|
||||
default=False,
|
||||
help='Debug mode. Writes to /tmp and does not reload.'),
|
||||
make_option('--force',
|
||||
action='store_true',
|
||||
dest='force',
|
||||
default=False,
|
||||
help='Write zone files even if serial is unchanged.'),
|
||||
)
|
||||
|
||||
bind_bin = "/etc/init.d/bind9"
|
||||
reload_command = "%s reload" % bind_bin
|
||||
rndc_bin = "/usr/sbin/rndc"
|
||||
reload_command = "%s reload" % rndc_bin
|
||||
freeze_command = "%s freeze" % rndc_bin
|
||||
thaw_command = "%s thaw" % rndc_bin
|
||||
commands_in_order = [freeze_command, reload_command, thaw_command]
|
||||
checkzone_bin = "/usr/sbin/named-checkzone"
|
||||
checkzone_dir = "/tmp/mdb-checkzone"
|
||||
debug = False
|
||||
force = False
|
||||
debug_dir = '/tmp/mdb-debug'
|
||||
changes = {}
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('--debug',
|
||||
action='store_true',
|
||||
dest='debug',
|
||||
default=False,
|
||||
help='Debug mode. Writes to /tmp and does not reload.')
|
||||
parser.add_argument('--force',
|
||||
action='store_true',
|
||||
dest='force',
|
||||
default=False,
|
||||
help='Write zone files even if serial is unchanged.')
|
||||
|
||||
def handle(self, *args, **options):
|
||||
self.debug = debug = options['debug']
|
||||
force = options['force']
|
||||
self.debug = options['debug']
|
||||
self.force = options['force']
|
||||
|
||||
# do the binaries exist?
|
||||
for f in (self.checkzone_bin, self.bind_bin):
|
||||
if not os.path.isfile(f) and not debug:
|
||||
print("ERROR: no such file %s, exiting..." % f)
|
||||
if not debug:
|
||||
sys.exit(1)
|
||||
self.validate_binaries_exist()
|
||||
|
||||
# create directories if needed
|
||||
os.path.isdir(self.checkzone_dir) or os.mkdir(self.checkzone_dir)
|
||||
debug and (os.path.isdir(self.debug_dir) or os.mkdir(self.debug_dir))
|
||||
self.debug and (os.path.isdir(self.debug_dir) or os.mkdir(self.debug_dir))
|
||||
|
||||
# update zones with new serials
|
||||
for zone in chain(Domain.objects.all(),
|
||||
Ip4Subnet.objects.all(),
|
||||
Ip6Subnet.objects.all()):
|
||||
if zone.domain_serial == zone.domain_active_serial and not force:
|
||||
continue
|
||||
if self.update_zone(zone):
|
||||
self.changes[zone.domain_name]['success'] = True
|
||||
self.update_zone_serials()
|
||||
|
||||
# join errors, diffs and zone names
|
||||
errors = "\n\n\n".join(
|
||||
@@ -72,35 +59,52 @@ class Command(BaseCommand):
|
||||
zones = ", ".join(self.changes.keys())
|
||||
|
||||
# reload and send email with changes
|
||||
if self.changes and not debug:
|
||||
sys.stdout.write("reloading bind... ")
|
||||
status, output = getstatusoutput(self.reload_command)
|
||||
if status != 0:
|
||||
sys.stdout.write("fail\n")
|
||||
message = (
|
||||
"Failed to reload bind, please inspect...\n\n" +
|
||||
"%s@%s# %s" % (
|
||||
os.getlogin(), os.uname()[1], self.reload_command) +
|
||||
"\n%s\n\n\n%s\n\n\n%s" % (output, errors, diffs))
|
||||
mail_admins(
|
||||
subject="FAIL: bind (%s changed: %s)" % (len(self.changes), zones),
|
||||
message=message,
|
||||
html_message='<pre>%s</pre>' % message)
|
||||
sys.exit(1)
|
||||
else:
|
||||
sys.stdout.write("ok\n")
|
||||
message = (
|
||||
"Successfully updated bind zone files\n\n" +
|
||||
"%s\n\n%s" % (errors, diffs))
|
||||
mail_admins(
|
||||
subject="Success: bind (%s changed: %s)" % (len(self.changes), zones),
|
||||
message=message,
|
||||
html_message='<pre>%s</pre>' % message)
|
||||
sys.exit(0)
|
||||
if self.changes and not self.debug:
|
||||
sys.stdout.write("reloading zones... ")
|
||||
for command in self.commands_in_order:
|
||||
status, output = getstatusoutput(command)
|
||||
if status != 0:
|
||||
sys.stdout.write("fail\n")
|
||||
message = (
|
||||
"Failed to reload zones, please inspect...\n\n" +
|
||||
"%s@%s$ %s" % (
|
||||
os.getlogin(), os.uname()[1], command) +
|
||||
"\n%s\n\n\n%s\n\n\n%s" % (output, errors, diffs))
|
||||
mail_admins(
|
||||
subject="FAIL: bind (%s changed: %s)" % (len(self.changes), zones),
|
||||
message=message,
|
||||
html_message='<pre>%s</pre>' % message)
|
||||
sys.exit(1)
|
||||
|
||||
sys.stdout.write("ok\n")
|
||||
message = (
|
||||
"Successfully updated bind zone files\n\n" +
|
||||
"%s\n\n%s" % (errors, diffs))
|
||||
mail_admins(
|
||||
subject="Success: bind (%s changed: %s)" % (len(self.changes), zones),
|
||||
message=message,
|
||||
html_message='<pre>%s</pre>' % message)
|
||||
sys.exit(0)
|
||||
|
||||
def update_zone_serials(self):
|
||||
for zone in chain(Domain.objects.all(),
|
||||
Ip4Subnet.objects.all(),
|
||||
Ip6Subnet.objects.all()):
|
||||
if zone.domain_serial == zone.domain_active_serial and not self.force:
|
||||
continue
|
||||
|
||||
if self.update_zone(zone):
|
||||
self.changes[zone.domain_name]['success'] = True
|
||||
|
||||
def validate_binaries_exist(self):
|
||||
for f in (self.checkzone_bin, self.rndc_bin):
|
||||
if not os.path.isfile(f) and not self.debug:
|
||||
print("ERROR: no such file %s, exiting..." % f)
|
||||
if not self.debug:
|
||||
sys.exit(1)
|
||||
|
||||
def update_zone(self, zone):
|
||||
zonetype = getattr(zone._meta, 'verbose_name', None) \
|
||||
or zone._meta.model_name
|
||||
zonetype = getattr(zone._meta, 'verbose_name', None) or zone._meta.model_name
|
||||
|
||||
self.changes[zone.domain_name] = {
|
||||
'old_serial': zone.domain_active_serial,
|
||||
@@ -126,14 +130,7 @@ class Command(BaseCommand):
|
||||
except IOError:
|
||||
old = ''
|
||||
|
||||
# calculate diff
|
||||
diff = "\n".join(context_diff(
|
||||
a=old.splitlines(),
|
||||
b=new.splitlines(),
|
||||
fromfile=str(zone.domain_active_serial) + '-' + zone.domain_name,
|
||||
tofile=str(zone.domain_serial) + '-' + zone.domain_name,
|
||||
lineterm=''))
|
||||
self.changes[zone.domain_name]['diff'] = diff
|
||||
self.changes[zone.domain_name]['diff'] = self.calculate_diff(new, old, zone)
|
||||
|
||||
# validate with zonecheck
|
||||
sys.stdout.write("\t- validating... ")
|
||||
@@ -142,6 +139,7 @@ class Command(BaseCommand):
|
||||
sys.stdout.write("fail\n")
|
||||
self.changes[zone.domain_name]['errors'] = output
|
||||
return False
|
||||
|
||||
sys.stdout.write("ok\n")
|
||||
|
||||
# write to zone file
|
||||
@@ -166,10 +164,17 @@ class Command(BaseCommand):
|
||||
self.changes[zone.domain_name]['success'] = True
|
||||
return True
|
||||
|
||||
def calculate_diff(self, new, old, zone):
|
||||
return "\n".join(context_diff(
|
||||
a=old.splitlines(),
|
||||
b=new.splitlines(),
|
||||
fromfile=str(zone.domain_active_serial) + '-' + zone.domain_name,
|
||||
tofile=str(zone.domain_serial) + '-' + zone.domain_name,
|
||||
lineterm=''))
|
||||
|
||||
def check_zone(self, zone, contents):
|
||||
zonefile = self.checkzone_dir + '/' + zone.domain_name
|
||||
with open(zonefile, 'w') as f:
|
||||
f.write(contents)
|
||||
|
||||
return getstatusoutput("%s %s %s" % (
|
||||
self.checkzone_bin, zone.domain_name, zonefile))
|
||||
return getstatusoutput("%s %s %s" % (self.checkzone_bin, zone.domain_name, zonefile))
|
||||
@@ -81,7 +81,7 @@ class Migration(migrations.Migration):
|
||||
('name', models.CharField(max_length=256)),
|
||||
('target', models.CharField(max_length=256)),
|
||||
('created_date', models.DateTimeField(auto_now_add=True)),
|
||||
('domain', models.ForeignKey(to='mdb.Domain')),
|
||||
('domain', models.ForeignKey(to='mdb.Domain', on_delete=models.CASCADE)),
|
||||
],
|
||||
options={
|
||||
},
|
||||
@@ -94,7 +94,7 @@ class Migration(migrations.Migration):
|
||||
('name', models.CharField(max_length=256)),
|
||||
('target', models.CharField(max_length=256)),
|
||||
('created_date', models.DateTimeField(auto_now_add=True)),
|
||||
('domain', models.ForeignKey(to='mdb.Domain')),
|
||||
('domain', models.ForeignKey(to='mdb.Domain', on_delete=models.CASCADE)),
|
||||
],
|
||||
options={
|
||||
},
|
||||
@@ -112,7 +112,7 @@ class Migration(migrations.Migration):
|
||||
('port', models.IntegerField()),
|
||||
('target', models.CharField(max_length=256)),
|
||||
('created_date', models.DateTimeField(auto_now_add=True)),
|
||||
('domain', models.ForeignKey(to='mdb.Domain')),
|
||||
('domain', models.ForeignKey(to='mdb.Domain', on_delete=models.CASCADE)),
|
||||
],
|
||||
options={
|
||||
},
|
||||
@@ -125,7 +125,7 @@ class Migration(migrations.Migration):
|
||||
('name', models.CharField(max_length=256)),
|
||||
('target', models.CharField(max_length=256)),
|
||||
('created_date', models.DateTimeField(auto_now_add=True)),
|
||||
('domain', models.ForeignKey(to='mdb.Domain')),
|
||||
('domain', models.ForeignKey(to='mdb.Domain', on_delete=models.CASCADE)),
|
||||
],
|
||||
options={
|
||||
},
|
||||
@@ -174,8 +174,8 @@ class Migration(migrations.Migration):
|
||||
('pxe_filename', models.CharField(max_length=64, blank=True)),
|
||||
('dhcp_client', models.BooleanField(default=False)),
|
||||
('created_date', models.DateTimeField(auto_now_add=True)),
|
||||
('domain', models.ForeignKey(to='mdb.Domain')),
|
||||
('host', models.ForeignKey(to='mdb.Host')),
|
||||
('domain', models.ForeignKey(to='mdb.Domain', on_delete=models.CASCADE)),
|
||||
('host', models.ForeignKey(to='mdb.Host', on_delete=models.CASCADE)),
|
||||
],
|
||||
options={
|
||||
},
|
||||
@@ -217,7 +217,7 @@ class Migration(migrations.Migration):
|
||||
('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(to='mdb.DhcpConfig')),
|
||||
('dhcp_config', models.ForeignKey(to='mdb.DhcpConfig', on_delete=models.CASCADE)),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'IPv4 subnet',
|
||||
@@ -229,7 +229,7 @@ class Migration(migrations.Migration):
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||
('address', models.CharField(max_length=64)),
|
||||
('interface', models.ForeignKey(to='mdb.Interface')),
|
||||
('interface', models.ForeignKey(to='mdb.Interface', on_delete=models.CASCADE)),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'IPv6 address',
|
||||
@@ -309,7 +309,7 @@ class Migration(migrations.Migration):
|
||||
migrations.AddField(
|
||||
model_name='operatingsystem',
|
||||
name='architecture',
|
||||
field=models.ForeignKey(to='mdb.OsArchitecture'),
|
||||
field=models.ForeignKey(to='mdb.OsArchitecture', on_delete=models.CASCADE),
|
||||
preserve_default=True,
|
||||
),
|
||||
migrations.AddField(
|
||||
@@ -321,7 +321,7 @@ class Migration(migrations.Migration):
|
||||
migrations.AddField(
|
||||
model_name='ip6address',
|
||||
name='subnet',
|
||||
field=models.ForeignKey(to='mdb.Ip6Subnet'),
|
||||
field=models.ForeignKey(to='mdb.Ip6Subnet', on_delete=models.CASCADE),
|
||||
preserve_default=True,
|
||||
),
|
||||
migrations.AddField(
|
||||
@@ -333,25 +333,25 @@ class Migration(migrations.Migration):
|
||||
migrations.AddField(
|
||||
model_name='ip4address',
|
||||
name='subnet',
|
||||
field=models.ForeignKey(to='mdb.Ip4Subnet'),
|
||||
field=models.ForeignKey(to='mdb.Ip4Subnet', on_delete=models.CASCADE),
|
||||
preserve_default=True,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='interface',
|
||||
name='ip4address',
|
||||
field=models.ForeignKey(null=True, blank=True, to='mdb.Ip4Address', unique=True),
|
||||
field=models.ForeignKey(null=True, blank=True, to='mdb.Ip4Address', unique=True, on_delete=models.SET_NULL),
|
||||
preserve_default=True,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='host',
|
||||
name='host_type',
|
||||
field=models.ForeignKey(to='mdb.HostType'),
|
||||
field=models.ForeignKey(to='mdb.HostType', on_delete=models.CASCADE),
|
||||
preserve_default=True,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='host',
|
||||
name='operating_system',
|
||||
field=models.ForeignKey(to='mdb.OperatingSystem'),
|
||||
field=models.ForeignKey(to='mdb.OperatingSystem', on_delete=models.CASCADE),
|
||||
preserve_default=True,
|
||||
),
|
||||
migrations.AddField(
|
||||
@@ -369,13 +369,13 @@ class Migration(migrations.Migration):
|
||||
migrations.AddField(
|
||||
model_name='dhcpoption',
|
||||
name='ip4subnet',
|
||||
field=models.ForeignKey(to='mdb.Ip4Subnet'),
|
||||
field=models.ForeignKey(to='mdb.Ip4Subnet', on_delete=models.CASCADE),
|
||||
preserve_default=True,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='dhcpcustomfield',
|
||||
name='ip4subnet',
|
||||
field=models.ForeignKey(to='mdb.Ip4Subnet'),
|
||||
field=models.ForeignKey(to='mdb.Ip4Subnet', on_delete=models.CASCADE),
|
||||
preserve_default=True,
|
||||
),
|
||||
]
|
||||
@@ -35,7 +35,7 @@ class Migration(migrations.Migration):
|
||||
migrations.AlterField(
|
||||
model_name='interface',
|
||||
name='ip4address',
|
||||
field=models.OneToOneField(to='mdb.Ip4Address', null=True, blank=True),
|
||||
field=models.OneToOneField(to='mdb.Ip4Address', null=True, blank=True, on_delete=models.SET_NULL),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='interface',
|
||||
|
||||
@@ -18,7 +18,7 @@ class Migration(migrations.Migration):
|
||||
('name', models.CharField(max_length=256)),
|
||||
('target', models.GenericIPAddressField(protocol='IPv6')),
|
||||
('created_date', models.DateTimeField(auto_now_add=True)),
|
||||
('domain', models.ForeignKey(to='mdb.Domain')),
|
||||
('domain', models.ForeignKey(to='mdb.Domain', on_delete=models.CASCADE)),
|
||||
],
|
||||
),
|
||||
migrations.AlterField(
|
||||
|
||||
+16
-35
@@ -1,5 +1,4 @@
|
||||
from django.db import models
|
||||
from django.utils.encoding import python_2_unicode_compatible
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from mdb.pxe import host_as_pxe_files
|
||||
|
||||
@@ -9,7 +8,6 @@ import ipaddress
|
||||
import datetime
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class Nameserver(models.Model):
|
||||
hostname = models.CharField(max_length=256)
|
||||
|
||||
@@ -17,7 +15,6 @@ class Nameserver(models.Model):
|
||||
return self.hostname
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class MailExchange(models.Model):
|
||||
priority = models.IntegerField()
|
||||
hostname = models.CharField(max_length=256)
|
||||
@@ -26,7 +23,6 @@ class MailExchange(models.Model):
|
||||
return "(" + str(self.priority) + ") " + self.hostname
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class Domain(models.Model):
|
||||
domain_name = models.CharField(max_length=256)
|
||||
domain_soa = models.CharField(max_length=256)
|
||||
@@ -124,7 +120,6 @@ class Domain(models.Model):
|
||||
return content
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class DomainSrvRecord(models.Model):
|
||||
srvce = models.CharField(max_length=64)
|
||||
prot = models.CharField(max_length=64)
|
||||
@@ -133,7 +128,7 @@ class DomainSrvRecord(models.Model):
|
||||
weight = models.IntegerField()
|
||||
port = models.IntegerField()
|
||||
target = models.CharField(max_length=256)
|
||||
domain = models.ForeignKey(Domain)
|
||||
domain = models.ForeignKey(Domain, on_delete=models.CASCADE)
|
||||
created_date = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
def as_record(self):
|
||||
@@ -152,11 +147,10 @@ class DomainSrvRecord(models.Model):
|
||||
return self.as_record()
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class DomainTxtRecord(models.Model):
|
||||
name = models.CharField(max_length=256)
|
||||
target = models.CharField(max_length=256)
|
||||
domain = models.ForeignKey(Domain)
|
||||
domain = models.ForeignKey(Domain, on_delete=models.CASCADE)
|
||||
created_date = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
def as_record(self):
|
||||
@@ -166,11 +160,10 @@ class DomainTxtRecord(models.Model):
|
||||
return self.as_record()
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class DomainCnameRecord(models.Model):
|
||||
name = models.CharField(max_length=256)
|
||||
target = models.CharField(max_length=256)
|
||||
domain = models.ForeignKey(Domain)
|
||||
domain = models.ForeignKey(Domain, on_delete=models.CASCADE)
|
||||
created_date = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
def as_record(self):
|
||||
@@ -180,11 +173,10 @@ class DomainCnameRecord(models.Model):
|
||||
return self.as_record()
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class DomainARecord(models.Model):
|
||||
name = models.CharField(max_length=256)
|
||||
target = models.GenericIPAddressField(protocol='IPv4')
|
||||
domain = models.ForeignKey(Domain)
|
||||
domain = models.ForeignKey(Domain, on_delete=models.CASCADE)
|
||||
created_date = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
def as_record(self):
|
||||
@@ -194,11 +186,10 @@ class DomainARecord(models.Model):
|
||||
return self.as_record()
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class DomainAAAARecord(models.Model):
|
||||
name = models.CharField(max_length=256)
|
||||
target = models.GenericIPAddressField(protocol='IPv6')
|
||||
domain = models.ForeignKey(Domain)
|
||||
domain = models.ForeignKey(Domain, on_delete=models.CASCADE)
|
||||
created_date = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
def as_record(self):
|
||||
@@ -208,7 +199,6 @@ class DomainAAAARecord(models.Model):
|
||||
return self.as_record()
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class DhcpConfig(models.Model):
|
||||
serial = models.IntegerField()
|
||||
active_serial = models.IntegerField()
|
||||
@@ -270,7 +260,6 @@ class DhcpConfig(models.Model):
|
||||
verbose_name = 'DHCP config'
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class Ip6Subnet(models.Model):
|
||||
name = models.CharField(max_length=255)
|
||||
network = models.CharField(max_length=255)
|
||||
@@ -340,7 +329,6 @@ class Ip6Subnet(models.Model):
|
||||
verbose_name = 'IPv6 subnet'
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class Ip4Subnet(models.Model):
|
||||
name = models.CharField(max_length=256)
|
||||
netmask = models.GenericIPAddressField(protocol='IPv4')
|
||||
@@ -362,7 +350,7 @@ class Ip4Subnet(models.Model):
|
||||
dhcp_dynamic = models.BooleanField(default=False)
|
||||
dhcp_dynamic_start = models.GenericIPAddressField(protocol='IPv4', null=True, blank=True)
|
||||
dhcp_dynamic_end = models.GenericIPAddressField(protocol='IPv4', null=True, blank=True)
|
||||
dhcp_config = models.ForeignKey(DhcpConfig)
|
||||
dhcp_config = models.ForeignKey(DhcpConfig, on_delete=models.CASCADE)
|
||||
|
||||
def __str__(self):
|
||||
return self.network + " (" + self.name + ")"
|
||||
@@ -409,11 +397,10 @@ class Ip4Subnet(models.Model):
|
||||
verbose_name = 'IPv4 subnet'
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class DhcpOption(models.Model):
|
||||
key = models.CharField(max_length=255)
|
||||
value = models.CharField(max_length=255)
|
||||
ip4subnet = models.ForeignKey(Ip4Subnet)
|
||||
ip4subnet = models.ForeignKey(Ip4Subnet, on_delete=models.CASCADE)
|
||||
|
||||
def __str__(self):
|
||||
return self.key + " " + self.value
|
||||
@@ -424,15 +411,14 @@ class DhcpOption(models.Model):
|
||||
|
||||
class DhcpCustomField(models.Model):
|
||||
value = models.CharField(max_length=255)
|
||||
ip4subnet = models.ForeignKey(Ip4Subnet)
|
||||
ip4subnet = models.ForeignKey(Ip4Subnet, on_delete=models.CASCADE)
|
||||
|
||||
class Meta:
|
||||
verbose_name = 'DHCP custom field'
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class Ip4Address(models.Model):
|
||||
subnet = models.ForeignKey(Ip4Subnet)
|
||||
subnet = models.ForeignKey(Ip4Subnet, on_delete=models.CASCADE)
|
||||
address = models.GenericIPAddressField(protocol='IPv4')
|
||||
last_contact = models.DateTimeField(null=True, blank=True)
|
||||
ping_avg_rtt = models.FloatField(null=True, blank=True)
|
||||
@@ -445,7 +431,6 @@ class Ip4Address(models.Model):
|
||||
verbose_name_plural = 'IPv4 addresses'
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class HostType(models.Model):
|
||||
host_type = models.CharField(max_length=64)
|
||||
description = models.CharField(max_length=1024)
|
||||
@@ -460,7 +445,6 @@ class HostType(models.Model):
|
||||
ordering = ("host_type",)
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class OperatingSystem(models.Model):
|
||||
OS_ARCHITECTURES = (
|
||||
('mips', _('MIPS')),
|
||||
@@ -488,7 +472,6 @@ class OperatingSystem(models.Model):
|
||||
ordering = ("name", "version")
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class Host(models.Model):
|
||||
location = models.CharField(max_length=1024)
|
||||
brand = models.CharField(max_length=1024)
|
||||
@@ -498,9 +481,9 @@ class Host(models.Model):
|
||||
serial_number = models.CharField(max_length=256)
|
||||
description = models.CharField(max_length=1024)
|
||||
created_date = models.DateTimeField(auto_now_add=True)
|
||||
host_type = models.ForeignKey(HostType)
|
||||
host_type = models.ForeignKey(HostType, on_delete=models.CASCADE)
|
||||
virtual = models.BooleanField(default=False)
|
||||
operating_system = models.ForeignKey(OperatingSystem)
|
||||
operating_system = models.ForeignKey(OperatingSystem, on_delete=models.CASCADE)
|
||||
|
||||
request_kerberos_principal = models.BooleanField(default=False)
|
||||
kerberos_principal_created = models.BooleanField(default=False, editable=False)
|
||||
@@ -517,16 +500,15 @@ class Host(models.Model):
|
||||
return host_as_pxe_files(self)
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class Interface(models.Model):
|
||||
name = models.CharField(max_length=128)
|
||||
macaddr = models.CharField(max_length=17, validators=[validate_macaddr])
|
||||
pxe_filename = models.CharField(max_length=64, blank=True)
|
||||
dhcp_client = models.BooleanField(default=False)
|
||||
host = models.ForeignKey(Host)
|
||||
ip4address = models.OneToOneField(Ip4Address, blank=True, null=True)
|
||||
host = models.ForeignKey(Host, on_delete=models.CASCADE)
|
||||
ip4address = models.OneToOneField(Ip4Address, blank=True, null=True, on_delete=models.SET_NULL)
|
||||
created_date = models.DateTimeField(auto_now_add=True)
|
||||
domain = models.ForeignKey(Domain)
|
||||
domain = models.ForeignKey(Domain, on_delete=models.CASCADE)
|
||||
|
||||
def __str__(self):
|
||||
return "%s (%s on %s)" % (self.macaddr, self.name, self.host.hostname)
|
||||
@@ -535,11 +517,10 @@ class Interface(models.Model):
|
||||
return self.ip6address_set.exists()
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class Ip6Address(models.Model):
|
||||
subnet = models.ForeignKey(Ip6Subnet)
|
||||
subnet = models.ForeignKey(Ip6Subnet, on_delete=models.CASCADE)
|
||||
address = models.GenericIPAddressField(protocol='IPv6')
|
||||
interface = models.ForeignKey(Interface)
|
||||
interface = models.ForeignKey(Interface, on_delete=models.CASCADE)
|
||||
|
||||
def full_address(self):
|
||||
return self.subnet.network + self.address
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
from __future__ import unicode_literals
|
||||
from django.core.validators import RegexValidator
|
||||
import re
|
||||
|
||||
|
||||
+72
-21
@@ -1,5 +1,5 @@
|
||||
import os
|
||||
from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS as TCP
|
||||
import raven
|
||||
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
|
||||
|
||||
@@ -32,38 +32,40 @@ ADMIN_MEDIA_PREFIX = '/media/'
|
||||
|
||||
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
|
||||
STATIC_URL = '/static/'
|
||||
|
||||
|
||||
# Additional locations of static files
|
||||
STATICFILES_DIRS = (
|
||||
)
|
||||
|
||||
# List of finder classes that know how to find static files in
|
||||
# various locations.
|
||||
STATICFILES_FINDERS = (
|
||||
'django.contrib.staticfiles.finders.FileSystemFinder',
|
||||
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
|
||||
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
|
||||
)
|
||||
|
||||
# Make this unique, and don't share it with anybody.
|
||||
SECRET_KEY = '@4ps=ebofcpv8sb#y7gm896=l&l*u0u-pgo7bcdj%+(k+2lqnl'
|
||||
|
||||
MIDDLEWARE_CLASSES = (
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
)
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'mdbsite.urls'
|
||||
|
||||
TEMPLATE_DIRS = (
|
||||
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
|
||||
# Always use forward slashes, even on Windows.
|
||||
# Don't forget to use absolute paths, not relative paths.
|
||||
)
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.template.context_processors.debug',
|
||||
'django.template.context_processors.request',
|
||||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
INSTALLED_APPS = (
|
||||
'django.contrib.auth',
|
||||
@@ -77,15 +79,55 @@ INSTALLED_APPS = (
|
||||
'rest_framework',
|
||||
'rest_framework.authtoken',
|
||||
'django_extensions',
|
||||
|
||||
'raven.contrib.django.raven_compat',
|
||||
'mdb',
|
||||
)
|
||||
|
||||
EMAIL_SUBJECT_PREFIX = '[MDB] '
|
||||
|
||||
TEMPLATE_CONTEXT_PROCESSORS = TCP + (
|
||||
'django.core.context_processors.request', # for django-suit
|
||||
)
|
||||
# Logging
|
||||
LOGGING = {
|
||||
'version': 1,
|
||||
'disable_existing_loggers': True,
|
||||
'formatters': {
|
||||
'verbose': {
|
||||
'format': '%(levelname)s %(asctime)s %(module)s '
|
||||
'%(process)d %(thread)d %(message)s'
|
||||
},
|
||||
},
|
||||
'handlers': {
|
||||
'sentry': {
|
||||
'level': 'WARNING', # To capture more than ERROR, change to WARNING, INFO, etc.
|
||||
'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler',
|
||||
},
|
||||
'console': {
|
||||
'level': 'DEBUG',
|
||||
'class': 'logging.StreamHandler',
|
||||
'formatter': 'verbose'
|
||||
}
|
||||
},
|
||||
'loggers': {
|
||||
'root': {
|
||||
'level': 'WARNING',
|
||||
'handlers': ['sentry'],
|
||||
},
|
||||
'django.db.backends': {
|
||||
'level': 'ERROR',
|
||||
'handlers': ['console'],
|
||||
'propagate': False,
|
||||
},
|
||||
'raven': {
|
||||
'level': 'WARNING',
|
||||
'handlers': ['console'],
|
||||
'propagate': False,
|
||||
},
|
||||
'sentry.errors': {
|
||||
'level': 'DEBUG',
|
||||
'handlers': ['console'],
|
||||
'propagate': False,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
# django-suit configuration
|
||||
SUIT_CONFIG = {
|
||||
@@ -118,16 +160,25 @@ SUIT_CONFIG = {
|
||||
# misc
|
||||
'LIST_PER_PAGE': 35
|
||||
}
|
||||
|
||||
# REST Framework
|
||||
REST_FRAMEWORK = {
|
||||
'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAuthenticated',),
|
||||
'PAGINATE_BY': 10
|
||||
}
|
||||
|
||||
# PXE
|
||||
MDB_PXE_TFTP_ROOT = '/var/lib/tftpboot/pxelinux/pxelinux.cfg/'
|
||||
MDB_PXE_KERNEL = 'ubuntu/14_04/amd64/alternate/linux'
|
||||
MDB_PXE_INITRD = 'ubuntu/14_04/amd64/alternate/initrd.gz'
|
||||
MDB_PXE_PRESEED_URL = 'http://158.36.190.194/ubuntu/preseed_1404.cfg'
|
||||
|
||||
# Sentry
|
||||
RAVEN_CONFIG = {
|
||||
'dsn': os.getenv('RAVEN_DSN'),
|
||||
'release': raven.fetch_git_sha(BASE_DIR)
|
||||
}
|
||||
|
||||
try:
|
||||
from .local_settings import *
|
||||
except ImportError:
|
||||
|
||||
+4
-4
@@ -1,15 +1,15 @@
|
||||
from django.conf.urls import include, url
|
||||
from django.contrib import admin
|
||||
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
|
||||
from django.urls import re_path, path
|
||||
from django.views.generic.base import RedirectView
|
||||
from mdb.api.views import HostPXEValidate
|
||||
|
||||
admin.autodiscover()
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$', RedirectView.as_view(url='admin/', permanent=True)),
|
||||
url(r'^admin/', include(admin.site.urls)),
|
||||
url(r'^api/validate-host-secret/', HostPXEValidate.as_view(), name='api-validate-host-secret')
|
||||
re_path(r'^$', RedirectView.as_view(url='admin/', permanent=True)),
|
||||
path('admin/', admin.site.urls),
|
||||
path('api/validate-host-secret/', HostPXEValidate.as_view(), name='api-validate-host-secret')
|
||||
]
|
||||
|
||||
urlpatterns += staticfiles_urlpatterns()
|
||||
@@ -1,7 +0,0 @@
|
||||
Django>=1.8,<1.9
|
||||
django-auth-ldap==1.2.7
|
||||
django-extensions==1.6.1
|
||||
djangorestframework==3.3.3
|
||||
django-suit==0.2.18
|
||||
ipaddress==1.0.16
|
||||
mysqlclient==1.3.7
|
||||
Reference in new issue
Block a user