Revision 6a946adf flowspec/models.py

b/flowspec/models.py
128 128
                self.source = address.exploded
129 129
            except Exception:
130 130
                raise ValidationError('Invalid network address format at Source Field')
131
    
132
#    def save(self, *args, **kwargs):
133
#        edit = False
134
#        if self.pk:
135
#            #This is an edit
136
#            edit = True
137
#        super(Route, self).save(*args, **kwargs)
138
#        if not edit:
139
#            response = add.delay(self)
140
#            logger.info("Got save job id: %s" %response)
141
    
131
   
142 132
    def commit_add(self, *args, **kwargs):
143 133
        peer = self.applier.get_profile().peer.domain_name
144 134
        send_message("[%s] Adding route %s. Please wait..." %(self.applier.username, self.name), peer)
145 135
        response = add.delay(self)
146
        logger.info("Got save job id: %s" %response)
147

  
148
    def deactivate(self):
149
        self.status = "INACTIVE"
150
        self.save()
151
#    def delete(self, *args, **kwargs):
152
#        response = delete.delay(self)
153
#        logger.info("Got delete job id: %s" %response)
136
        logger.info("Got add job id: %s" %response)
154 137
        
155 138
    def commit_edit(self, *args, **kwargs):
156 139
        peer = self.applier.get_profile().peer.domain_name
......
159 142
        logger.info("Got edit job id: %s" %response)
160 143

  
161 144
    def commit_delete(self, *args, **kwargs):
145
        reason_text = ''
146
        if "reason" in kwargs:
147
            reason = kwargs['reason']
148
            reason_text = "Reason: %s. " %reason
162 149
        peer = self.applier.get_profile().peer.domain_name
163
        send_message("[%s] Removing route %s. Please wait..." %(self.applier.username, self.name), peer)
164
        response = delete.delay(self)
165
        logger.info("Got edit job id: %s" %response)
166
#    
167
#    def delete(self, *args, **kwargs):
168
#        response = delete.delay(self)
169
#        logger.info("Got delete job id: %s" %response)
150
        send_message("[%s] Removing route %s. %sPlease wait..." %(self.applier.username, self.name, reason), peer)
151
        response = delete.delay(self, reason=reason)
152
        logger.info("Got delete job id: %s" %response)
153

  
170 154
    def has_expired(self):
171 155
        today = datetime.date.today()
172 156
        if today > self.expires:
173 157
            return True
174 158
        return False
175

  
176
    def is_synced(self):      
159
    
160
    def check_sync(self):
161
        if not self.is_synced():
162
            self.status = "OUTOFSYNC"
163
            self.save()
164
    
165
    def is_synced(self):
177 166
        found = False
178 167
        get_device = PR.Retriever()
179 168
        device = get_device.fetch_device()
......
183 172
            self.status = "EXPIRED"
184 173
            self.save()
185 174
            logger.error("No routing options on device. Exception: %s" %e)
186
            return False
175
            return True
187 176
        for route in routes:
188 177
            if route.name == self.name:
189 178
                found = True
......
257 246
                    pass
258 247
                if found and self.status != "ACTIVE":
259 248
                     logger.error('Rule is applied on device but appears as offline')
260
                     found = False
261
        
249
                     self.status = "ACTIVE"
250
                     self.save()
251
                     found = True
262 252
        return found
263 253

  
264 254
    def get_then(self):

Also available in: Unified diff