diff --git a/flowspec/admin.py b/flowspec/admin.py index 8743f1fa69a1300ef093b82099f107954d877b3a..37a638c52956f3589bd4c76f66653a31f6c96766 100644 --- a/flowspec/admin.py +++ b/flowspec/admin.py @@ -7,14 +7,12 @@ from django.contrib.auth.models import User from django.contrib.auth.admin import UserAdmin from accounts.models import UserProfile - class RouteAdmin(admin.ModelAdmin): actions = ['deactivate'] def deactivate(self, request, queryset): queryset = queryset.filter(status='ACTIVE') - rows = queryset.update(status='PENDING') response = batch_delete.delay(queryset, reason="ADMININACTIVE") self.message_user(request, "Added request %s to job que. Check in a while for result" % response) deactivate.short_description = "Remove selected routes from network" diff --git a/flowspec/models.py b/flowspec/models.py index f0c21bf0cdf1f4def0007af06eb1d7746c30a3c6..e1006c1e3e8119ee65e21d40d68959c9c999f692 100644 --- a/flowspec/models.py +++ b/flowspec/models.py @@ -249,12 +249,12 @@ class Route(models.Model): except: pass if found and self.status != "ACTIVE": - logger.error('Rule is applied on device but appears as offline') - self.status = "ACTIVE" - self.save() - found = True - if not found and self.status == "ADMININACTIVE": - found = True + logger.error('Rule is applied on device but appears as offline') + self.status = "ACTIVE" + self.save() + found = True + if self.status == "ADMININACTIVE": + found = True return found def get_then(self): diff --git a/flowspec/tasks.py b/flowspec/tasks.py index 199c4f3659b3d6b6dec820f53c57d5f979af3470..f548c7ed6ca18f10a6b729c81a2b67bb49dee3ff 100644 --- a/flowspec/tasks.py +++ b/flowspec/tasks.py @@ -61,6 +61,8 @@ def delete(route, **kwargs): @task def batch_delete(routes, **kwargs): if routes: + for route in routes: + route.status='PENDING';route.save() applier = PR.Applier(route_objects=routes) conf = applier.delete_routes() commit, response = applier.apply(configuration = conf)