1 | from django.contrib import admin
|
---|
2 | from django.contrib import databrowse
|
---|
3 | from django import forms
|
---|
4 | from exodus.models import *
|
---|
5 |
|
---|
6 | from exodus.wllogic import free_masterip, newSSIDName, addInterlinkIP, \
|
---|
7 | freeInterlinkIP, freePublicAPIP
|
---|
8 |
|
---|
9 | from exodus.contrib import ReadOnlyAdminFields
|
---|
10 |
|
---|
11 | class InterfaceCommon(ReadOnlyAdminFields):
|
---|
12 | readonly = ('ip', )
|
---|
13 | def save_model(self, request, obj, form, change):
|
---|
14 | if obj.link and (obj.type != obj.link.type):
|
---|
15 | raise ValueError,'Type of local and remote interface needs to match'
|
---|
16 | if str(obj.type) != "eth":
|
---|
17 | obj.ssid = newSSIDName(obj.node, obj.iface, 'unused')
|
---|
18 | obj.channel = '1'
|
---|
19 | obj.mode = 1 # set to master
|
---|
20 |
|
---|
21 | # Only change IP if changes in interface link/mask or new of course :-)
|
---|
22 | #if change or self.is_changed.has_key('link') or \
|
---|
23 | # self.is_changed.has_key('netmask'):
|
---|
24 | if not obj.link:
|
---|
25 | obj.ip = freeInterlinkIP(obj)
|
---|
26 | else:
|
---|
27 | obj.ip = addInterlinkIP(obj.link)
|
---|
28 |
|
---|
29 | # XXX: Change in netmask requires full range of netmask changes \
|
---|
30 | # on slaves
|
---|
31 | obj.save()
|
---|
32 | #Dirty to hack to get reference to self working
|
---|
33 | if not obj.link:
|
---|
34 | obj.link = obj
|
---|
35 | obj.save()
|
---|
36 |
|
---|
37 |
|
---|
38 | class PublicAPInline(ReadOnlyAdminFields,admin.TabularInline):
|
---|
39 | model = PublicAP
|
---|
40 | extra = 1
|
---|
41 |
|
---|
42 | class InterfaceAdmin(InterfaceCommon, admin.ModelAdmin):
|
---|
43 | inlines = (PublicAPInline,)
|
---|
44 | pass
|
---|
45 |
|
---|
46 | class InterfaceInline(InterfaceCommon, admin.TabularInline):
|
---|
47 | model = Interface
|
---|
48 | extra = 1
|
---|
49 |
|
---|
50 | class DhcpStaticInline(admin.TabularInline):
|
---|
51 | model = DhcpStatic
|
---|
52 | extra = 1
|
---|
53 |
|
---|
54 | class PublicAPAdmin(ReadOnlyAdminFields,admin.ModelAdmin):
|
---|
55 | inlines = (DhcpStaticInline,)
|
---|
56 |
|
---|
57 | class NodeAdmin(admin.ModelAdmin):
|
---|
58 | exclude = ('masterip',)
|
---|
59 | # Inline forms sucks bigtime, editing deleting, making readonly broken or non existing
|
---|
60 | # XXX: Every save creates a new interface :-(
|
---|
61 | inlines = (InterfaceInline,)
|
---|
62 |
|
---|
63 | def save_model(self, request, obj, form, change):
|
---|
64 | #XXX: Testing hidden field commits
|
---|
65 | obj.masterip = free_masterip(obj.network)
|
---|
66 | obj.save()
|
---|
67 |
|
---|
68 | admin.site.register(Antenna)
|
---|
69 | admin.site.register(Location)
|
---|
70 | admin.site.register(DnsServer)
|
---|
71 | admin.site.register(Network)
|
---|
72 | admin.site.register(Node,NodeAdmin)
|
---|
73 | admin.site.register(Interface,InterfaceAdmin)
|
---|
74 | admin.site.register(PublicAP, PublicAPAdmin)
|
---|
75 | admin.site.register(DhcpStatic)
|
---|
76 |
|
---|
77 | databrowse.site.register(Antenna)
|
---|
78 | databrowse.site.register(Location)
|
---|
79 | databrowse.site.register(DnsServer)
|
---|
80 | databrowse.site.register(Network)
|
---|
81 | databrowse.site.register(Node)
|
---|
82 | databrowse.site.register(Interface)
|
---|
83 | databrowse.site.register(PublicAP)
|
---|
84 | databrowse.site.register(DhcpStatic)
|
---|