Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
acd082b2f8 |
No files matched your search
@@ -1,20 +0,0 @@
|
||||
[[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
@@ -1,147 +0,0 @@
|
||||
{
|
||||
"_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": {}
|
||||
}
|
||||
+14
-77
@@ -1,12 +1,8 @@
|
||||
import ipaddress
|
||||
|
||||
from django.contrib import admin, messages
|
||||
from django.db.models import Count
|
||||
from mdb.forms import InterfaceForm
|
||||
from mdb.models import (
|
||||
Ip6Address, Interface, Ip4Address, DhcpOption, DhcpCustomField, DomainSrvRecord, DomainTxtRecord,
|
||||
DomainCnameRecord, DomainARecord, Domain, Host, Ip4Subnet, Ip6Subnet, Nameserver, MailExchange, OperatingSystem,
|
||||
HostType, DhcpConfig, DomainAAAARecord)
|
||||
|
||||
from mdb.models import Ip6Address, Interface, Ip4Address, DhcpOption, DhcpCustomField, DomainSrvRecord, DomainTxtRecord, \
|
||||
DomainCnameRecord, DomainARecord, Domain, Host, Ip4Subnet, Ip6Subnet, Nameserver, MailExchange, OperatingSystem, \
|
||||
HostType, DhcpConfig, DomainAAAARecord
|
||||
|
||||
|
||||
class Ip6AddressInline(admin.TabularInline):
|
||||
@@ -18,7 +14,6 @@ class InterfaceInline(admin.TabularInline):
|
||||
inlines = [Ip6AddressInline]
|
||||
model = Interface
|
||||
extra = 0
|
||||
form = InterfaceForm
|
||||
|
||||
def get_queryset(self, request):
|
||||
return super(InterfaceInline, self).get_queryset(request).select_related()
|
||||
@@ -38,39 +33,19 @@ class HostAdmin(admin.ModelAdmin):
|
||||
'fields': ('owner', 'location', 'description')
|
||||
}),
|
||||
('Hardware and Software Information', {
|
||||
'fields': (
|
||||
('hostname', 'host_type'),
|
||||
('pxe_key', 'pxe_installable'),
|
||||
('brand', 'model'),
|
||||
'serial_number',
|
||||
('operating_system', 'virtual'))
|
||||
'fields': (('hostname', 'host_type'), ('pxe_key', 'pxe_installable'), ('brand', 'model'), 'serial_number', ('operating_system', 'virtual'))
|
||||
}),
|
||||
# FIXME: Not in use
|
||||
# ('Domain and Kerberos Information', {
|
||||
# 'description': 'If this host is a member of the LDAP domain, you need to tick the request kerberos principal checkbox. A principal will then be created for the host.',
|
||||
# 'classes': ['collapse'],
|
||||
# 'fields': ('request_kerberos_principal', 'kerberos_principal_created',
|
||||
# ('kerberos_principal_name', 'kerberos_principal_created_date'))
|
||||
# }),
|
||||
)
|
||||
actions = ['set_installable']
|
||||
|
||||
def mac_addresses(self, host):
|
||||
addresses = host.interface_set.filter(macaddr__isnull=False).values_list('macaddr', flat=True)
|
||||
return ", ".join(addresses)
|
||||
|
||||
def ip_addresses(self, host):
|
||||
addresses = host.interface_set.filter(ip4address__isnull=False).values_list('ip4address__address', flat=True)
|
||||
return ", ".join(addresses)
|
||||
|
||||
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"
|
||||
|
||||
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):
|
||||
def _get_host_warning_message(self, host, ifs):
|
||||
ifs_str = ', '.join([_if.name for _if in ifs])
|
||||
return 'Host {} might not be installable since interface(s) {} has no IP set.'.format(host, ifs_str)
|
||||
|
||||
@@ -98,11 +73,6 @@ class Ip4AddressInline(admin.TabularInline):
|
||||
extra = 0
|
||||
readonly_fields = ['address', 'assigned_to_host']
|
||||
|
||||
def assigned_to_host(self, addr):
|
||||
return addr.interface.host
|
||||
|
||||
assigned_to_host.short_description = "Assigned to Host"
|
||||
|
||||
|
||||
class DhcpOptionInline(admin.TabularInline):
|
||||
model = DhcpOption
|
||||
@@ -118,27 +88,6 @@ class SubnetAdmin(admin.ModelAdmin):
|
||||
list_display = ['name', 'network', 'netmask', 'num_addresses', 'broadcast_address', 'first_address', 'last_address']
|
||||
inlines = [DhcpOptionInline, DhcpCustomFieldInline, Ip4AddressInline]
|
||||
|
||||
def num_addresses(self, ip4subnet):
|
||||
subnet = ipaddress.IPv4Network(ip4subnet.network + "/" + ip4subnet.netmask)
|
||||
return subnet.num_addresses
|
||||
|
||||
def broadcast_address(self, ip4subnet):
|
||||
subnet = ipaddress.IPv4Network(ip4subnet.network + "/" + ip4subnet.netmask)
|
||||
return subnet.broadcast_address
|
||||
|
||||
def first_address(self, ip4subnet):
|
||||
subnet = ipaddress.IPv4Network(ip4subnet.network + "/" + ip4subnet.netmask)
|
||||
return next(subnet.hosts())
|
||||
|
||||
def last_address(self, ip4subnet):
|
||||
subnet = ipaddress.IPv4Network(ip4subnet.network + "/" + ip4subnet.netmask)
|
||||
return list(subnet.hosts())[-1]
|
||||
|
||||
broadcast_address.short_description = 'broadcast'
|
||||
num_addresses.short_description = '#addresses'
|
||||
first_address.short_description = 'first address'
|
||||
last_address.short_description = 'last address'
|
||||
|
||||
def get_queryset(self, request):
|
||||
# TODO: optimize
|
||||
return super(SubnetAdmin, self).get_queryset(request)
|
||||
@@ -175,25 +124,13 @@ class DomainAdmin(admin.ModelAdmin):
|
||||
list_display = ['domain_name', 'domain_soa', 'domain_admin', 'num_records', 'domain_ipaddr', 'domain_ip6addr']
|
||||
search_fields = ['domain_name']
|
||||
|
||||
def num_records(self, domain):
|
||||
host_a_records = Host.objects.filter(interface__domain=domain).count()
|
||||
size = {
|
||||
"CNAME": domain.domaincnamerecord_set.count(),
|
||||
"SRV": domain.domainsrvrecord_set.count(),
|
||||
"TXT": domain.domaintxtrecord_set.count(),
|
||||
"A": domain.domainarecord_set.count() + host_a_records
|
||||
}
|
||||
return ', '.join(['{}: {}'.format(k, v) for k, v in size.items()])
|
||||
|
||||
num_records.short_description = "Num Records"
|
||||
|
||||
|
||||
class HostTypeAdmin(admin.ModelAdmin):
|
||||
list_display = ['host_type', 'description', 'num_members']
|
||||
|
||||
|
||||
class OperatingSystemAdmin(admin.ModelAdmin):
|
||||
list_display = ['name', 'version', 'arch', 'pxe_kernel', 'pxe_initrd', 'pxe_preseed_config_url']
|
||||
list_display = ['name', 'version', 'arch']
|
||||
|
||||
|
||||
admin.site.register(Domain, DomainAdmin)
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
from mdb.models import Host
|
||||
from rest_framework import serializers
|
||||
from rest_framework.exceptions import ValidationError
|
||||
|
||||
from mdb.models import Host
|
||||
|
||||
|
||||
class HostPXEValidateSerializer(serializers.Serializer):
|
||||
certname = serializers.CharField(required=True)
|
||||
@@ -33,9 +32,7 @@ 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['pxe_key'],
|
||||
attrs['certname']))
|
||||
raise ValidationError('Supplied pxe_key does not match host \'{}\'.'.format(attrs['certname']))
|
||||
|
||||
self.host = host
|
||||
|
||||
@@ -44,7 +41,6 @@ class HostPXEValidateSerializer(serializers.Serializer):
|
||||
def create(self, validated_data):
|
||||
# Make requests kind of idempotent by only allowing 1 request / installation
|
||||
self.host.pxe_installable = False
|
||||
self.host.pxe_key = ''
|
||||
self.host.save()
|
||||
|
||||
return self.host
|
||||
+1
-1
@@ -15,6 +15,6 @@ class HostPXEValidate(APIView):
|
||||
|
||||
serializer.is_valid(raise_exception=True)
|
||||
|
||||
serializer.save() # sets Host.pxe_installable=False
|
||||
host = serializer.save() # sets Host.pxe_installable=False
|
||||
|
||||
return Response({'valid_pxe_key': True})
|
||||
+1
-1
@@ -7,4 +7,4 @@ class MdbAppConfig(AppConfig):
|
||||
|
||||
def ready(self):
|
||||
# all models are loaded, now attach signals
|
||||
import mdb.signals # noqa
|
||||
import mdb.signals
|
||||
@@ -2738,18 +2738,6 @@
|
||||
"model": "mdb.operatingsystem",
|
||||
"pk": 1
|
||||
},
|
||||
{
|
||||
"fields": {
|
||||
"pxe_initrd": "path-to-initrd-for-os",
|
||||
"pxe_kernel": "path-to-kernel-for-os",
|
||||
"pxe_preseed_config_url": "http://url-to-preseed.config",
|
||||
"arch": "x86_64",
|
||||
"name": "Ubuntu",
|
||||
"version": "16.04-beta-final"
|
||||
},
|
||||
"model": "mdb.operatingsystem",
|
||||
"pk": 2
|
||||
},
|
||||
{
|
||||
"fields": {
|
||||
"kerberos_principal_name": "",
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
from django import forms
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.forms import ModelChoiceField
|
||||
|
||||
from mdb.models import Interface, Ip4Address
|
||||
|
||||
|
||||
class Ip4ModelChoiceField(ModelChoiceField):
|
||||
def label_from_instance(self, obj):
|
||||
if not hasattr(obj, 'interface'):
|
||||
return obj.address
|
||||
|
||||
return "{} ({})".format(obj.address, obj.interface.host.hostname)
|
||||
|
||||
|
||||
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)
|
||||
|
||||
# Join Ip4Address with tables interface and host,
|
||||
# before printing the select labels that walk those two relations.
|
||||
queryset = Ip4Address.objects.select_related('interface', 'interface__host')
|
||||
self.fields['ip4address'] = Ip4ModelChoiceField(queryset=queryset)
|
||||
@@ -1,9 +1,15 @@
|
||||
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 subprocess import getstatusoutput
|
||||
from optparse import make_option
|
||||
try:
|
||||
from subprocess import getstatusoutput
|
||||
except ImportError:
|
||||
from commands import getstatusoutput
|
||||
|
||||
from mdb.models import DhcpConfig
|
||||
|
||||
@@ -12,28 +18,29 @@ class Command(BaseCommand):
|
||||
args = '--output <path> [--force] [--restart]'
|
||||
help = 'Generates the DHCP configuration'
|
||||
|
||||
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'),
|
||||
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 handle(self, *args, **options):
|
||||
output = options['output'] if options['output'] else sys.stdout
|
||||
force = options['force']
|
||||
restart = options['restart']
|
||||
restart_command = "/usr/sbin/service isc-dhcp-server restart"
|
||||
restart_command = "service isc-dhcp-server restart"
|
||||
|
||||
config = DhcpConfig.objects.filter(name="default").get()
|
||||
|
||||
@@ -60,7 +67,13 @@ class Command(BaseCommand):
|
||||
with open(output, 'w') as f:
|
||||
f.write(new)
|
||||
|
||||
diff = self.calculate_diff(config, new, old)
|
||||
# calculate diff
|
||||
diff = "\n".join(context_diff(
|
||||
a=old.splitlines(),
|
||||
b=new.splitlines(),
|
||||
fromfile=config.active_serial,
|
||||
tofile=config.serial,
|
||||
lineterm=''))
|
||||
|
||||
print(diff)
|
||||
|
||||
@@ -91,11 +104,3 @@ 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,10 +1,16 @@
|
||||
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 subprocess import getstatusoutput
|
||||
from optparse import make_option
|
||||
try:
|
||||
from subprocess import getstatusoutput
|
||||
except ImportError:
|
||||
from commands import getstatusoutput
|
||||
|
||||
from mdb.models import Domain, Ip4Subnet, Ip6Subnet
|
||||
|
||||
@@ -13,43 +19,50 @@ class Command(BaseCommand):
|
||||
args = '[--force] [--debug]'
|
||||
help = 'Generates the bind configuration'
|
||||
|
||||
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]
|
||||
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
|
||||
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 = options['debug']
|
||||
self.force = options['force']
|
||||
self.debug = debug = options['debug']
|
||||
force = options['force']
|
||||
|
||||
# do the binaries exist?
|
||||
self.validate_binaries_exist()
|
||||
for f in (self.checkzone_bin, self.bind_bin):
|
||||
if not os.path.isfile(f):
|
||||
print("ERROR: no such file %s, exiting..." % f)
|
||||
if not debug:
|
||||
sys.exit(1)
|
||||
|
||||
# create directories if needed
|
||||
os.path.isdir(self.checkzone_dir) or os.mkdir(self.checkzone_dir)
|
||||
self.debug and (os.path.isdir(self.debug_dir) or os.mkdir(self.debug_dir))
|
||||
debug and (os.path.isdir(self.debug_dir) or os.mkdir(self.debug_dir))
|
||||
|
||||
# update zones with new serials
|
||||
self.update_zone_serials()
|
||||
for zone in chain(Domain.objects.all(),
|
||||
Ip4Subnet.objects.all(),
|
||||
Ip6Subnet.objects.all()):
|
||||
if zone.domain_serial == zone.domain_active_serial or force:
|
||||
continue
|
||||
if self.update_zone(zone):
|
||||
self.changes[zone.domain_name]['success'] = True
|
||||
|
||||
# join errors, diffs and zone names
|
||||
errors = "\n\n\n".join(
|
||||
@@ -59,52 +72,35 @@ class Command(BaseCommand):
|
||||
zones = ", ".join(self.changes.keys())
|
||||
|
||||
# reload and send email with changes
|
||||
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)
|
||||
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)
|
||||
|
||||
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,
|
||||
@@ -130,7 +126,14 @@ class Command(BaseCommand):
|
||||
except IOError:
|
||||
old = ''
|
||||
|
||||
self.changes[zone.domain_name]['diff'] = self.calculate_diff(new, old, zone)
|
||||
# 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
|
||||
|
||||
# validate with zonecheck
|
||||
sys.stdout.write("\t- validating... ")
|
||||
@@ -139,7 +142,6 @@ 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
|
||||
@@ -164,17 +166,10 @@ 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', on_delete=models.CASCADE)),
|
||||
('domain', models.ForeignKey(to='mdb.Domain')),
|
||||
],
|
||||
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', on_delete=models.CASCADE)),
|
||||
('domain', models.ForeignKey(to='mdb.Domain')),
|
||||
],
|
||||
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', on_delete=models.CASCADE)),
|
||||
('domain', models.ForeignKey(to='mdb.Domain')),
|
||||
],
|
||||
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', on_delete=models.CASCADE)),
|
||||
('domain', models.ForeignKey(to='mdb.Domain')),
|
||||
],
|
||||
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', on_delete=models.CASCADE)),
|
||||
('host', models.ForeignKey(to='mdb.Host', on_delete=models.CASCADE)),
|
||||
('domain', models.ForeignKey(to='mdb.Domain')),
|
||||
('host', models.ForeignKey(to='mdb.Host')),
|
||||
],
|
||||
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', on_delete=models.CASCADE)),
|
||||
('dhcp_config', models.ForeignKey(to='mdb.DhcpConfig')),
|
||||
],
|
||||
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', on_delete=models.CASCADE)),
|
||||
('interface', models.ForeignKey(to='mdb.Interface')),
|
||||
],
|
||||
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', on_delete=models.CASCADE),
|
||||
field=models.ForeignKey(to='mdb.OsArchitecture'),
|
||||
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', on_delete=models.CASCADE),
|
||||
field=models.ForeignKey(to='mdb.Ip6Subnet'),
|
||||
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', on_delete=models.CASCADE),
|
||||
field=models.ForeignKey(to='mdb.Ip4Subnet'),
|
||||
preserve_default=True,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='interface',
|
||||
name='ip4address',
|
||||
field=models.ForeignKey(null=True, blank=True, to='mdb.Ip4Address', unique=True, on_delete=models.SET_NULL),
|
||||
field=models.ForeignKey(null=True, blank=True, to='mdb.Ip4Address', unique=True),
|
||||
preserve_default=True,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='host',
|
||||
name='host_type',
|
||||
field=models.ForeignKey(to='mdb.HostType', on_delete=models.CASCADE),
|
||||
field=models.ForeignKey(to='mdb.HostType'),
|
||||
preserve_default=True,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='host',
|
||||
name='operating_system',
|
||||
field=models.ForeignKey(to='mdb.OperatingSystem', on_delete=models.CASCADE),
|
||||
field=models.ForeignKey(to='mdb.OperatingSystem'),
|
||||
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', on_delete=models.CASCADE),
|
||||
field=models.ForeignKey(to='mdb.Ip4Subnet'),
|
||||
preserve_default=True,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='dhcpcustomfield',
|
||||
name='ip4subnet',
|
||||
field=models.ForeignKey(to='mdb.Ip4Subnet', on_delete=models.CASCADE),
|
||||
field=models.ForeignKey(to='mdb.Ip4Subnet'),
|
||||
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, on_delete=models.SET_NULL),
|
||||
field=models.OneToOneField(to='mdb.Ip4Address', null=True, blank=True),
|
||||
),
|
||||
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', on_delete=models.CASCADE)),
|
||||
('domain', models.ForeignKey(to='mdb.Domain')),
|
||||
],
|
||||
),
|
||||
migrations.AlterField(
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('mdb', '0010_auto_20151004_1709'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='operatingsystem',
|
||||
name='pxe_initrd',
|
||||
field=models.CharField(null=True, blank=True, max_length=255),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='operatingsystem',
|
||||
name='pxe_kernel',
|
||||
field=models.CharField(null=True, blank=True, max_length=255),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='operatingsystem',
|
||||
name='pxe_preseed_config_url',
|
||||
field=models.URLField(null=True, blank=True),
|
||||
),
|
||||
]
|
||||
+113
-24
@@ -1,6 +1,9 @@
|
||||
from django.db import models
|
||||
from django.db.models import Count
|
||||
from django.template.loader import render_to_string
|
||||
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
|
||||
from mdb.utils import host_as_pxe_files
|
||||
|
||||
from mdb.validators import validate_hostname, validate_macaddr
|
||||
|
||||
@@ -8,6 +11,7 @@ import ipaddress
|
||||
import datetime
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class Nameserver(models.Model):
|
||||
hostname = models.CharField(max_length=256)
|
||||
|
||||
@@ -15,6 +19,7 @@ class Nameserver(models.Model):
|
||||
return self.hostname
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class MailExchange(models.Model):
|
||||
priority = models.IntegerField()
|
||||
hostname = models.CharField(max_length=256)
|
||||
@@ -23,6 +28,7 @@ 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)
|
||||
@@ -45,6 +51,21 @@ class Domain(models.Model):
|
||||
def __str__(self):
|
||||
return self.domain_name
|
||||
|
||||
def domain_admin_formatted(self):
|
||||
return self.domain_admin.replace("@", ".")
|
||||
|
||||
def num_records(self):
|
||||
host_a_records = Host.objects.filter(interface__domain=self).count()
|
||||
size = {
|
||||
"CNAME": self.domaincnamerecord_set.count(),
|
||||
"SRV": self.domainsrvrecord_set.count(),
|
||||
"TXT": self.domaintxtrecord_set.count(),
|
||||
"A": self.domainarecord_set.count() + host_a_records
|
||||
}
|
||||
return ', '.join(['{}: {}'.format(k, v) for k, v in size.items()])
|
||||
|
||||
num_records.short_description = "Num Records"
|
||||
|
||||
def __eq__(self, other):
|
||||
if not other or not hasattr(other, 'domain_name'):
|
||||
return False
|
||||
@@ -76,7 +97,7 @@ class Domain(models.Model):
|
||||
if self.domain_ipaddr is not None:
|
||||
content += "@\tIN\tA\t%s\n" % self.domain_ipaddr
|
||||
|
||||
if self.domain_ip6addr:
|
||||
if self.domain_ip6addr is not None:
|
||||
content += "@\tIN\tAAAA\t%s\n" % self.domain_ip6addr
|
||||
|
||||
content += "; SRV records\n"
|
||||
@@ -119,7 +140,15 @@ class Domain(models.Model):
|
||||
|
||||
return content
|
||||
|
||||
def zone_file_contents_alt(self):
|
||||
context = {
|
||||
'domain': self,
|
||||
'now': datetime.datetime.now()
|
||||
}
|
||||
return render_to_string('zone_file.txt', context=context)
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class DomainSrvRecord(models.Model):
|
||||
srvce = models.CharField(max_length=64)
|
||||
prot = models.CharField(max_length=64)
|
||||
@@ -128,7 +157,7 @@ class DomainSrvRecord(models.Model):
|
||||
weight = models.IntegerField()
|
||||
port = models.IntegerField()
|
||||
target = models.CharField(max_length=256)
|
||||
domain = models.ForeignKey(Domain, on_delete=models.CASCADE)
|
||||
domain = models.ForeignKey(Domain)
|
||||
created_date = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
def as_record(self):
|
||||
@@ -147,10 +176,11 @@ 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, on_delete=models.CASCADE)
|
||||
domain = models.ForeignKey(Domain)
|
||||
created_date = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
def as_record(self):
|
||||
@@ -160,10 +190,11 @@ 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, on_delete=models.CASCADE)
|
||||
domain = models.ForeignKey(Domain)
|
||||
created_date = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
def as_record(self):
|
||||
@@ -173,10 +204,11 @@ 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, on_delete=models.CASCADE)
|
||||
domain = models.ForeignKey(Domain)
|
||||
created_date = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
def as_record(self):
|
||||
@@ -186,10 +218,11 @@ 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, on_delete=models.CASCADE)
|
||||
domain = models.ForeignKey(Domain)
|
||||
created_date = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
def as_record(self):
|
||||
@@ -199,6 +232,7 @@ class DomainAAAARecord(models.Model):
|
||||
return self.as_record()
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class DhcpConfig(models.Model):
|
||||
serial = models.IntegerField()
|
||||
active_serial = models.IntegerField()
|
||||
@@ -260,6 +294,7 @@ 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)
|
||||
@@ -308,7 +343,7 @@ class Ip6Subnet(models.Model):
|
||||
# content += "$ORIGIN " + ".".join(network.exploded.replace(":","")[:16])[::-1] + ".ip6.arpa.\n"
|
||||
|
||||
for addr in self.ip6address_set.all():
|
||||
# if addr.interface_set.count() == 0: continue
|
||||
#if addr.interface_set.count() == 0: continue
|
||||
|
||||
if addr.interface.domain is None:
|
||||
continue
|
||||
@@ -329,6 +364,7 @@ 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')
|
||||
@@ -350,11 +386,32 @@ 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, on_delete=models.CASCADE)
|
||||
dhcp_config = models.ForeignKey(DhcpConfig)
|
||||
|
||||
def __str__(self):
|
||||
return self.network + " (" + self.name + ")"
|
||||
|
||||
def num_addresses(self):
|
||||
subnet = ipaddress.IPv4Network(self.network + "/" + self.netmask)
|
||||
return subnet.num_addresses
|
||||
|
||||
def broadcast_address(self):
|
||||
subnet = ipaddress.IPv4Network(self.network + "/" + self.netmask)
|
||||
return subnet.broadcast_address
|
||||
|
||||
def first_address(self):
|
||||
subnet = ipaddress.IPv4Network(self.network + "/" + self.netmask)
|
||||
return next(subnet.hosts())
|
||||
|
||||
def last_address(self):
|
||||
subnet = ipaddress.IPv4Network(self.network + "/" + self.netmask)
|
||||
return list(subnet.hosts())[-1]
|
||||
|
||||
broadcast_address.short_description = 'broadcast'
|
||||
num_addresses.short_description = '#addresses'
|
||||
first_address.short_description = 'first address'
|
||||
last_address.short_description = 'last address'
|
||||
|
||||
def zone_file_contents(self, generate_unassigned=False):
|
||||
content = ""
|
||||
content += "; zone file for %s\n" % self.domain_name
|
||||
@@ -397,10 +454,11 @@ 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, on_delete=models.CASCADE)
|
||||
ip4subnet = models.ForeignKey(Ip4Subnet)
|
||||
|
||||
def __str__(self):
|
||||
return self.key + " " + self.value
|
||||
@@ -411,26 +469,37 @@ class DhcpOption(models.Model):
|
||||
|
||||
class DhcpCustomField(models.Model):
|
||||
value = models.CharField(max_length=255)
|
||||
ip4subnet = models.ForeignKey(Ip4Subnet, on_delete=models.CASCADE)
|
||||
ip4subnet = models.ForeignKey(Ip4Subnet)
|
||||
|
||||
class Meta:
|
||||
verbose_name = 'DHCP custom field'
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class Ip4Address(models.Model):
|
||||
subnet = models.ForeignKey(Ip4Subnet, on_delete=models.CASCADE)
|
||||
subnet = models.ForeignKey(Ip4Subnet)
|
||||
address = models.GenericIPAddressField(protocol='IPv4')
|
||||
last_contact = models.DateTimeField(null=True, blank=True)
|
||||
ping_avg_rtt = models.FloatField(null=True, blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.address
|
||||
# FIXME: generates 2 SQL queries?
|
||||
if not hasattr(self, 'interface'):
|
||||
return self.address
|
||||
|
||||
return "{} ({})".format(self.address, self.interface.host.hostname)
|
||||
|
||||
def assigned_to_host(self):
|
||||
return self.interface.host
|
||||
|
||||
assigned_to_host.short_description = "Assigned to Host"
|
||||
|
||||
class Meta:
|
||||
verbose_name = 'IPv4 address'
|
||||
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)
|
||||
@@ -445,6 +514,7 @@ class HostType(models.Model):
|
||||
ordering = ("host_type",)
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class OperatingSystem(models.Model):
|
||||
OS_ARCHITECTURES = (
|
||||
('mips', _('MIPS')),
|
||||
@@ -461,10 +531,6 @@ class OperatingSystem(models.Model):
|
||||
version = models.CharField(max_length=64)
|
||||
arch = models.CharField(max_length=255, choices=OS_ARCHITECTURES, blank=True, null=True)
|
||||
|
||||
pxe_kernel = models.CharField(max_length=255, blank=True, null=True)
|
||||
pxe_initrd = models.CharField(max_length=255, blank=True, null=True)
|
||||
pxe_preseed_config_url = models.URLField(blank=True, null=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.name + " " + self.version + " (" + self.arch + ")"
|
||||
|
||||
@@ -472,6 +538,7 @@ 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)
|
||||
@@ -481,9 +548,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, on_delete=models.CASCADE)
|
||||
host_type = models.ForeignKey(HostType)
|
||||
virtual = models.BooleanField(default=False)
|
||||
operating_system = models.ForeignKey(OperatingSystem, on_delete=models.CASCADE)
|
||||
operating_system = models.ForeignKey(OperatingSystem)
|
||||
|
||||
request_kerberos_principal = models.BooleanField(default=False)
|
||||
kerberos_principal_created = models.BooleanField(default=False, editable=False)
|
||||
@@ -496,19 +563,40 @@ class Host(models.Model):
|
||||
def __str__(self):
|
||||
return self.hostname
|
||||
|
||||
def in_domain(self):
|
||||
domains = self.interface_set.values_list('domain__domain_name', flat=True)
|
||||
return ",".join(domains)
|
||||
|
||||
in_domain.short_description = "in domains"
|
||||
|
||||
def ipv6_enabled(self):
|
||||
ipv6_ifs = self.interface_set.annotate(num_ipv6=Count('ip6address')).filter(num_ipv6__gt=0)
|
||||
return ipv6_ifs.exists()
|
||||
|
||||
ipv6_enabled.boolean = True
|
||||
|
||||
def mac_addresses(self):
|
||||
addresses = self.interface_set.filter(macaddr__isnull=False).values_list('macaddr', flat=True)
|
||||
return ", ".join(addresses)
|
||||
|
||||
def ip_addresses(self):
|
||||
addresses = self.interface_set.filter(ip4address__isnull=False).values_list('ip4address__address', flat=True)
|
||||
return ", ".join(addresses)
|
||||
|
||||
def as_pxe_files(self):
|
||||
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, on_delete=models.CASCADE)
|
||||
ip4address = models.OneToOneField(Ip4Address, blank=True, null=True, on_delete=models.SET_NULL)
|
||||
host = models.ForeignKey(Host)
|
||||
ip4address = models.OneToOneField(Ip4Address, blank=True, null=True)
|
||||
created_date = models.DateTimeField(auto_now_add=True)
|
||||
domain = models.ForeignKey(Domain, on_delete=models.CASCADE)
|
||||
domain = models.ForeignKey(Domain)
|
||||
|
||||
def __str__(self):
|
||||
return "%s (%s on %s)" % (self.macaddr, self.name, self.host.hostname)
|
||||
@@ -517,10 +605,11 @@ class Interface(models.Model):
|
||||
return self.ip6address_set.exists()
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class Ip6Address(models.Model):
|
||||
subnet = models.ForeignKey(Ip6Subnet, on_delete=models.CASCADE)
|
||||
subnet = models.ForeignKey(Ip6Subnet)
|
||||
address = models.GenericIPAddressField(protocol='IPv6')
|
||||
interface = models.ForeignKey(Interface, on_delete=models.CASCADE)
|
||||
interface = models.ForeignKey(Interface)
|
||||
|
||||
def full_address(self):
|
||||
return self.subnet.network + self.address
|
||||
|
||||
-58
@@ -1,58 +0,0 @@
|
||||
from django.conf import settings
|
||||
from django.template.loader import render_to_string
|
||||
import ipaddress
|
||||
|
||||
|
||||
def render_pxelinux_cfg(_if, host):
|
||||
"""Renders pxelinux.cfg based on a host and the set of host interfaces.
|
||||
If the host is tied to an OS with PXE fields set, it will use these instead of defaults."""
|
||||
# Default config
|
||||
kernel = settings.MDB_PXE_KERNEL
|
||||
initrd = settings.MDB_PXE_INITRD
|
||||
preseed_config_url = settings.MDB_PXE_PRESEED_URL
|
||||
|
||||
# Per host config (via OS model)
|
||||
_os = host.operating_system
|
||||
pxe_attrs = [_os.pxe_initrd, _os.pxe_kernel, _os.pxe_preseed_config_url]
|
||||
if None not in pxe_attrs and '' not in pxe_attrs:
|
||||
kernel = _os.pxe_kernel
|
||||
initrd = _os.pxe_initrd
|
||||
preseed_config_url = _os.pxe_preseed_config_url
|
||||
|
||||
context = {
|
||||
'kernel': kernel,
|
||||
'initrd': initrd,
|
||||
'preseed_config_url': preseed_config_url,
|
||||
'host': host,
|
||||
'interface': _if
|
||||
}
|
||||
|
||||
return render_to_string('pxelinux.cfg', context=context)
|
||||
|
||||
|
||||
def get_pxe_filename(interface, filename_format='mac_addr'):
|
||||
"""
|
||||
Mac or IP address based PXE filename
|
||||
Ref: http://www.syslinux.org/wiki/index.php/PXELINUX#Examples
|
||||
"""
|
||||
ip_addr_in_hex = '{:02X}'.format(int(ipaddress.IPv4Address(interface.ip4address.address)))
|
||||
formats = {
|
||||
'ip_addr': ip_addr_in_hex,
|
||||
'mac_addr': '01-{}'.format(interface.macaddr.lower().replace(':', '-'))
|
||||
}
|
||||
|
||||
return formats.get(filename_format, formats['mac_addr'])
|
||||
|
||||
|
||||
def host_as_pxe_files(host):
|
||||
"""Returns a list of filename,content for each host interface with an IPv4 address."""
|
||||
from mdb.models import Host
|
||||
assert isinstance(host, Host)
|
||||
|
||||
pxe_files = []
|
||||
for _if in host.interface_set.exclude(ip4address__isnull=True):
|
||||
filename = get_pxe_filename(_if)
|
||||
content = render_pxelinux_cfg(_if, host)
|
||||
pxe_files.append((filename, content))
|
||||
|
||||
return pxe_files
|
||||
@@ -98,11 +98,9 @@ def create_pxe_key_and_write_pxe_files_when_host_changes(sender, instance, creat
|
||||
for pxe_file_name, pxe_file in host.as_pxe_files():
|
||||
path = os.path.join(settings.MDB_PXE_TFTP_ROOT, pxe_file_name)
|
||||
if host.pxe_installable:
|
||||
# Write pxeconfig file to disk
|
||||
with open(path, 'w+') as f:
|
||||
f.write(pxe_file)
|
||||
logger.info("Created or updated {}".format(path))
|
||||
os.chmod(path, 0o644) # Not writeable for all
|
||||
|
||||
# Also set necessary fields for pxe installation
|
||||
interfaces = host.interface_set.exclude(ip4address__isnull=True)
|
||||
@@ -121,7 +119,6 @@ def create_pxe_key_and_write_pxe_files_when_host_changes(sender, instance, creat
|
||||
|
||||
else:
|
||||
if os.path.exists(path):
|
||||
# Delete pxeconfig file from disk
|
||||
os.unlink(path)
|
||||
logger.info("deleted {}".format(path))
|
||||
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
default ninja
|
||||
kernel {{kernel}}
|
||||
append ramdisk_size=14984 locale=en_US console-setup/ask_detect=false keyboard-configuration/layoutcode=no netcfg/wireless_wep= netcfg_choose_interface=eth0 netcfg/get_hostname= preseed/url={{preseed_config_url}} vga=normal initrd={{initrd}} -- snop={{host.pxe_key}}
|
||||
prompt 0
|
||||
timeout 0
|
||||
|
||||
label ninja
|
||||
kernel {{kernel}}
|
||||
append ramdisk_size=14984 locale=en_US console-setup/ask_detect=false keyboard-configuration/layoutcode=no netcfg/wireless_wep= netcfg_choose_interface=eth0 netcfg/get_hostname= preseed/url={{preseed_config_url}} vga=normal snop={{host.pxe_key}} initrd={{initrd}} -- quiet
|
||||
timeout 0
|
||||
@@ -0,0 +1,31 @@
|
||||
; serial: {{ domain.domain_serial }}
|
||||
; zone file for {{ domain.domain_name }}
|
||||
; {{ now|date:"c" }}
|
||||
; filename: {{ domain.domain_filename }}
|
||||
$TTL {{ domain.domain_ttl }}
|
||||
@ IN SOA {{ domain.domain_soa }}. {{ domain.domain_admin_formatted }}. (
|
||||
{{ domain.domain_serial|stringformat:"-10s" }} ; serial
|
||||
{{ domain.domain_refresh|stringformat:"-10s" }} ; refresh
|
||||
{{ domain.domain_retry|stringformat:"-10s" }} ; retry
|
||||
{{ domain.domain_expire|stringformat:"-10s" }} ; expire
|
||||
{{ domain.domain_minimum_ttl }} ) ; minimum ttl
|
||||
;
|
||||
{% for nameserver in domain.domain_nameservers.all %}@ IN NS {{ nameserver.hostname }}.
|
||||
{% endfor %}{% for mx in domain.domain_mailexchanges.all %}@ MX {{ mx.priority }} {{ mx.hostname }}.{% endfor %}
|
||||
{% if domain.domain_ipaddr %}@ IN A {{ domain.domain_ipaddr }}{% endif %}
|
||||
{% if domain.domain_ip6addr %}@ IN AAAA {{ domain.domain_ip6addr }}{% endif %}
|
||||
; SRV records
|
||||
{% for srv in domain.domainsrvrecord_set.all %}{{ srv.as_record }}{% endfor %}
|
||||
; A records
|
||||
{% for a in domain.domainarecord_set.all %}{{ a.as_record }}{% endfor %}
|
||||
; AAAA records
|
||||
{% for aaaa in domain.domainaaaarecord_set.all %}{{ aaaa.as_record }}{% endfor %}
|
||||
; CNAME records
|
||||
{% for cname in domain.domaincnamerecord_set.all %}{{ cname.name|stringformat:"-20s" }} IN CNAME {{ cname.target }}{% endfor %}
|
||||
; TXT records
|
||||
{% for txt in domain.domaintxtrecord_set.all %}{{ txt.as_record }}{% endfor %}
|
||||
; HOST records
|
||||
{% for interface in domain.interface_set.all %}
|
||||
{% if interface.ip4address %}{{ interface.host.hostname|stringformat:"-20s" }} IN A {{ interface.ip4address.address }}{% endif %}
|
||||
{% for ipv6addr in interface.ip6address_set.all %}{{ interface.host.hostname|stringformat:"-20s" }} IN AAAA {{ ipv6addr.full_address }}{% endfor %}
|
||||
{% endfor %}
|
||||
+3
-27
@@ -1,15 +1,12 @@
|
||||
import io
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.management import call_command
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.test import TestCase
|
||||
from mdb.pxe import render_pxelinux_cfg
|
||||
from rest_framework.authtoken.models import Token
|
||||
from rest_framework.test import APITestCase
|
||||
|
||||
from mdb.models import Host, OperatingSystem
|
||||
from mdb.models import Host
|
||||
|
||||
|
||||
class MyAPITestCases(APITestCase):
|
||||
@@ -38,27 +35,6 @@ class MyAPITestCases(APITestCase):
|
||||
class UnitTests(TestCase):
|
||||
fixtures = ['test_data']
|
||||
|
||||
def test_render_pxeconfig(self):
|
||||
host = Host.objects.first()
|
||||
interface = host.interface_set.exclude(ip4address__isnull=True).first()
|
||||
config = render_pxelinux_cfg(interface, host)
|
||||
|
||||
self.assertIn(settings.MDB_PXE_INITRD, config)
|
||||
self.assertIn(settings.MDB_PXE_KERNEL, config)
|
||||
self.assertIn(settings.MDB_PXE_PRESEED_URL, config)
|
||||
|
||||
def test_render_pxeconfig_with_os_pxe_config(self):
|
||||
_os = OperatingSystem.objects.get(pk=2) # OS with all pxe vars set
|
||||
Host.objects.filter(pk=Host.objects.first().pk).update(operating_system=_os)
|
||||
host = Host.objects.first()
|
||||
|
||||
interface = host.interface_set.exclude(ip4address__isnull=True).first()
|
||||
config = render_pxelinux_cfg(interface, host)
|
||||
|
||||
self.assertIn(_os.pxe_initrd, config)
|
||||
self.assertIn(_os.pxe_kernel, config)
|
||||
self.assertIn(_os.pxe_preseed_config_url, config)
|
||||
|
||||
def test_host_as_pxe_files(self):
|
||||
host = Host.objects.first()
|
||||
self.assertEqual(len(host.as_pxe_files()), 1)
|
||||
@@ -68,13 +44,13 @@ class RunManagementCommands(TestCase):
|
||||
fixtures = ['test_data']
|
||||
|
||||
def test_zone_sync(self):
|
||||
# expected_zone_file = ''
|
||||
expected_zone_file = ''
|
||||
with io.BytesIO() as f:
|
||||
call_command('zone-sync', debug=True, stdout=f)
|
||||
# TODO check expected_zone_file
|
||||
|
||||
def test_dhcp_sync(self):
|
||||
# expected_dhcp_file = ''
|
||||
expected_dhcp_file = ''
|
||||
with io.BytesIO() as f:
|
||||
call_command('dhcp-sync', stdout=f)
|
||||
# TODO check expected_dhcp_file
|
||||
+48
-1
@@ -1,4 +1,7 @@
|
||||
import datetime
|
||||
from django.conf import settings
|
||||
from django.template.loader import render_to_string
|
||||
import ipaddress
|
||||
import re
|
||||
|
||||
|
||||
@@ -17,7 +20,7 @@ def format_domain_serial_and_add_one(serial):
|
||||
""" The serial contains todays date, just update it. """
|
||||
try:
|
||||
number = int(res[0])
|
||||
except ValueError:
|
||||
except:
|
||||
number = 1
|
||||
if number >= 99:
|
||||
""" This is bad... Just keep the number on 99.
|
||||
@@ -32,3 +35,47 @@ def format_domain_serial_and_add_one(serial):
|
||||
""" Just return the first serial for today. """
|
||||
return "%4d%02d%02d%02d" % \
|
||||
(today.year, today.month, today.day, 1)
|
||||
|
||||
|
||||
def render_pxelinux_cfg(_if, host):
|
||||
# TODO add fields to os model and make dynamic per host
|
||||
distro = 'ubuntu/14_04/amd64/alternate/'
|
||||
kernel = distro + 'linux'
|
||||
initrd = distro + 'initrd.gz'
|
||||
preseed_config_url = settings.MDB_PXE_PRESEED_URL
|
||||
context = {
|
||||
'kernel': kernel,
|
||||
'initrd': initrd,
|
||||
'preseed_config_url': preseed_config_url,
|
||||
'host': host,
|
||||
'interface': _if
|
||||
}
|
||||
return render_to_string('pxelinux.cfg', context=context)
|
||||
|
||||
|
||||
def get_pxe_filename(interface, filename_format='mac_addr'):
|
||||
"""
|
||||
Mac or IP address based PXE filename
|
||||
Ref: http://www.syslinux.org/wiki/index.php/PXELINUX#Examples
|
||||
"""
|
||||
ip_addr_in_hex = '{:02X}'.format(int(ipaddress.IPv4Address(interface.ip4address.address)))
|
||||
formats = {
|
||||
'ip_addr': ip_addr_in_hex,
|
||||
'mac_addr': '01-{}'.format(interface.macaddr.lower().replace(':', '-'))
|
||||
}
|
||||
|
||||
return formats.get(filename_format, formats['mac_addr'])
|
||||
|
||||
|
||||
def host_as_pxe_files(host):
|
||||
""" Returns a list of filename,content for each host interface with an IPv4 address """
|
||||
from mdb.models import Host
|
||||
assert isinstance(host, Host)
|
||||
|
||||
pxe_files = []
|
||||
for _if in host.interface_set.exclude(ip4address__isnull=True):
|
||||
filename = get_pxe_filename(_if)
|
||||
content = render_pxelinux_cfg(_if, host)
|
||||
pxe_files.append((filename, content))
|
||||
|
||||
return pxe_files
|
||||
@@ -1,3 +1,4 @@
|
||||
from __future__ import unicode_literals
|
||||
from django.core.validators import RegexValidator
|
||||
import re
|
||||
|
||||
|
||||
+22
-76
@@ -1,5 +1,5 @@
|
||||
import os
|
||||
import raven
|
||||
from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS as TCP
|
||||
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
|
||||
|
||||
@@ -32,40 +32,38 @@ 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 = [
|
||||
MIDDLEWARE_CLASSES = (
|
||||
'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'
|
||||
|
||||
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',
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
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.
|
||||
)
|
||||
|
||||
INSTALLED_APPS = (
|
||||
'django.contrib.auth',
|
||||
@@ -78,56 +76,15 @@ INSTALLED_APPS = (
|
||||
'django.contrib.admin',
|
||||
'rest_framework',
|
||||
'rest_framework.authtoken',
|
||||
'django_extensions',
|
||||
'raven.contrib.django.raven_compat',
|
||||
|
||||
'mdb',
|
||||
)
|
||||
|
||||
EMAIL_SUBJECT_PREFIX = '[MDB] '
|
||||
|
||||
# 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,
|
||||
},
|
||||
},
|
||||
}
|
||||
TEMPLATE_CONTEXT_PROCESSORS = TCP + (
|
||||
'django.core.context_processors.request', # for django-suit
|
||||
)
|
||||
|
||||
# django-suit configuration
|
||||
SUIT_CONFIG = {
|
||||
@@ -158,27 +115,16 @@ SUIT_CONFIG = {
|
||||
),
|
||||
|
||||
# misc
|
||||
'LIST_PER_PAGE': 35
|
||||
'LIST_PER_PAGE': 30
|
||||
}
|
||||
|
||||
# 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 = [
|
||||
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')
|
||||
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')
|
||||
]
|
||||
|
||||
urlpatterns += staticfiles_urlpatterns()
|
||||
+2
-3
@@ -1,6 +1,5 @@
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
import os
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mdb.settings")
|
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mdbsite.settings")
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
application = get_wsgi_application()
|
||||
@@ -0,0 +1,7 @@
|
||||
Django>=1.8,<1.9
|
||||
django-auth-ldap
|
||||
django-extensions==1.5.7
|
||||
djangorestframework==3.2.4
|
||||
django-suit==0.2.15
|
||||
ipaddress==1.0.14
|
||||
mysqlclient==1.3.6
|
||||
Reference in new issue
Block a user