Revision a24fbf37

b/flowspec/admin.py
1
from django.contrib import admin
2
from flowspy.flowspec.models import *
3

  
4
admin.site.register(MatchAddress)
5
admin.site.register(MatchPort)
6
admin.site.register(MatchDscp)
7
admin.site.register(MatchFragmentType)
8
admin.site.register(MatchIcmpCode)
9
admin.site.register(MatchIcmpType)
10
admin.site.register(MatchPacketLength)
11
admin.site.register(MatchProtocol)
12
admin.site.register(MatchTcpFlag)
13
admin.site.register(ThenAction)
14
admin.site.register(ThenStatement)
15
admin.site.register(MatchStatement)
16
admin.site.register(Route)
/dev/null
1
# encoding: utf-8
2
import datetime
3
from south.db import db
4
from south.v2 import SchemaMigration
5
from django.db import models
6

  
7
class Migration(SchemaMigration):
8
    
9
    def forwards(self, orm):
10
        
11
        # Adding model 'MatchAddress'
12
        db.create_table(u'match_address', (
13
            ('destination', self.gf('django.db.models.fields.CharField')(max_length=255)),
14
            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
15
        ))
16
        db.send_create_signal('flowspec', ['MatchAddress'])
17

  
18
        # Adding model 'MatchPort'
19
        db.create_table(u'match_port', (
20
            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
21
            ('port', self.gf('django.db.models.fields.CharField')(max_length=24)),
22
        ))
23
        db.send_create_signal('flowspec', ['MatchPort'])
24

  
25
        # Adding model 'MatchDscp'
26
        db.create_table(u'match_dscp', (
27
            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
28
            ('dscp', self.gf('django.db.models.fields.CharField')(max_length=24)),
29
        ))
30
        db.send_create_signal('flowspec', ['MatchDscp'])
31

  
32
        # Adding model 'MatchFragmentType'
33
        db.create_table(u'match_fragment_type', (
34
            ('fragmenttype', self.gf('django.db.models.fields.CharField')(max_length=20)),
35
            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
36
        ))
37
        db.send_create_signal('flowspec', ['MatchFragmentType'])
38

  
39
        # Adding model 'MatchIcmpCode'
40
        db.create_table(u'match_icmp_code', (
41
            ('icmp_code', self.gf('django.db.models.fields.CharField')(max_length=64)),
42
            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
43
        ))
44
        db.send_create_signal('flowspec', ['MatchIcmpCode'])
45

  
46
        # Adding model 'MatchIcmpType'
47
        db.create_table(u'match_icmp_type', (
48
            ('icmp_type', self.gf('django.db.models.fields.CharField')(max_length=64)),
49
            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
50
        ))
51
        db.send_create_signal('flowspec', ['MatchIcmpType'])
52

  
53
        # Adding model 'MatchPacketLength'
54
        db.create_table(u'match_packet_length', (
55
            ('packet_length', self.gf('django.db.models.fields.IntegerField')()),
56
            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
57
        ))
58
        db.send_create_signal('flowspec', ['MatchPacketLength'])
59

  
60
        # Adding model 'MatchProtocol'
61
        db.create_table(u'match_protocol', (
62
            ('protocol', self.gf('django.db.models.fields.CharField')(max_length=64)),
63
            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
64
        ))
65
        db.send_create_signal('flowspec', ['MatchProtocol'])
66

  
67
        # Adding model 'MatchTcpFlag'
68
        db.create_table(u'match_tcp_flag', (
69
            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
70
            ('tcp_flag', self.gf('django.db.models.fields.CharField')(max_length=255)),
71
        ))
72
        db.send_create_signal('flowspec', ['MatchTcpFlag'])
73

  
74
        # Adding model 'ThenAction'
75
        db.create_table(u'then_action', (
76
            ('action', self.gf('django.db.models.fields.CharField')(max_length=60)),
77
            ('action_value', self.gf('django.db.models.fields.CharField')(max_length=255, null=True, blank=True)),
78
            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
79
        ))
80
        db.send_create_signal('flowspec', ['ThenAction'])
81

  
82
        # Adding model 'ThenStatement'
83
        db.create_table(u'then', (
84
            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
85
        ))
86
        db.send_create_signal('flowspec', ['ThenStatement'])
87

  
88
        # Adding M2M table for field thenaction on 'ThenStatement'
89
        db.create_table(u'then_thenaction', (
90
            ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
91
            ('thenstatement', models.ForeignKey(orm['flowspec.thenstatement'], null=False)),
92
            ('thenaction', models.ForeignKey(orm['flowspec.thenaction'], null=False))
93
        ))
94
        db.create_unique(u'then_thenaction', ['thenstatement_id', 'thenaction_id'])
95

  
96
        # Adding model 'MatchStatement'
97
        db.create_table(u'match', (
98
            ('matchfragmenttype', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['flowspec.MatchFragmentType'], null=True, blank=True)),
99
            ('matchprotocol', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['flowspec.MatchProtocol'], null=True, blank=True)),
100
            ('matchicmptype', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['flowspec.MatchIcmpType'], null=True, blank=True)),
101
            ('matchSourcePort', self.gf('django.db.models.fields.related.ForeignKey')(blank=True, related_name='matchSourcePort', null=True, to=orm['flowspec.MatchPort'])),
102
            ('matchicmpcode', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['flowspec.MatchIcmpCode'], null=True, blank=True)),
103
            ('matchTcpFlag', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['flowspec.MatchTcpFlag'], null=True, blank=True)),
104
            ('matchDestination', self.gf('django.db.models.fields.related.ForeignKey')(blank=True, related_name='matchDestination', null=True, to=orm['flowspec.MatchAddress'])),
105
            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
106
            ('matchpacketlength', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['flowspec.MatchPacketLength'], null=True, blank=True)),
107
        ))
108
        db.send_create_signal('flowspec', ['MatchStatement'])
109

  
110
        # Adding M2M table for field matchDestinationPort on 'MatchStatement'
111
        db.create_table(u'match_matchDestinationPort', (
112
            ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
113
            ('matchstatement', models.ForeignKey(orm['flowspec.matchstatement'], null=False)),
114
            ('matchport', models.ForeignKey(orm['flowspec.matchport'], null=False))
115
        ))
116
        db.create_unique(u'match_matchDestinationPort', ['matchstatement_id', 'matchport_id'])
117

  
118
        # Adding M2M table for field matchSource on 'MatchStatement'
119
        db.create_table(u'match_matchSource', (
120
            ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
121
            ('matchstatement', models.ForeignKey(orm['flowspec.matchstatement'], null=False)),
122
            ('matchaddress', models.ForeignKey(orm['flowspec.matchaddress'], null=False))
123
        ))
124
        db.create_unique(u'match_matchSource', ['matchstatement_id', 'matchaddress_id'])
125

  
126
        # Adding M2M table for field matchdscp on 'MatchStatement'
127
        db.create_table(u'match_matchdscp', (
128
            ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
129
            ('matchstatement', models.ForeignKey(orm['flowspec.matchstatement'], null=False)),
130
            ('matchdscp', models.ForeignKey(orm['flowspec.matchdscp'], null=False))
131
        ))
132
        db.create_unique(u'match_matchdscp', ['matchstatement_id', 'matchdscp_id'])
133

  
134
        # Adding M2M table for field matchport on 'MatchStatement'
135
        db.create_table(u'match_matchport', (
136
            ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
137
            ('matchstatement', models.ForeignKey(orm['flowspec.matchstatement'], null=False)),
138
            ('matchport', models.ForeignKey(orm['flowspec.matchport'], null=False))
139
        ))
140
        db.create_unique(u'match_matchport', ['matchstatement_id', 'matchport_id'])
141

  
142
        # Adding model 'Route'
143
        db.create_table(u'route', (
144
            ('then', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['flowspec.ThenStatement'])),
145
            ('last_updated', self.gf('django.db.models.fields.DateTimeField')(auto_now=True, blank=True)),
146
            ('name', self.gf('django.db.models.fields.CharField')(max_length=128)),
147
            ('expires', self.gf('django.db.models.fields.DateTimeField')()),
148
            ('applier', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User'])),
149
            ('filed', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)),
150
            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
151
            ('match', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['flowspec.MatchStatement'])),
152
        ))
153
        db.send_create_signal('flowspec', ['Route'])
154
    
155
    
156
    def backwards(self, orm):
157
        
158
        # Deleting model 'MatchAddress'
159
        db.delete_table(u'match_address')
160

  
161
        # Deleting model 'MatchPort'
162
        db.delete_table(u'match_port')
163

  
164
        # Deleting model 'MatchDscp'
165
        db.delete_table(u'match_dscp')
166

  
167
        # Deleting model 'MatchFragmentType'
168
        db.delete_table(u'match_fragment_type')
169

  
170
        # Deleting model 'MatchIcmpCode'
171
        db.delete_table(u'match_icmp_code')
172

  
173
        # Deleting model 'MatchIcmpType'
174
        db.delete_table(u'match_icmp_type')
175

  
176
        # Deleting model 'MatchPacketLength'
177
        db.delete_table(u'match_packet_length')
178

  
179
        # Deleting model 'MatchProtocol'
180
        db.delete_table(u'match_protocol')
181

  
182
        # Deleting model 'MatchTcpFlag'
183
        db.delete_table(u'match_tcp_flag')
184

  
185
        # Deleting model 'ThenAction'
186
        db.delete_table(u'then_action')
187

  
188
        # Deleting model 'ThenStatement'
189
        db.delete_table(u'then')
190

  
191
        # Removing M2M table for field thenaction on 'ThenStatement'
192
        db.delete_table('then_thenaction')
193

  
194
        # Deleting model 'MatchStatement'
195
        db.delete_table(u'match')
196

  
197
        # Removing M2M table for field matchDestinationPort on 'MatchStatement'
198
        db.delete_table('match_matchDestinationPort')
199

  
200
        # Removing M2M table for field matchSource on 'MatchStatement'
201
        db.delete_table('match_matchSource')
202

  
203
        # Removing M2M table for field matchdscp on 'MatchStatement'
204
        db.delete_table('match_matchdscp')
205

  
206
        # Removing M2M table for field matchport on 'MatchStatement'
207
        db.delete_table('match_matchport')
208

  
209
        # Deleting model 'Route'
210
        db.delete_table(u'route')
211
    
212
    
213
    models = {
214
        'auth.group': {
215
            'Meta': {'object_name': 'Group'},
216
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
217
            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
218
            'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
219
        },
220
        'auth.permission': {
221
            'Meta': {'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
222
            'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
223
            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
224
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
225
            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
226
        },
227
        'auth.user': {
228
            'Meta': {'object_name': 'User'},
229
            'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
230
            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
231
            'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
232
            'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
233
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
234
            'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'blank': 'True'}),
235
            'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
236
            'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
237
            'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
238
            'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
239
            'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
240
            'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
241
            'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
242
        },
243
        'contenttypes.contenttype': {
244
            'Meta': {'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
245
            'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
246
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
247
            'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
248
            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
249
        },
250
        'flowspec.matchaddress': {
251
            'Meta': {'object_name': 'MatchAddress', 'db_table': "u'match_address'"},
252
            'destination': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
253
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
254
        },
255
        'flowspec.matchdscp': {
256
            'Meta': {'object_name': 'MatchDscp', 'db_table': "u'match_dscp'"},
257
            'dscp': ('django.db.models.fields.CharField', [], {'max_length': '24'}),
258
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
259
        },
260
        'flowspec.matchfragmenttype': {
261
            'Meta': {'object_name': 'MatchFragmentType', 'db_table': "u'match_fragment_type'"},
262
            'fragmenttype': ('django.db.models.fields.CharField', [], {'max_length': '20'}),
263
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
264
        },
265
        'flowspec.matchicmpcode': {
266
            'Meta': {'object_name': 'MatchIcmpCode', 'db_table': "u'match_icmp_code'"},
267
            'icmp_code': ('django.db.models.fields.CharField', [], {'max_length': '64'}),
268
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
269
        },
270
        'flowspec.matchicmptype': {
271
            'Meta': {'object_name': 'MatchIcmpType', 'db_table': "u'match_icmp_type'"},
272
            'icmp_type': ('django.db.models.fields.CharField', [], {'max_length': '64'}),
273
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
274
        },
275
        'flowspec.matchpacketlength': {
276
            'Meta': {'object_name': 'MatchPacketLength', 'db_table': "u'match_packet_length'"},
277
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
278
            'packet_length': ('django.db.models.fields.IntegerField', [], {})
279
        },
280
        'flowspec.matchport': {
281
            'Meta': {'object_name': 'MatchPort', 'db_table': "u'match_port'"},
282
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
283
            'port': ('django.db.models.fields.CharField', [], {'max_length': '24'})
284
        },
285
        'flowspec.matchprotocol': {
286
            'Meta': {'object_name': 'MatchProtocol', 'db_table': "u'match_protocol'"},
287
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
288
            'protocol': ('django.db.models.fields.CharField', [], {'max_length': '64'})
289
        },
290
        'flowspec.matchstatement': {
291
            'Meta': {'object_name': 'MatchStatement', 'db_table': "u'match'"},
292
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
293
            'matchDestination': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'matchDestination'", 'null': 'True', 'to': "orm['flowspec.MatchAddress']"}),
294
            'matchDestinationPort': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'matchDestinationPort'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['flowspec.MatchPort']"}),
295
            'matchSource': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'matchSource'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['flowspec.MatchAddress']"}),
296
            'matchSourcePort': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'matchSourcePort'", 'null': 'True', 'to': "orm['flowspec.MatchPort']"}),
297
            'matchTcpFlag': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['flowspec.MatchTcpFlag']", 'null': 'True', 'blank': 'True'}),
298
            'matchdscp': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': "orm['flowspec.MatchDscp']", 'null': 'True', 'blank': 'True'}),
299
            'matchfragmenttype': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['flowspec.MatchFragmentType']", 'null': 'True', 'blank': 'True'}),
300
            'matchicmpcode': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['flowspec.MatchIcmpCode']", 'null': 'True', 'blank': 'True'}),
301
            'matchicmptype': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['flowspec.MatchIcmpType']", 'null': 'True', 'blank': 'True'}),
302
            'matchpacketlength': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['flowspec.MatchPacketLength']", 'null': 'True', 'blank': 'True'}),
303
            'matchport': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': "orm['flowspec.MatchPort']", 'null': 'True', 'blank': 'True'}),
304
            'matchprotocol': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['flowspec.MatchProtocol']", 'null': 'True', 'blank': 'True'})
305
        },
306
        'flowspec.matchtcpflag': {
307
            'Meta': {'object_name': 'MatchTcpFlag', 'db_table': "u'match_tcp_flag'"},
308
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
309
            'tcp_flag': ('django.db.models.fields.CharField', [], {'max_length': '255'})
310
        },
311
        'flowspec.route': {
312
            'Meta': {'object_name': 'Route', 'db_table': "u'route'"},
313
            'applier': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}),
314
            'expires': ('django.db.models.fields.DateTimeField', [], {}),
315
            'filed': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
316
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
317
            'last_updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
318
            'match': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['flowspec.MatchStatement']"}),
319
            'name': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
320
            'then': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['flowspec.ThenStatement']"})
321
        },
322
        'flowspec.thenaction': {
323
            'Meta': {'object_name': 'ThenAction', 'db_table': "u'then_action'"},
324
            'action': ('django.db.models.fields.CharField', [], {'max_length': '60'}),
325
            'action_value': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
326
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
327
        },
328
        'flowspec.thenstatement': {
329
            'Meta': {'object_name': 'ThenStatement', 'db_table': "u'then'"},
330
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
331
            'thenaction': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': "orm['flowspec.ThenAction']", 'null': 'True', 'blank': 'True'})
332
        }
333
    }
334
    
335
    complete_apps = ['flowspec']
b/flowspec/models.py
1 1
from django.db import models
2 2
from django.contrib.auth.models import User
3 3

  
4
import nxpy as np
5
from ncclient import manager
6
from ncclient.transport.errors import AuthenticationError, SSHError
7
from lxml import etree as ET
8

  
4 9
FRAGMENT_CODES = (
5 10
    ("dont-fragment", "Don't fragment"),
6 11
    ("first-fragment", "First fragment"),
......
22 27

  
23 28
    
24 29
class MatchAddress(models.Model):
25
    destination = models.CharField(max_length=255)
30
    address = models.CharField(max_length=255)
31
    def __unicode__(self):
32
        return self.address
26 33
    class Meta:
27 34
        db_table = u'match_address'
28 35

  
29 36
class MatchPort(models.Model):
30 37
    port = models.CharField(max_length=24)
38
    def __unicode__(self):
39
        return self.port
31 40
    class Meta:
32 41
        db_table = u'match_port'    
33 42

  
34 43
class MatchDscp(models.Model):
35 44
    dscp = models.CharField(max_length=24)
45
    def __unicode__(self):
46
        return self.dscp
36 47
    class Meta:
37 48
        db_table = u'match_dscp'
38 49

  
39 50
class MatchFragmentType(models.Model):
40 51
    fragmenttype = models.CharField(max_length=20, choices=FRAGMENT_CODES)
52
    def __unicode__(self):
53
        return self.fragmenttype
41 54
    class Meta:
42 55
        db_table = u'match_fragment_type'
43 56
    
44 57
class MatchIcmpCode(models.Model):
45 58
    icmp_code = models.CharField(max_length=64)
59
    def __unicode__(self):
60
        return self.icmp_code
46 61
    class Meta:
47 62
        db_table = u'match_icmp_code'    
48 63

  
......
58 73

  
59 74
class MatchProtocol(models.Model):
60 75
    protocol = models.CharField(max_length=64)
76
    def __unicode__(self):
77
        return self.protocol
61 78
    class Meta:
62 79
        db_table = u'match_protocol'    
63 80

  
64 81
class MatchTcpFlag(models.Model):
65 82
    tcp_flag = models.CharField(max_length=255)
83
    def __unicode__(self):
84
        return self.tcp_flag
66 85
    class Meta:
67 86
        db_table = u'match_tcp_flag'    
68 87
    
69 88
class ThenAction(models.Model):
70 89
    action = models.CharField(max_length=60, choices=THEN_CHOICES)
71 90
    action_value = models.CharField(max_length=255, blank=True, null=True)
91
    def __unicode__(self):
92
        return "%s %s" %(self.action, self.action_value)
72 93
    class Meta:
73 94
        db_table = u'then_action'
74 95

  
......
85 106
    matchicmpcode = models.ForeignKey(MatchIcmpCode, blank=True, null=True)
86 107
    matchicmptype = models.ForeignKey(MatchIcmpType, blank=True, null=True)
87 108
    matchpacketlength = models.ForeignKey(MatchPacketLength, blank=True, null=True)
88
    matchport = models.ManyToManyField(MatchPort, blank=True, null=True)
109
    matchport = models.ManyToManyField(MatchPort, blank=True, null=True, related_name="matchPort")
89 110
    matchprotocol = models.ForeignKey(MatchProtocol, blank=True, null=True)
90
    matchSource = models.ManyToManyField(MatchAddress, blank=True, null=True, related_name="matchSource")
91
    matchSourcePort = models.ForeignKey(MatchPort, blank=True, null=True, related_name="matchSourcePort")
111
    matchSource = models.ForeignKey(MatchAddress, blank=True, null=True, related_name="matchSource")
112
    matchSourcePort = models.ManyToManyField(MatchPort, blank=True, null=True, related_name="matchSourcePort")
92 113
    matchTcpFlag = models.ForeignKey(MatchTcpFlag, blank=True, null=True)
93 114
    class Meta:
94 115
        db_table = u'match'
......
101 122
    filed = models.DateTimeField(auto_now_add=True)
102 123
    last_updated = models.DateTimeField(auto_now=True)
103 124
    expires = models.DateTimeField()
125
    def __unicode__(self):
126
        return self.name
127
    
104 128
    class Meta:
105
        db_table = u'route'
129
        db_table = u'route'
130

  
131
    def save(self, *args, **kwargs):
132
        # Begin translation to device xml configuration
133
        device = np.Device()
134
        flow = np.Flow()
135
        route = np.Route()
136
        flow.routes.append(route)
137
        device.routing_options.append(flow)
138
        route.name = self.name
139
        match = self.match
140
        if match.matchSource:
141
            route.match['source'].append(match.matchSource.address)
142
        if match.matchDestination:
143
            route.match['destination'].append(match.matchDestination.address)
144
        if match.matchprotocol:
145
            route.match['protocol'].append(match.matchprotocol.protocol)
146
        if match.matchport:
147
            for port in match.matchport.all():
148
                route.match['port'].append(port.port)
149
        if match.matchDestinationPort:
150
            for port in match.matchDestinationPort.all():
151
                route.match['destination-port'].append(port.port)
152
        if match.matchSourcePort:
153
            for port in match.matchSourcePort.all():
154
                route.match['source-port'].append(port.port)
155
        if match.matchicmpcode:
156
            route.match['icmp-code'].append(match.matchicmpcode.icmp_code)
157
        if match.matchicmptype:
158
            route.match['icmp-type'].append(match.matchicmptype.icmp_type)
159
        if match.matchTcpFlag:
160
            route.match['tcp-flags'].append(match.matchTcpFlag.tcp_flags)
161
        if match.matchdscp:
162
            for dscp in match.matchdscp.all():
163
                route.match['dscp'].append(dscp.dscp)
164
        if match.matchfragmenttype:
165
            route.match['fragment'].append(match.matchfragmenttype.fragmenttype)
166
        then = self.then
167
        for thenaction in then.thenaction.all():
168
            if thenaction.action_value:
169
                route.then[thenaction.action] = thenaction.action_value
170
            else:
171
                route.then[thenaction.action] = True
172
        print ET.tostring(device.export())
173
        super(Route, self).save(*args, **kwargs)
b/urls.py
1 1
from django.conf.urls.defaults import *
2 2

  
3 3
# Uncomment the next two lines to enable the admin:
4
# from django.contrib import admin
5
# admin.autodiscover()
4
from django.contrib import admin
5
admin.autodiscover()
6 6

  
7 7
urlpatterns = patterns('',
8 8
    # Example:
9 9
    # (r'^flowspy/', include('flowspy.foo.urls')),
10 10

  
11 11
    # Uncomment the admin/doc line below to enable admin documentation:
12
    # (r'^admin/doc/', include('django.contrib.admindocs.urls')),
12
    (r'^admin/doc/', include('django.contrib.admindocs.urls')),
13 13

  
14 14
    # Uncomment the next line to enable the admin:
15
    # (r'^admin/', include(admin.site.urls)),
15
    (r'^admin/', include(admin.site.urls)),
16 16
)

Also available in: Unified diff