Compare commits
31
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9dc195fd46 | ||
|
|
d5d63b4dca | ||
|
|
47b69a9ea7 | ||
|
|
7de3e4008c | ||
|
|
54180d6bb5 | ||
|
|
49183fb646 | ||
|
|
cf6b1ad13d | ||
|
|
51b595a11d | ||
|
|
093fae0fea | ||
|
|
b79fdafaa1 | ||
|
|
8fe8a1b311 | ||
|
|
935e38d224 | ||
|
|
2fd8001ba5 | ||
|
|
ca76aaa80b | ||
|
|
456bcb7c50 | ||
|
|
277fde9809 | ||
|
|
257b00be1b | ||
|
|
3659215a2f | ||
|
|
7b47e1d6d9 | ||
|
|
e17bf339e2 | ||
|
|
9d737dcd45 | ||
|
|
898578852d | ||
|
|
2a0744f602 | ||
|
|
15cde2cce4 | ||
|
|
d523b4ae99 | ||
|
|
fdb826d5ac | ||
|
|
bcb4b2e713 | ||
|
|
4daf775adb | ||
|
|
2df1f6ab36 | ||
|
|
5ece0c21f9 | ||
|
|
8946234b10 |
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": {}
|
||||||
|
}
|
||||||
+77
-14
@@ -1,8 +1,12 @@
|
|||||||
from django.contrib import admin, messages
|
import ipaddress
|
||||||
|
|
||||||
from mdb.models import Ip6Address, Interface, Ip4Address, DhcpOption, DhcpCustomField, DomainSrvRecord, DomainTxtRecord, \
|
from django.contrib import admin, messages
|
||||||
DomainCnameRecord, DomainARecord, Domain, Host, Ip4Subnet, Ip6Subnet, Nameserver, MailExchange, OperatingSystem, \
|
from django.db.models import Count
|
||||||
HostType, DhcpConfig, DomainAAAARecord
|
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)
|
||||||
|
|
||||||
|
|
||||||
class Ip6AddressInline(admin.TabularInline):
|
class Ip6AddressInline(admin.TabularInline):
|
||||||
@@ -14,6 +18,7 @@ class InterfaceInline(admin.TabularInline):
|
|||||||
inlines = [Ip6AddressInline]
|
inlines = [Ip6AddressInline]
|
||||||
model = Interface
|
model = Interface
|
||||||
extra = 0
|
extra = 0
|
||||||
|
form = InterfaceForm
|
||||||
|
|
||||||
def get_queryset(self, request):
|
def get_queryset(self, request):
|
||||||
return super(InterfaceInline, self).get_queryset(request).select_related()
|
return super(InterfaceInline, self).get_queryset(request).select_related()
|
||||||
@@ -33,19 +38,39 @@ class HostAdmin(admin.ModelAdmin):
|
|||||||
'fields': ('owner', 'location', 'description')
|
'fields': ('owner', 'location', 'description')
|
||||||
}),
|
}),
|
||||||
('Hardware and Software Information', {
|
('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']
|
actions = ['set_installable']
|
||||||
|
|
||||||
def _get_host_warning_message(self, host, ifs):
|
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):
|
||||||
ifs_str = ', '.join([_if.name for _if in 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)
|
return 'Host {} might not be installable since interface(s) {} has no IP set.'.format(host, ifs_str)
|
||||||
|
|
||||||
@@ -73,6 +98,11 @@ class Ip4AddressInline(admin.TabularInline):
|
|||||||
extra = 0
|
extra = 0
|
||||||
readonly_fields = ['address', 'assigned_to_host']
|
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):
|
class DhcpOptionInline(admin.TabularInline):
|
||||||
model = DhcpOption
|
model = DhcpOption
|
||||||
@@ -88,6 +118,27 @@ class SubnetAdmin(admin.ModelAdmin):
|
|||||||
list_display = ['name', 'network', 'netmask', 'num_addresses', 'broadcast_address', 'first_address', 'last_address']
|
list_display = ['name', 'network', 'netmask', 'num_addresses', 'broadcast_address', 'first_address', 'last_address']
|
||||||
inlines = [DhcpOptionInline, DhcpCustomFieldInline, Ip4AddressInline]
|
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):
|
def get_queryset(self, request):
|
||||||
# TODO: optimize
|
# TODO: optimize
|
||||||
return super(SubnetAdmin, self).get_queryset(request)
|
return super(SubnetAdmin, self).get_queryset(request)
|
||||||
@@ -124,13 +175,25 @@ class DomainAdmin(admin.ModelAdmin):
|
|||||||
list_display = ['domain_name', 'domain_soa', 'domain_admin', 'num_records', 'domain_ipaddr', 'domain_ip6addr']
|
list_display = ['domain_name', 'domain_soa', 'domain_admin', 'num_records', 'domain_ipaddr', 'domain_ip6addr']
|
||||||
search_fields = ['domain_name']
|
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):
|
class HostTypeAdmin(admin.ModelAdmin):
|
||||||
list_display = ['host_type', 'description', 'num_members']
|
list_display = ['host_type', 'description', 'num_members']
|
||||||
|
|
||||||
|
|
||||||
class OperatingSystemAdmin(admin.ModelAdmin):
|
class OperatingSystemAdmin(admin.ModelAdmin):
|
||||||
list_display = ['name', 'version', 'arch']
|
list_display = ['name', 'version', 'arch', 'pxe_kernel', 'pxe_initrd', 'pxe_preseed_config_url']
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(Domain, DomainAdmin)
|
admin.site.register(Domain, DomainAdmin)
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
from mdb.models import Host
|
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from rest_framework.exceptions import ValidationError
|
from rest_framework.exceptions import ValidationError
|
||||||
|
|
||||||
|
from mdb.models import Host
|
||||||
|
|
||||||
|
|
||||||
class HostPXEValidateSerializer(serializers.Serializer):
|
class HostPXEValidateSerializer(serializers.Serializer):
|
||||||
certname = serializers.CharField(required=True)
|
certname = serializers.CharField(required=True)
|
||||||
@@ -32,7 +33,9 @@ class HostPXEValidateSerializer(serializers.Serializer):
|
|||||||
raise ValidationError('Host \'{}\' has no pxe_key.'.format(attrs['certname']))
|
raise ValidationError('Host \'{}\' has no pxe_key.'.format(attrs['certname']))
|
||||||
|
|
||||||
if host.pxe_key != attrs['pxe_key']:
|
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
|
self.host = host
|
||||||
|
|
||||||
@@ -41,6 +44,7 @@ class HostPXEValidateSerializer(serializers.Serializer):
|
|||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
# Make requests kind of idempotent by only allowing 1 request / installation
|
# Make requests kind of idempotent by only allowing 1 request / installation
|
||||||
self.host.pxe_installable = False
|
self.host.pxe_installable = False
|
||||||
|
self.host.pxe_key = ''
|
||||||
self.host.save()
|
self.host.save()
|
||||||
|
|
||||||
return self.host
|
return self.host
|
||||||
+1
-1
@@ -15,6 +15,6 @@ class HostPXEValidate(APIView):
|
|||||||
|
|
||||||
serializer.is_valid(raise_exception=True)
|
serializer.is_valid(raise_exception=True)
|
||||||
|
|
||||||
host = serializer.save() # sets Host.pxe_installable=False
|
serializer.save() # sets Host.pxe_installable=False
|
||||||
|
|
||||||
return Response({'valid_pxe_key': True})
|
return Response({'valid_pxe_key': True})
|
||||||
+1
-1
@@ -7,4 +7,4 @@ class MdbAppConfig(AppConfig):
|
|||||||
|
|
||||||
def ready(self):
|
def ready(self):
|
||||||
# all models are loaded, now attach signals
|
# all models are loaded, now attach signals
|
||||||
import mdb.signals
|
import mdb.signals # noqa
|
||||||
@@ -2738,6 +2738,18 @@
|
|||||||
"model": "mdb.operatingsystem",
|
"model": "mdb.operatingsystem",
|
||||||
"pk": 1
|
"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": {
|
"fields": {
|
||||||
"kerberos_principal_name": "",
|
"kerberos_principal_name": "",
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
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,15 +1,9 @@
|
|||||||
from __future__ import with_statement
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from difflib import context_diff
|
from difflib import context_diff
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
from django.core.mail import mail_admins
|
from django.core.mail import mail_admins
|
||||||
from optparse import make_option
|
from subprocess import getstatusoutput
|
||||||
try:
|
|
||||||
from subprocess import getstatusoutput
|
|
||||||
except ImportError:
|
|
||||||
from commands import getstatusoutput
|
|
||||||
|
|
||||||
from mdb.models import DhcpConfig
|
from mdb.models import DhcpConfig
|
||||||
|
|
||||||
@@ -18,29 +12,28 @@ class Command(BaseCommand):
|
|||||||
args = '--output <path> [--force] [--restart]'
|
args = '--output <path> [--force] [--restart]'
|
||||||
help = 'Generates the DHCP configuration'
|
help = 'Generates the DHCP configuration'
|
||||||
|
|
||||||
option_list = BaseCommand.option_list + (
|
def add_arguments(self, parser):
|
||||||
make_option('--output',
|
parser.add_argument('--output',
|
||||||
action='store',
|
action='store',
|
||||||
dest='output',
|
dest='output',
|
||||||
default=None,
|
default=None,
|
||||||
help='Path to dhcpd.conf, defaults to stdout'),
|
help='Path to dhcpd.conf, defaults to stdout'),
|
||||||
make_option('--force',
|
parser.add_argument('--force',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
dest='force',
|
dest='force',
|
||||||
default=False,
|
default=False,
|
||||||
help='Write configuration even if serial is unchanged.'),
|
help='Write configuration even if serial is unchanged.'),
|
||||||
make_option('--restart',
|
parser.add_argument('--restart',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
dest='restart',
|
dest='restart',
|
||||||
default=False,
|
default=False,
|
||||||
help='Restart dhcp3-server if serial is changed'),
|
help='Restart dhcp3-server if serial is changed'),
|
||||||
)
|
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
output = options['output'] if options['output'] else sys.stdout
|
output = options['output'] if options['output'] else sys.stdout
|
||||||
force = options['force']
|
force = options['force']
|
||||||
restart = options['restart']
|
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()
|
config = DhcpConfig.objects.filter(name="default").get()
|
||||||
|
|
||||||
@@ -67,13 +60,7 @@ class Command(BaseCommand):
|
|||||||
with open(output, 'w') as f:
|
with open(output, 'w') as f:
|
||||||
f.write(new)
|
f.write(new)
|
||||||
|
|
||||||
# calculate diff
|
diff = self.calculate_diff(config, new, old)
|
||||||
diff = "\n".join(context_diff(
|
|
||||||
a=old.splitlines(),
|
|
||||||
b=new.splitlines(),
|
|
||||||
fromfile=config.active_serial,
|
|
||||||
tofile=config.serial,
|
|
||||||
lineterm=''))
|
|
||||||
|
|
||||||
print(diff)
|
print(diff)
|
||||||
|
|
||||||
@@ -104,3 +91,11 @@ class Command(BaseCommand):
|
|||||||
message=message,
|
message=message,
|
||||||
html_message='<pre>%s</pre>' % message)
|
html_message='<pre>%s</pre>' % message)
|
||||||
sys.exit(0)
|
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 os
|
||||||
import sys
|
import sys
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
from difflib import context_diff
|
from difflib import context_diff
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
from django.core.mail import mail_admins
|
from django.core.mail import mail_admins
|
||||||
from optparse import make_option
|
from subprocess import getstatusoutput
|
||||||
try:
|
|
||||||
from subprocess import getstatusoutput
|
|
||||||
except ImportError:
|
|
||||||
from commands import getstatusoutput
|
|
||||||
|
|
||||||
from mdb.models import Domain, Ip4Subnet, Ip6Subnet
|
from mdb.models import Domain, Ip4Subnet, Ip6Subnet
|
||||||
|
|
||||||
@@ -19,50 +13,43 @@ class Command(BaseCommand):
|
|||||||
args = '[--force] [--debug]'
|
args = '[--force] [--debug]'
|
||||||
help = 'Generates the bind configuration'
|
help = 'Generates the bind configuration'
|
||||||
|
|
||||||
option_list = BaseCommand.option_list + (
|
rndc_bin = "/usr/sbin/rndc"
|
||||||
make_option('--debug',
|
reload_command = "%s reload" % rndc_bin
|
||||||
action='store_true',
|
freeze_command = "%s freeze" % rndc_bin
|
||||||
dest='debug',
|
thaw_command = "%s thaw" % rndc_bin
|
||||||
default=False,
|
commands_in_order = [freeze_command, reload_command, thaw_command]
|
||||||
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_bin = "/usr/sbin/named-checkzone"
|
||||||
checkzone_dir = "/tmp/mdb-checkzone"
|
checkzone_dir = "/tmp/mdb-checkzone"
|
||||||
debug = False
|
debug = False
|
||||||
|
force = False
|
||||||
debug_dir = '/tmp/mdb-debug'
|
debug_dir = '/tmp/mdb-debug'
|
||||||
changes = {}
|
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):
|
def handle(self, *args, **options):
|
||||||
self.debug = debug = options['debug']
|
self.debug = options['debug']
|
||||||
force = options['force']
|
self.force = options['force']
|
||||||
|
|
||||||
# do the binaries exist?
|
# do the binaries exist?
|
||||||
for f in (self.checkzone_bin, self.bind_bin):
|
self.validate_binaries_exist()
|
||||||
if not os.path.isfile(f):
|
|
||||||
print("ERROR: no such file %s, exiting..." % f)
|
|
||||||
if not debug:
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
# create directories if needed
|
# create directories if needed
|
||||||
os.path.isdir(self.checkzone_dir) or os.mkdir(self.checkzone_dir)
|
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
|
# update zones with new serials
|
||||||
for zone in chain(Domain.objects.all(),
|
self.update_zone_serials()
|
||||||
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
|
# join errors, diffs and zone names
|
||||||
errors = "\n\n\n".join(
|
errors = "\n\n\n".join(
|
||||||
@@ -72,35 +59,52 @@ class Command(BaseCommand):
|
|||||||
zones = ", ".join(self.changes.keys())
|
zones = ", ".join(self.changes.keys())
|
||||||
|
|
||||||
# reload and send email with changes
|
# reload and send email with changes
|
||||||
if self.changes and not debug:
|
if self.changes and not self.debug:
|
||||||
sys.stdout.write("reloading bind... ")
|
sys.stdout.write("reloading zones... ")
|
||||||
status, output = getstatusoutput(self.reload_command)
|
for command in self.commands_in_order:
|
||||||
if status != 0:
|
status, output = getstatusoutput(command)
|
||||||
sys.stdout.write("fail\n")
|
if status != 0:
|
||||||
message = (
|
sys.stdout.write("fail\n")
|
||||||
"Failed to reload bind, please inspect...\n\n" +
|
message = (
|
||||||
"%s@%s# %s" % (
|
"Failed to reload zones, please inspect...\n\n" +
|
||||||
os.getlogin(), os.uname()[1], self.reload_command) +
|
"%s@%s$ %s" % (
|
||||||
"\n%s\n\n\n%s\n\n\n%s" % (output, errors, diffs))
|
os.getlogin(), os.uname()[1], command) +
|
||||||
mail_admins(
|
"\n%s\n\n\n%s\n\n\n%s" % (output, errors, diffs))
|
||||||
subject="FAIL: bind (%s changed: %s)" % (len(self.changes), zones),
|
mail_admins(
|
||||||
message=message,
|
subject="FAIL: bind (%s changed: %s)" % (len(self.changes), zones),
|
||||||
html_message='<pre>%s</pre>' % message)
|
message=message,
|
||||||
sys.exit(1)
|
html_message='<pre>%s</pre>' % message)
|
||||||
else:
|
sys.exit(1)
|
||||||
sys.stdout.write("ok\n")
|
|
||||||
message = (
|
sys.stdout.write("ok\n")
|
||||||
"Successfully updated bind zone files\n\n" +
|
message = (
|
||||||
"%s\n\n%s" % (errors, diffs))
|
"Successfully updated bind zone files\n\n" +
|
||||||
mail_admins(
|
"%s\n\n%s" % (errors, diffs))
|
||||||
subject="Success: bind (%s changed: %s)" % (len(self.changes), zones),
|
mail_admins(
|
||||||
message=message,
|
subject="Success: bind (%s changed: %s)" % (len(self.changes), zones),
|
||||||
html_message='<pre>%s</pre>' % message)
|
message=message,
|
||||||
sys.exit(0)
|
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):
|
def update_zone(self, zone):
|
||||||
zonetype = getattr(zone._meta, 'verbose_name', None) \
|
zonetype = getattr(zone._meta, 'verbose_name', None) or zone._meta.model_name
|
||||||
or zone._meta.model_name
|
|
||||||
|
|
||||||
self.changes[zone.domain_name] = {
|
self.changes[zone.domain_name] = {
|
||||||
'old_serial': zone.domain_active_serial,
|
'old_serial': zone.domain_active_serial,
|
||||||
@@ -126,14 +130,7 @@ class Command(BaseCommand):
|
|||||||
except IOError:
|
except IOError:
|
||||||
old = ''
|
old = ''
|
||||||
|
|
||||||
# calculate diff
|
self.changes[zone.domain_name]['diff'] = self.calculate_diff(new, old, zone)
|
||||||
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
|
# validate with zonecheck
|
||||||
sys.stdout.write("\t- validating... ")
|
sys.stdout.write("\t- validating... ")
|
||||||
@@ -142,6 +139,7 @@ class Command(BaseCommand):
|
|||||||
sys.stdout.write("fail\n")
|
sys.stdout.write("fail\n")
|
||||||
self.changes[zone.domain_name]['errors'] = output
|
self.changes[zone.domain_name]['errors'] = output
|
||||||
return False
|
return False
|
||||||
|
|
||||||
sys.stdout.write("ok\n")
|
sys.stdout.write("ok\n")
|
||||||
|
|
||||||
# write to zone file
|
# write to zone file
|
||||||
@@ -166,10 +164,17 @@ class Command(BaseCommand):
|
|||||||
self.changes[zone.domain_name]['success'] = True
|
self.changes[zone.domain_name]['success'] = True
|
||||||
return 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):
|
def check_zone(self, zone, contents):
|
||||||
zonefile = self.checkzone_dir + '/' + zone.domain_name
|
zonefile = self.checkzone_dir + '/' + zone.domain_name
|
||||||
with open(zonefile, 'w') as f:
|
with open(zonefile, 'w') as f:
|
||||||
f.write(contents)
|
f.write(contents)
|
||||||
|
|
||||||
return getstatusoutput("%s %s %s" % (
|
return getstatusoutput("%s %s %s" % (self.checkzone_bin, zone.domain_name, zonefile))
|
||||||
self.checkzone_bin, zone.domain_name, zonefile))
|
|
||||||
@@ -81,7 +81,7 @@ class Migration(migrations.Migration):
|
|||||||
('name', models.CharField(max_length=256)),
|
('name', models.CharField(max_length=256)),
|
||||||
('target', models.CharField(max_length=256)),
|
('target', models.CharField(max_length=256)),
|
||||||
('created_date', models.DateTimeField(auto_now_add=True)),
|
('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={
|
options={
|
||||||
},
|
},
|
||||||
@@ -94,7 +94,7 @@ class Migration(migrations.Migration):
|
|||||||
('name', models.CharField(max_length=256)),
|
('name', models.CharField(max_length=256)),
|
||||||
('target', models.CharField(max_length=256)),
|
('target', models.CharField(max_length=256)),
|
||||||
('created_date', models.DateTimeField(auto_now_add=True)),
|
('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={
|
options={
|
||||||
},
|
},
|
||||||
@@ -112,7 +112,7 @@ class Migration(migrations.Migration):
|
|||||||
('port', models.IntegerField()),
|
('port', models.IntegerField()),
|
||||||
('target', models.CharField(max_length=256)),
|
('target', models.CharField(max_length=256)),
|
||||||
('created_date', models.DateTimeField(auto_now_add=True)),
|
('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={
|
options={
|
||||||
},
|
},
|
||||||
@@ -125,7 +125,7 @@ class Migration(migrations.Migration):
|
|||||||
('name', models.CharField(max_length=256)),
|
('name', models.CharField(max_length=256)),
|
||||||
('target', models.CharField(max_length=256)),
|
('target', models.CharField(max_length=256)),
|
||||||
('created_date', models.DateTimeField(auto_now_add=True)),
|
('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={
|
options={
|
||||||
},
|
},
|
||||||
@@ -174,8 +174,8 @@ class Migration(migrations.Migration):
|
|||||||
('pxe_filename', models.CharField(max_length=64, blank=True)),
|
('pxe_filename', models.CharField(max_length=64, blank=True)),
|
||||||
('dhcp_client', models.BooleanField(default=False)),
|
('dhcp_client', models.BooleanField(default=False)),
|
||||||
('created_date', models.DateTimeField(auto_now_add=True)),
|
('created_date', models.DateTimeField(auto_now_add=True)),
|
||||||
('domain', models.ForeignKey(to='mdb.Domain')),
|
('domain', models.ForeignKey(to='mdb.Domain', on_delete=models.CASCADE)),
|
||||||
('host', models.ForeignKey(to='mdb.Host')),
|
('host', models.ForeignKey(to='mdb.Host', on_delete=models.CASCADE)),
|
||||||
],
|
],
|
||||||
options={
|
options={
|
||||||
},
|
},
|
||||||
@@ -217,7 +217,7 @@ class Migration(migrations.Migration):
|
|||||||
('dhcp_dynamic', models.BooleanField(default=False)),
|
('dhcp_dynamic', models.BooleanField(default=False)),
|
||||||
('dhcp_dynamic_start', models.IPAddressField(null=True, blank=True)),
|
('dhcp_dynamic_start', models.IPAddressField(null=True, blank=True)),
|
||||||
('dhcp_dynamic_end', 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={
|
options={
|
||||||
'verbose_name': 'IPv4 subnet',
|
'verbose_name': 'IPv4 subnet',
|
||||||
@@ -229,7 +229,7 @@ class Migration(migrations.Migration):
|
|||||||
fields=[
|
fields=[
|
||||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||||
('address', models.CharField(max_length=64)),
|
('address', models.CharField(max_length=64)),
|
||||||
('interface', models.ForeignKey(to='mdb.Interface')),
|
('interface', models.ForeignKey(to='mdb.Interface', on_delete=models.CASCADE)),
|
||||||
],
|
],
|
||||||
options={
|
options={
|
||||||
'verbose_name': 'IPv6 address',
|
'verbose_name': 'IPv6 address',
|
||||||
@@ -309,7 +309,7 @@ class Migration(migrations.Migration):
|
|||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='operatingsystem',
|
model_name='operatingsystem',
|
||||||
name='architecture',
|
name='architecture',
|
||||||
field=models.ForeignKey(to='mdb.OsArchitecture'),
|
field=models.ForeignKey(to='mdb.OsArchitecture', on_delete=models.CASCADE),
|
||||||
preserve_default=True,
|
preserve_default=True,
|
||||||
),
|
),
|
||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
@@ -321,7 +321,7 @@ class Migration(migrations.Migration):
|
|||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='ip6address',
|
model_name='ip6address',
|
||||||
name='subnet',
|
name='subnet',
|
||||||
field=models.ForeignKey(to='mdb.Ip6Subnet'),
|
field=models.ForeignKey(to='mdb.Ip6Subnet', on_delete=models.CASCADE),
|
||||||
preserve_default=True,
|
preserve_default=True,
|
||||||
),
|
),
|
||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
@@ -333,25 +333,25 @@ class Migration(migrations.Migration):
|
|||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='ip4address',
|
model_name='ip4address',
|
||||||
name='subnet',
|
name='subnet',
|
||||||
field=models.ForeignKey(to='mdb.Ip4Subnet'),
|
field=models.ForeignKey(to='mdb.Ip4Subnet', on_delete=models.CASCADE),
|
||||||
preserve_default=True,
|
preserve_default=True,
|
||||||
),
|
),
|
||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='interface',
|
model_name='interface',
|
||||||
name='ip4address',
|
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,
|
preserve_default=True,
|
||||||
),
|
),
|
||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='host',
|
model_name='host',
|
||||||
name='host_type',
|
name='host_type',
|
||||||
field=models.ForeignKey(to='mdb.HostType'),
|
field=models.ForeignKey(to='mdb.HostType', on_delete=models.CASCADE),
|
||||||
preserve_default=True,
|
preserve_default=True,
|
||||||
),
|
),
|
||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='host',
|
model_name='host',
|
||||||
name='operating_system',
|
name='operating_system',
|
||||||
field=models.ForeignKey(to='mdb.OperatingSystem'),
|
field=models.ForeignKey(to='mdb.OperatingSystem', on_delete=models.CASCADE),
|
||||||
preserve_default=True,
|
preserve_default=True,
|
||||||
),
|
),
|
||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
@@ -369,13 +369,13 @@ class Migration(migrations.Migration):
|
|||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='dhcpoption',
|
model_name='dhcpoption',
|
||||||
name='ip4subnet',
|
name='ip4subnet',
|
||||||
field=models.ForeignKey(to='mdb.Ip4Subnet'),
|
field=models.ForeignKey(to='mdb.Ip4Subnet', on_delete=models.CASCADE),
|
||||||
preserve_default=True,
|
preserve_default=True,
|
||||||
),
|
),
|
||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='dhcpcustomfield',
|
model_name='dhcpcustomfield',
|
||||||
name='ip4subnet',
|
name='ip4subnet',
|
||||||
field=models.ForeignKey(to='mdb.Ip4Subnet'),
|
field=models.ForeignKey(to='mdb.Ip4Subnet', on_delete=models.CASCADE),
|
||||||
preserve_default=True,
|
preserve_default=True,
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
@@ -35,7 +35,7 @@ class Migration(migrations.Migration):
|
|||||||
migrations.AlterField(
|
migrations.AlterField(
|
||||||
model_name='interface',
|
model_name='interface',
|
||||||
name='ip4address',
|
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(
|
migrations.AlterField(
|
||||||
model_name='interface',
|
model_name='interface',
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ class Migration(migrations.Migration):
|
|||||||
('name', models.CharField(max_length=256)),
|
('name', models.CharField(max_length=256)),
|
||||||
('target', models.GenericIPAddressField(protocol='IPv6')),
|
('target', models.GenericIPAddressField(protocol='IPv6')),
|
||||||
('created_date', models.DateTimeField(auto_now_add=True)),
|
('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(
|
migrations.AlterField(
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
# -*- 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),
|
||||||
|
),
|
||||||
|
]
|
||||||
+24
-102
@@ -1,8 +1,6 @@
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models import Count
|
|
||||||
from django.utils.encoding import python_2_unicode_compatible
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from mdb.utils import host_as_pxe_files
|
from mdb.pxe import host_as_pxe_files
|
||||||
|
|
||||||
from mdb.validators import validate_hostname, validate_macaddr
|
from mdb.validators import validate_hostname, validate_macaddr
|
||||||
|
|
||||||
@@ -10,7 +8,6 @@ import ipaddress
|
|||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
|
||||||
class Nameserver(models.Model):
|
class Nameserver(models.Model):
|
||||||
hostname = models.CharField(max_length=256)
|
hostname = models.CharField(max_length=256)
|
||||||
|
|
||||||
@@ -18,7 +15,6 @@ class Nameserver(models.Model):
|
|||||||
return self.hostname
|
return self.hostname
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
|
||||||
class MailExchange(models.Model):
|
class MailExchange(models.Model):
|
||||||
priority = models.IntegerField()
|
priority = models.IntegerField()
|
||||||
hostname = models.CharField(max_length=256)
|
hostname = models.CharField(max_length=256)
|
||||||
@@ -27,7 +23,6 @@ class MailExchange(models.Model):
|
|||||||
return "(" + str(self.priority) + ") " + self.hostname
|
return "(" + str(self.priority) + ") " + self.hostname
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
|
||||||
class Domain(models.Model):
|
class Domain(models.Model):
|
||||||
domain_name = models.CharField(max_length=256)
|
domain_name = models.CharField(max_length=256)
|
||||||
domain_soa = models.CharField(max_length=256)
|
domain_soa = models.CharField(max_length=256)
|
||||||
@@ -50,18 +45,6 @@ class Domain(models.Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.domain_name
|
return self.domain_name
|
||||||
|
|
||||||
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):
|
def __eq__(self, other):
|
||||||
if not other or not hasattr(other, 'domain_name'):
|
if not other or not hasattr(other, 'domain_name'):
|
||||||
return False
|
return False
|
||||||
@@ -93,7 +76,7 @@ class Domain(models.Model):
|
|||||||
if self.domain_ipaddr is not None:
|
if self.domain_ipaddr is not None:
|
||||||
content += "@\tIN\tA\t%s\n" % self.domain_ipaddr
|
content += "@\tIN\tA\t%s\n" % self.domain_ipaddr
|
||||||
|
|
||||||
if self.domain_ip6addr is not None:
|
if self.domain_ip6addr:
|
||||||
content += "@\tIN\tAAAA\t%s\n" % self.domain_ip6addr
|
content += "@\tIN\tAAAA\t%s\n" % self.domain_ip6addr
|
||||||
|
|
||||||
content += "; SRV records\n"
|
content += "; SRV records\n"
|
||||||
@@ -137,7 +120,6 @@ class Domain(models.Model):
|
|||||||
return content
|
return content
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
|
||||||
class DomainSrvRecord(models.Model):
|
class DomainSrvRecord(models.Model):
|
||||||
srvce = models.CharField(max_length=64)
|
srvce = models.CharField(max_length=64)
|
||||||
prot = models.CharField(max_length=64)
|
prot = models.CharField(max_length=64)
|
||||||
@@ -146,7 +128,7 @@ class DomainSrvRecord(models.Model):
|
|||||||
weight = models.IntegerField()
|
weight = models.IntegerField()
|
||||||
port = models.IntegerField()
|
port = models.IntegerField()
|
||||||
target = 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)
|
created_date = models.DateTimeField(auto_now_add=True)
|
||||||
|
|
||||||
def as_record(self):
|
def as_record(self):
|
||||||
@@ -165,11 +147,10 @@ class DomainSrvRecord(models.Model):
|
|||||||
return self.as_record()
|
return self.as_record()
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
|
||||||
class DomainTxtRecord(models.Model):
|
class DomainTxtRecord(models.Model):
|
||||||
name = models.CharField(max_length=256)
|
name = models.CharField(max_length=256)
|
||||||
target = 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)
|
created_date = models.DateTimeField(auto_now_add=True)
|
||||||
|
|
||||||
def as_record(self):
|
def as_record(self):
|
||||||
@@ -179,11 +160,10 @@ class DomainTxtRecord(models.Model):
|
|||||||
return self.as_record()
|
return self.as_record()
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
|
||||||
class DomainCnameRecord(models.Model):
|
class DomainCnameRecord(models.Model):
|
||||||
name = models.CharField(max_length=256)
|
name = models.CharField(max_length=256)
|
||||||
target = 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)
|
created_date = models.DateTimeField(auto_now_add=True)
|
||||||
|
|
||||||
def as_record(self):
|
def as_record(self):
|
||||||
@@ -193,11 +173,10 @@ class DomainCnameRecord(models.Model):
|
|||||||
return self.as_record()
|
return self.as_record()
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
|
||||||
class DomainARecord(models.Model):
|
class DomainARecord(models.Model):
|
||||||
name = models.CharField(max_length=256)
|
name = models.CharField(max_length=256)
|
||||||
target = models.GenericIPAddressField(protocol='IPv4')
|
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)
|
created_date = models.DateTimeField(auto_now_add=True)
|
||||||
|
|
||||||
def as_record(self):
|
def as_record(self):
|
||||||
@@ -207,11 +186,10 @@ class DomainARecord(models.Model):
|
|||||||
return self.as_record()
|
return self.as_record()
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
|
||||||
class DomainAAAARecord(models.Model):
|
class DomainAAAARecord(models.Model):
|
||||||
name = models.CharField(max_length=256)
|
name = models.CharField(max_length=256)
|
||||||
target = models.GenericIPAddressField(protocol='IPv6')
|
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)
|
created_date = models.DateTimeField(auto_now_add=True)
|
||||||
|
|
||||||
def as_record(self):
|
def as_record(self):
|
||||||
@@ -221,7 +199,6 @@ class DomainAAAARecord(models.Model):
|
|||||||
return self.as_record()
|
return self.as_record()
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
|
||||||
class DhcpConfig(models.Model):
|
class DhcpConfig(models.Model):
|
||||||
serial = models.IntegerField()
|
serial = models.IntegerField()
|
||||||
active_serial = models.IntegerField()
|
active_serial = models.IntegerField()
|
||||||
@@ -283,7 +260,6 @@ class DhcpConfig(models.Model):
|
|||||||
verbose_name = 'DHCP config'
|
verbose_name = 'DHCP config'
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
|
||||||
class Ip6Subnet(models.Model):
|
class Ip6Subnet(models.Model):
|
||||||
name = models.CharField(max_length=255)
|
name = models.CharField(max_length=255)
|
||||||
network = models.CharField(max_length=255)
|
network = models.CharField(max_length=255)
|
||||||
@@ -332,7 +308,7 @@ class Ip6Subnet(models.Model):
|
|||||||
# content += "$ORIGIN " + ".".join(network.exploded.replace(":","")[:16])[::-1] + ".ip6.arpa.\n"
|
# content += "$ORIGIN " + ".".join(network.exploded.replace(":","")[:16])[::-1] + ".ip6.arpa.\n"
|
||||||
|
|
||||||
for addr in self.ip6address_set.all():
|
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:
|
if addr.interface.domain is None:
|
||||||
continue
|
continue
|
||||||
@@ -353,7 +329,6 @@ class Ip6Subnet(models.Model):
|
|||||||
verbose_name = 'IPv6 subnet'
|
verbose_name = 'IPv6 subnet'
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
|
||||||
class Ip4Subnet(models.Model):
|
class Ip4Subnet(models.Model):
|
||||||
name = models.CharField(max_length=256)
|
name = models.CharField(max_length=256)
|
||||||
netmask = models.GenericIPAddressField(protocol='IPv4')
|
netmask = models.GenericIPAddressField(protocol='IPv4')
|
||||||
@@ -375,32 +350,11 @@ class Ip4Subnet(models.Model):
|
|||||||
dhcp_dynamic = models.BooleanField(default=False)
|
dhcp_dynamic = models.BooleanField(default=False)
|
||||||
dhcp_dynamic_start = models.GenericIPAddressField(protocol='IPv4', null=True, blank=True)
|
dhcp_dynamic_start = models.GenericIPAddressField(protocol='IPv4', null=True, blank=True)
|
||||||
dhcp_dynamic_end = 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):
|
def __str__(self):
|
||||||
return self.network + " (" + self.name + ")"
|
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):
|
def zone_file_contents(self, generate_unassigned=False):
|
||||||
content = ""
|
content = ""
|
||||||
content += "; zone file for %s\n" % self.domain_name
|
content += "; zone file for %s\n" % self.domain_name
|
||||||
@@ -443,11 +397,10 @@ class Ip4Subnet(models.Model):
|
|||||||
verbose_name = 'IPv4 subnet'
|
verbose_name = 'IPv4 subnet'
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
|
||||||
class DhcpOption(models.Model):
|
class DhcpOption(models.Model):
|
||||||
key = models.CharField(max_length=255)
|
key = models.CharField(max_length=255)
|
||||||
value = 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):
|
def __str__(self):
|
||||||
return self.key + " " + self.value
|
return self.key + " " + self.value
|
||||||
@@ -458,37 +411,26 @@ class DhcpOption(models.Model):
|
|||||||
|
|
||||||
class DhcpCustomField(models.Model):
|
class DhcpCustomField(models.Model):
|
||||||
value = models.CharField(max_length=255)
|
value = models.CharField(max_length=255)
|
||||||
ip4subnet = models.ForeignKey(Ip4Subnet)
|
ip4subnet = models.ForeignKey(Ip4Subnet, on_delete=models.CASCADE)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = 'DHCP custom field'
|
verbose_name = 'DHCP custom field'
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
|
||||||
class Ip4Address(models.Model):
|
class Ip4Address(models.Model):
|
||||||
subnet = models.ForeignKey(Ip4Subnet)
|
subnet = models.ForeignKey(Ip4Subnet, on_delete=models.CASCADE)
|
||||||
address = models.GenericIPAddressField(protocol='IPv4')
|
address = models.GenericIPAddressField(protocol='IPv4')
|
||||||
last_contact = models.DateTimeField(null=True, blank=True)
|
last_contact = models.DateTimeField(null=True, blank=True)
|
||||||
ping_avg_rtt = models.FloatField(null=True, blank=True)
|
ping_avg_rtt = models.FloatField(null=True, blank=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
# FIXME: generates 2 SQL queries?
|
return self.address
|
||||||
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:
|
class Meta:
|
||||||
verbose_name = 'IPv4 address'
|
verbose_name = 'IPv4 address'
|
||||||
verbose_name_plural = 'IPv4 addresses'
|
verbose_name_plural = 'IPv4 addresses'
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
|
||||||
class HostType(models.Model):
|
class HostType(models.Model):
|
||||||
host_type = models.CharField(max_length=64)
|
host_type = models.CharField(max_length=64)
|
||||||
description = models.CharField(max_length=1024)
|
description = models.CharField(max_length=1024)
|
||||||
@@ -503,7 +445,6 @@ class HostType(models.Model):
|
|||||||
ordering = ("host_type",)
|
ordering = ("host_type",)
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
|
||||||
class OperatingSystem(models.Model):
|
class OperatingSystem(models.Model):
|
||||||
OS_ARCHITECTURES = (
|
OS_ARCHITECTURES = (
|
||||||
('mips', _('MIPS')),
|
('mips', _('MIPS')),
|
||||||
@@ -520,6 +461,10 @@ class OperatingSystem(models.Model):
|
|||||||
version = models.CharField(max_length=64)
|
version = models.CharField(max_length=64)
|
||||||
arch = models.CharField(max_length=255, choices=OS_ARCHITECTURES, blank=True, null=True)
|
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):
|
def __str__(self):
|
||||||
return self.name + " " + self.version + " (" + self.arch + ")"
|
return self.name + " " + self.version + " (" + self.arch + ")"
|
||||||
|
|
||||||
@@ -527,7 +472,6 @@ class OperatingSystem(models.Model):
|
|||||||
ordering = ("name", "version")
|
ordering = ("name", "version")
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
|
||||||
class Host(models.Model):
|
class Host(models.Model):
|
||||||
location = models.CharField(max_length=1024)
|
location = models.CharField(max_length=1024)
|
||||||
brand = models.CharField(max_length=1024)
|
brand = models.CharField(max_length=1024)
|
||||||
@@ -537,9 +481,9 @@ class Host(models.Model):
|
|||||||
serial_number = models.CharField(max_length=256)
|
serial_number = models.CharField(max_length=256)
|
||||||
description = models.CharField(max_length=1024)
|
description = models.CharField(max_length=1024)
|
||||||
created_date = models.DateTimeField(auto_now_add=True)
|
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)
|
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)
|
request_kerberos_principal = models.BooleanField(default=False)
|
||||||
kerberos_principal_created = models.BooleanField(default=False, editable=False)
|
kerberos_principal_created = models.BooleanField(default=False, editable=False)
|
||||||
@@ -552,40 +496,19 @@ class Host(models.Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.hostname
|
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):
|
def as_pxe_files(self):
|
||||||
return host_as_pxe_files(self)
|
return host_as_pxe_files(self)
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
|
||||||
class Interface(models.Model):
|
class Interface(models.Model):
|
||||||
name = models.CharField(max_length=128)
|
name = models.CharField(max_length=128)
|
||||||
macaddr = models.CharField(max_length=17, validators=[validate_macaddr])
|
macaddr = models.CharField(max_length=17, validators=[validate_macaddr])
|
||||||
pxe_filename = models.CharField(max_length=64, blank=True)
|
pxe_filename = models.CharField(max_length=64, blank=True)
|
||||||
dhcp_client = models.BooleanField(default=False)
|
dhcp_client = models.BooleanField(default=False)
|
||||||
host = models.ForeignKey(Host)
|
host = models.ForeignKey(Host, on_delete=models.CASCADE)
|
||||||
ip4address = models.OneToOneField(Ip4Address, blank=True, null=True)
|
ip4address = models.OneToOneField(Ip4Address, blank=True, null=True, on_delete=models.SET_NULL)
|
||||||
created_date = models.DateTimeField(auto_now_add=True)
|
created_date = models.DateTimeField(auto_now_add=True)
|
||||||
domain = models.ForeignKey(Domain)
|
domain = models.ForeignKey(Domain, on_delete=models.CASCADE)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "%s (%s on %s)" % (self.macaddr, self.name, self.host.hostname)
|
return "%s (%s on %s)" % (self.macaddr, self.name, self.host.hostname)
|
||||||
@@ -594,11 +517,10 @@ class Interface(models.Model):
|
|||||||
return self.ip6address_set.exists()
|
return self.ip6address_set.exists()
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
|
||||||
class Ip6Address(models.Model):
|
class Ip6Address(models.Model):
|
||||||
subnet = models.ForeignKey(Ip6Subnet)
|
subnet = models.ForeignKey(Ip6Subnet, on_delete=models.CASCADE)
|
||||||
address = models.GenericIPAddressField(protocol='IPv6')
|
address = models.GenericIPAddressField(protocol='IPv6')
|
||||||
interface = models.ForeignKey(Interface)
|
interface = models.ForeignKey(Interface, on_delete=models.CASCADE)
|
||||||
|
|
||||||
def full_address(self):
|
def full_address(self):
|
||||||
return self.subnet.network + self.address
|
return self.subnet.network + self.address
|
||||||
|
|||||||
+58
@@ -0,0 +1,58 @@
|
|||||||
|
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,9 +98,11 @@ 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():
|
for pxe_file_name, pxe_file in host.as_pxe_files():
|
||||||
path = os.path.join(settings.MDB_PXE_TFTP_ROOT, pxe_file_name)
|
path = os.path.join(settings.MDB_PXE_TFTP_ROOT, pxe_file_name)
|
||||||
if host.pxe_installable:
|
if host.pxe_installable:
|
||||||
|
# Write pxeconfig file to disk
|
||||||
with open(path, 'w+') as f:
|
with open(path, 'w+') as f:
|
||||||
f.write(pxe_file)
|
f.write(pxe_file)
|
||||||
logger.info("Created or updated {}".format(path))
|
logger.info("Created or updated {}".format(path))
|
||||||
|
os.chmod(path, 0o644) # Not writeable for all
|
||||||
|
|
||||||
# Also set necessary fields for pxe installation
|
# Also set necessary fields for pxe installation
|
||||||
interfaces = host.interface_set.exclude(ip4address__isnull=True)
|
interfaces = host.interface_set.exclude(ip4address__isnull=True)
|
||||||
@@ -119,6 +121,7 @@ def create_pxe_key_and_write_pxe_files_when_host_changes(sender, instance, creat
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
|
# Delete pxeconfig file from disk
|
||||||
os.unlink(path)
|
os.unlink(path)
|
||||||
logger.info("deleted {}".format(path))
|
logger.info("deleted {}".format(path))
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
kernel {{kernel}}
|
default ninja
|
||||||
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
|
prompt 0
|
||||||
timeout 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
|
||||||
+27
-3
@@ -1,12 +1,15 @@
|
|||||||
import io
|
import io
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.core.management import call_command
|
from django.core.management import call_command
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
from mdb.pxe import render_pxelinux_cfg
|
||||||
from rest_framework.authtoken.models import Token
|
from rest_framework.authtoken.models import Token
|
||||||
from rest_framework.test import APITestCase
|
from rest_framework.test import APITestCase
|
||||||
|
|
||||||
from mdb.models import Host
|
from mdb.models import Host, OperatingSystem
|
||||||
|
|
||||||
|
|
||||||
class MyAPITestCases(APITestCase):
|
class MyAPITestCases(APITestCase):
|
||||||
@@ -35,6 +38,27 @@ class MyAPITestCases(APITestCase):
|
|||||||
class UnitTests(TestCase):
|
class UnitTests(TestCase):
|
||||||
fixtures = ['test_data']
|
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):
|
def test_host_as_pxe_files(self):
|
||||||
host = Host.objects.first()
|
host = Host.objects.first()
|
||||||
self.assertEqual(len(host.as_pxe_files()), 1)
|
self.assertEqual(len(host.as_pxe_files()), 1)
|
||||||
@@ -44,13 +68,13 @@ class RunManagementCommands(TestCase):
|
|||||||
fixtures = ['test_data']
|
fixtures = ['test_data']
|
||||||
|
|
||||||
def test_zone_sync(self):
|
def test_zone_sync(self):
|
||||||
expected_zone_file = ''
|
# expected_zone_file = ''
|
||||||
with io.BytesIO() as f:
|
with io.BytesIO() as f:
|
||||||
call_command('zone-sync', debug=True, stdout=f)
|
call_command('zone-sync', debug=True, stdout=f)
|
||||||
# TODO check expected_zone_file
|
# TODO check expected_zone_file
|
||||||
|
|
||||||
def test_dhcp_sync(self):
|
def test_dhcp_sync(self):
|
||||||
expected_dhcp_file = ''
|
# expected_dhcp_file = ''
|
||||||
with io.BytesIO() as f:
|
with io.BytesIO() as f:
|
||||||
call_command('dhcp-sync', stdout=f)
|
call_command('dhcp-sync', stdout=f)
|
||||||
# TODO check expected_dhcp_file
|
# TODO check expected_dhcp_file
|
||||||
+1
-48
@@ -1,7 +1,4 @@
|
|||||||
import datetime
|
import datetime
|
||||||
from django.conf import settings
|
|
||||||
from django.template.loader import render_to_string
|
|
||||||
import ipaddress
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
||||||
@@ -20,7 +17,7 @@ def format_domain_serial_and_add_one(serial):
|
|||||||
""" The serial contains todays date, just update it. """
|
""" The serial contains todays date, just update it. """
|
||||||
try:
|
try:
|
||||||
number = int(res[0])
|
number = int(res[0])
|
||||||
except:
|
except ValueError:
|
||||||
number = 1
|
number = 1
|
||||||
if number >= 99:
|
if number >= 99:
|
||||||
""" This is bad... Just keep the number on 99.
|
""" This is bad... Just keep the number on 99.
|
||||||
@@ -35,47 +32,3 @@ def format_domain_serial_and_add_one(serial):
|
|||||||
""" Just return the first serial for today. """
|
""" Just return the first serial for today. """
|
||||||
return "%4d%02d%02d%02d" % \
|
return "%4d%02d%02d%02d" % \
|
||||||
(today.year, today.month, today.day, 1)
|
(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,4 +1,3 @@
|
|||||||
from __future__ import unicode_literals
|
|
||||||
from django.core.validators import RegexValidator
|
from django.core.validators import RegexValidator
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
|||||||
+76
-22
@@ -1,5 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS as TCP
|
import raven
|
||||||
|
|
||||||
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
|
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_ROOT = os.path.join(BASE_DIR, 'staticfiles')
|
||||||
STATIC_URL = '/static/'
|
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 = (
|
STATICFILES_FINDERS = (
|
||||||
'django.contrib.staticfiles.finders.FileSystemFinder',
|
'django.contrib.staticfiles.finders.FileSystemFinder',
|
||||||
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
|
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
|
||||||
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Make this unique, and don't share it with anybody.
|
# Make this unique, and don't share it with anybody.
|
||||||
SECRET_KEY = '@4ps=ebofcpv8sb#y7gm896=l&l*u0u-pgo7bcdj%+(k+2lqnl'
|
SECRET_KEY = '@4ps=ebofcpv8sb#y7gm896=l&l*u0u-pgo7bcdj%+(k+2lqnl'
|
||||||
|
|
||||||
MIDDLEWARE_CLASSES = (
|
MIDDLEWARE = [
|
||||||
'django.middleware.common.CommonMiddleware',
|
'django.middleware.common.CommonMiddleware',
|
||||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||||
'django.middleware.csrf.CsrfViewMiddleware',
|
'django.middleware.csrf.CsrfViewMiddleware',
|
||||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||||
'django.contrib.messages.middleware.MessageMiddleware',
|
'django.contrib.messages.middleware.MessageMiddleware',
|
||||||
)
|
]
|
||||||
|
|
||||||
ROOT_URLCONF = 'mdbsite.urls'
|
ROOT_URLCONF = 'mdbsite.urls'
|
||||||
|
|
||||||
TEMPLATE_DIRS = (
|
TEMPLATES = [
|
||||||
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
|
{
|
||||||
# Always use forward slashes, even on Windows.
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||||
# Don't forget to use absolute paths, not relative paths.
|
'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 = (
|
INSTALLED_APPS = (
|
||||||
'django.contrib.auth',
|
'django.contrib.auth',
|
||||||
@@ -76,15 +78,56 @@ INSTALLED_APPS = (
|
|||||||
'django.contrib.admin',
|
'django.contrib.admin',
|
||||||
'rest_framework',
|
'rest_framework',
|
||||||
'rest_framework.authtoken',
|
'rest_framework.authtoken',
|
||||||
|
'django_extensions',
|
||||||
|
'raven.contrib.django.raven_compat',
|
||||||
'mdb',
|
'mdb',
|
||||||
)
|
)
|
||||||
|
|
||||||
EMAIL_SUBJECT_PREFIX = '[MDB] '
|
EMAIL_SUBJECT_PREFIX = '[MDB] '
|
||||||
|
|
||||||
TEMPLATE_CONTEXT_PROCESSORS = TCP + (
|
# Logging
|
||||||
'django.core.context_processors.request', # for django-suit
|
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
|
# django-suit configuration
|
||||||
SUIT_CONFIG = {
|
SUIT_CONFIG = {
|
||||||
@@ -115,16 +158,27 @@ SUIT_CONFIG = {
|
|||||||
),
|
),
|
||||||
|
|
||||||
# misc
|
# misc
|
||||||
'LIST_PER_PAGE': 30
|
'LIST_PER_PAGE': 35
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# REST Framework
|
||||||
REST_FRAMEWORK = {
|
REST_FRAMEWORK = {
|
||||||
'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAuthenticated',),
|
'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAuthenticated',),
|
||||||
'PAGINATE_BY': 10
|
'PAGINATE_BY': 10
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# PXE
|
||||||
MDB_PXE_TFTP_ROOT = '/var/lib/tftpboot/pxelinux/pxelinux.cfg/'
|
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'
|
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:
|
try:
|
||||||
from .local_settings import *
|
from .local_settings import *
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
|||||||
+4
-4
@@ -1,15 +1,15 @@
|
|||||||
from django.conf.urls import include, url
|
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
|
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
|
||||||
|
from django.urls import re_path, path
|
||||||
from django.views.generic.base import RedirectView
|
from django.views.generic.base import RedirectView
|
||||||
from mdb.api.views import HostPXEValidate
|
from mdb.api.views import HostPXEValidate
|
||||||
|
|
||||||
admin.autodiscover()
|
admin.autodiscover()
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^$', RedirectView.as_view(url='admin/', permanent=True)),
|
re_path(r'^$', RedirectView.as_view(url='admin/', permanent=True)),
|
||||||
url(r'^admin/', include(admin.site.urls)),
|
path('admin/', admin.site.urls),
|
||||||
url(r'^api/validate-host-secret/', HostPXEValidate.as_view(), name='api-validate-host-secret')
|
path('api/validate-host-secret/', HostPXEValidate.as_view(), name='api-validate-host-secret')
|
||||||
]
|
]
|
||||||
|
|
||||||
urlpatterns += staticfiles_urlpatterns()
|
urlpatterns += staticfiles_urlpatterns()
|
||||||
+4
-3
@@ -1,5 +1,6 @@
|
|||||||
import os
|
|
||||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mdb.settings")
|
|
||||||
|
|
||||||
from django.core.wsgi import get_wsgi_application
|
from django.core.wsgi import get_wsgi_application
|
||||||
|
import os
|
||||||
|
|
||||||
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mdbsite.settings")
|
||||||
|
|
||||||
application = get_wsgi_application()
|
application = get_wsgi_application()
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
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