Revision 9cad4715 flowspec/models.py
b/flowspec/models.py | ||
---|---|---|
8 | 8 |
from ipaddr import * |
9 | 9 |
from datetime import * |
10 | 10 |
import logging |
11 |
from flowspec.tasks import * |
|
12 |
from time import sleep |
|
11 | 13 |
|
12 | 14 |
FORMAT = '%(asctime)s %(levelname)s: %(message)s' |
13 | 15 |
logging.basicConfig(format=FORMAT) |
... | ... | |
61 | 63 |
|
62 | 64 |
class Route(models.Model): |
63 | 65 |
name = models.CharField(max_length=128) |
64 |
applier = models.ForeignKey(User) |
|
66 |
applier = models.ForeignKey(User, blank=True, null=True)
|
|
65 | 67 |
source = models.CharField(max_length=32, blank=True, null=True, help_text=u"Network address. Use address/CIDR notation", verbose_name="Source Address") |
66 | 68 |
sourceport = models.ManyToManyField(MatchPort, blank=True, null=True, related_name="matchSourcePort", verbose_name="Source Port") |
67 | 69 |
destination = models.CharField(max_length=32, blank=True, null=True, help_text=u"Network address. Use address/CIDR notation", verbose_name="Destination Address") |
... | ... | |
79 | 81 |
last_updated = models.DateTimeField(auto_now=True) |
80 | 82 |
is_online = models.BooleanField(default=False) |
81 | 83 |
is_active = models.BooleanField(default=False) |
82 |
expires = models.DateField(default=days_offset) |
|
84 |
expires = models.DateField(default=days_offset, blank=True, null=True,)
|
|
83 | 85 |
response = models.CharField(max_length=512, blank=True, null=True) |
84 | 86 |
comments = models.TextField(null=True, blank=True, verbose_name="Comments") |
85 | 87 |
|
... | ... | |
106 | 108 |
except Exception: |
107 | 109 |
raise ValidationError('Invalid network address format at Source Field') |
108 | 110 |
|
109 |
def save(self, *args, **kwargs): |
|
110 |
applier = PR.Applier(route_object=self) |
|
111 |
commit, response = applier.apply() |
|
112 |
if commit: |
|
113 |
self.is_online = True |
|
114 |
self.is_active = True |
|
115 |
self.response = response |
|
116 |
else: |
|
117 |
self.is_online = False |
|
118 |
self.response = response |
|
119 |
super(Route, self).save(*args, **kwargs) |
|
111 |
# def save(self, *args, **kwargs): |
|
112 |
# edit = False |
|
113 |
# if self.pk: |
|
114 |
# #This is an edit |
|
115 |
# edit = True |
|
116 |
# super(Route, self).save(*args, **kwargs) |
|
117 |
# if not edit: |
|
118 |
# response = add.delay(self) |
|
119 |
# logger.info("Got save job id: %s" %response) |
|
120 |
|
|
121 |
def commit_add(self, *args, **kwargs): |
|
122 |
response = add.delay(self) |
|
123 |
logger.info("Got save job id: %s" %response) |
|
124 |
# |
|
125 |
# def delete(self, *args, **kwargs): |
|
126 |
# response = delete.delay(self) |
|
127 |
# logger.info("Got delete job id: %s" %response) |
|
128 |
|
|
120 | 129 |
|
121 | 130 |
def is_synced(self): |
122 | 131 |
|
Also available in: Unified diff