source: branches/exodus-roland/exodus/models.py@ 6411

Last change on this file since 6411 was 6411, checked in by roland, 16 years ago

A check in with some addons, still code in progress.
Some niceties in admin.

File size: 4.5 KB
Line 
1# (c) Roland van Laar 2006
2# vi:et:ts=4
3from django.db import models
4from django.contrib import admin
5from django import forms
6
7
8#No need to formalize it; CHOICES don't change much
9
10STATUS_CHOICES = (
11 ('up', 'up'),
12 ('dw', 'down'),
13 ('pl', 'planned'),
14 )
15
16POLAR_CHOICES = (
17 ('hr', 'horizontal'),
18 ('vr', 'vertical'),
19 )
20
21INTERFACE_TYPE_CHOICES = (
22 ('eth', 'eth'),
23 ('11a', '11a'),
24 ('11b', '11b'),
25 ('11g', '11g'),
26 )
27WIFI_MODE_CHOICES = (
28 ('ms', 'master'),
29 ('mn', 'managed'),
30 )
31
32class Antenna(models.Model):
33 type = models.CharField(max_length=20, unique=True)
34 gain = models.IntegerField(max_length=3)
35
36 class Meta:
37 verbose_name = 'Antenna'
38
39 def __str__(self):
40 return self.type
41
42class Location(models.Model):
43 description = models.CharField(max_length=200, unique=True)
44 longitude = models.DecimalField(max_digits=8,decimal_places=6)
45 latitude = models.DecimalField(max_digits=8,decimal_places=6)
46
47 class Meta:
48 verbose_name = 'Location'
49
50 def __str__(self):
51 return self.description
52
53
54#XXX: Name Domain perhaps?
55class DnsServer(models.Model):
56 ipaddress = models.IPAddressField()
57 domainname = models.CharField(max_length=50, unique=True)
58
59 class Meta:
60 verbose_name = 'Dns Server'
61
62 def __str__(self):
63 return "%s, %s"% (self.domainname, self.ipaddress )
64
65
66class Network(models.Model):
67 name = models.CharField(max_length=50, unique=True)
68 ipspacestart = models.IPAddressField()
69 netmask = models.IntegerField()
70
71 class Meta:
72 verbose_name = 'Network'
73
74 def __str__(self):
75 return self.name
76
77class Node(models.Model):
78 name = models.CharField(max_length=30, unique=True)
79 location = models.ForeignKey(Location)
80 status = models.CharField(max_length=10, choices=STATUS_CHOICES , \
81 default='up')
82 masterip = models.IPAddressField(unique=True)
83 network = models.ForeignKey(Network,default=1)
84
85 class Meta:
86 ordering = ['name']
87 verbose_name = 'Node'
88
89 def __str__(self):
90 return self.name
91
92
93class Interface(models.Model):
94 node = models.ForeignKey(Node)
95 type = models.CharField(max_length=10, choices=INTERFACE_TYPE_CHOICES, \
96 default='eth')
97 iface = models.CharField(max_length=10, verbose_name="interface", \
98 default='eth0')
99 ip = models.IPAddressField(unique=True, blank=True)
100 netmask = models.IntegerField(default=30)
101 polar = models.CharField(blank=True, max_length=10, choices=POLAR_CHOICES)
102 ssid = models.CharField(max_length=30, blank=True, null=True)
103 mode = models.CharField(max_length=10, choices=WIFI_MODE_CHOICES, blank=True)
104 channel = models.IntegerField(blank=True, null=True)
105 antenna = models.ForeignKey(Antenna, blank=True, null=True)
106 shortdesc = models.CharField(blank=True, max_length=10)
107 desc = models.CharField(blank=True, max_length=100)
108 link = models.ForeignKey('self', blank=True, null=True)
109
110 class Meta:
111 #unique_together = ('node', 'iface')
112 verbose_name = 'Interface'
113
114 def __str__(self):
115 return "%s/%s" % (self.node, self.iface)
116
117class InterfaceAlias(models.Model):
118 iface = models.ForeignKey(Interface,related_name='child')
119 ip = models.IPAddressField(unique=True)
120 netmask = models.IntegerField(default=30)
121 shortdesc = models.CharField(blank=True, max_length=10)
122 desc = models.CharField(blank=True, max_length=100)
123 linkAlias = models.ForeignKey('self', blank=True, null=True)
124 link = models.ForeignKey(Interface, blank=True, null=True)
125
126 def __str__(self):
127 return "Alias %s" % (self.iface)
128
129#
130# XXX: Needs rethinking, dhcp[start|stop] could be removed if whole publicAP is
131# going to be activated as DHCP range, or only number of fixed clients needs to
132# be defined, all other could be calculated on the fly if needed
133
134class PublicAP(models.Model):
135 iface = models.ForeignKey(Interface,related_name='ap', verbose_name="interface")
136 ip = models.IPAddressField(unique=True)
137 netmask = models.IntegerField(default=28)
138 dhcpstart = models.IPAddressField()
139 dhcpstop = models.IPAddressField()
140 shortdesc = models.CharField(max_length=10)
141 desc = models.CharField(max_length=100)
142
143 class Meta:
144 verbose_name = "Public Access Point"
145
146 def __str__(self):
147 return "%s:%s" % (self.iface,self.pk)
148
149class DhcpStatic(models.Model):
150 hostname = models.CharField(max_length=10,unique=True)
151 macaddress = models.CharField(max_length=17)
152 address = models.IPAddressField()
153 PublicAP = models.ForeignKey(PublicAP)
154
155 class Meta:
156 verbose_name = "Static host"
157
158 def __str__(self):
159 return self.hostname
Note: See TracBrowser for help on using the repository browser.