From fdc3d663caf4d9398be54dddacfa364c200edcf1 Mon Sep 17 00:00:00 2001 From: Leonidas Poulopoulos <leopoul@noc.grnet.gr> Date: Thu, 22 Dec 2011 11:19:21 +0200 Subject: [PATCH] Expiration mechanism and messages refinement --- cron_notify_expired.py | 2 +- flowspec/admin.py | 3 ++- flowspec/models.py | 1 + flowspec/tasks.py | 10 +++++----- flowspec/views.py | 3 ++- templates/user_routes.html | 6 +++--- 6 files changed, 14 insertions(+), 11 deletions(-) diff --git a/cron_notify_expired.py b/cron_notify_expired.py index 6969133e..122625d2 100755 --- a/cron_notify_expired.py +++ b/cron_notify_expired.py @@ -13,7 +13,7 @@ import datetime def notify_expired(): routes = Route.objects.all() for route in routes: - if route.status not in ['EXPIRED', 'ADMININACTIVE', 'ERROR']: + if route.status not in ['EXPIRED', 'ADMININACTIVE', 'INACTIVE', 'ERROR']: expiration_days = (route.expires - datetime.date.today()).days if expiration_days < settings.EXPIRATION_NOTIFY_DAYS: try: diff --git a/flowspec/admin.py b/flowspec/admin.py index 76307a12..5ee2e914 100644 --- a/flowspec/admin.py +++ b/flowspec/admin.py @@ -7,7 +7,7 @@ from django.contrib.auth.models import User from django.contrib.auth.admin import UserAdmin from accounts.models import UserProfile from flowspy.flowspec.forms import * - +import datetime class RouteAdmin(admin.ModelAdmin): form = RouteForm @@ -21,6 +21,7 @@ class RouteAdmin(admin.ModelAdmin): def save_model(self, request, obj, form, change): obj.status = "PENDING" + obj.expires = datetime.date.today() obj.save() obj.commit_add() diff --git a/flowspec/models.py b/flowspec/models.py index ebfaebfe..0caba493 100644 --- a/flowspec/models.py +++ b/flowspec/models.py @@ -75,6 +75,7 @@ class ThenAction(models.Model): return ret.rstrip(":") class Meta: db_table = u'then_action' + ordering = ['action', 'action_value'] unique_together = ("action", "action_value") class Route(models.Model): diff --git a/flowspec/tasks.py b/flowspec/tasks.py index 35a52bcb..d793402f 100644 --- a/flowspec/tasks.py +++ b/flowspec/tasks.py @@ -121,11 +121,11 @@ def check_sync(route_name=None, selected_routes = []): if route.has_expired() and (route.status != 'EXPIRED' and route.status != 'ADMININACTIVE' and route.status != 'INACTIVE'): logger.info('Expiring route %s' %route.name) subtask(delete).delay(route, reason="EXPIRED") - elif route.has_expired() and (route.status == 'ADMININACTIVE' or route.status == 'INACTIVE'): - route.status = 'EXPIRED' - route.response = 'Rule Expired' - logger.info('Expiring route %s' %route.name) - route.save() +# elif route.has_expired() and (route.status == 'ADMININACTIVE' or route.status == 'INACTIVE'): +# route.status = 'EXPIRED' +# route.response = 'Rule Expired' +# logger.info('Expiring route %s' %route.name) +# route.save() else: if route.status != 'EXPIRED': route.check_sync() diff --git a/flowspec/views.py b/flowspec/views.py index c1839895..b3c93024 100644 --- a/flowspec/views.py +++ b/flowspec/views.py @@ -32,7 +32,7 @@ from flowspy.utils.decorators import shib_required from django.views.decorators.cache import never_cache from django.conf import settings from django.core.mail import mail_admins, mail_managers, send_mail - +import datetime import os LOG_FILENAME = os.path.join(settings.LOG_FILE_LOCATION, 'celery_jobs.log') @@ -174,6 +174,7 @@ def delete_route(request, route_slug): requester_peer = request.user.get_profile().peer if applier_peer == requester_peer: route.status = "PENDING" + route.expires = datetime.date.today() route.save() route.commit_delete() requesters_address = request.META['HTTP_X_FORWARDED_FOR'] diff --git a/templates/user_routes.html b/templates/user_routes.html index 97c1acc6..9c86c011 100644 --- a/templates/user_routes.html +++ b/templates/user_routes.html @@ -282,12 +282,12 @@ function delete_route(route){ title = "{% ifequal route.status 'INACTIVE' %}Suspended by user{% else %}{% ifequal route.status 'ADMININACTIVE' %}Suspended by administrator{% else %}{% ifequal route.status 'EXPIRED' %}Suspended due to expiration{% else %}{% ifequal route.status 'OUTOFSYNC' %}Syncronization error. Configuration in device deffers from rule{% endifequal %}{% endifequal %}{% endifequal %}{% endifequal %}"{% endif %}>{% if route.status == 'EXPIRED' or route.status == 'ADMININACTIVE' or route.status == 'INACTIVE' %}SUSPENDED{% else %}{% if route.status == 'OUTOFSYNC' %}ERROR{% else %}{{route.status}}{% endif %}{% endif %}</span></td> {% comment %}<td style="text-align: center;">{{ route.response }}</td>{% endcomment %} <td style="text-align: center;">{{ route.applier }}</td> - <td style="text-align: center;"><span {% if route.days_to_expire %} + <td style="text-align: center;"><span {% if route.status == 'EXPIRED' or route.status == 'ADMININACTIVE' or route.status == 'INACTIVE' or route.status == 'OUTOFSYNC'%}{% else %}{% if route.days_to_expire %} class="expiresclass" style="border-bottom:2px dashed red;" title="Expires {% ifequal route.days_to_expire '0' %}today{% else%}in {{route.days_to_expire}} day{{ route.days_to_expire|pluralize }}{% endifequal %}" - {% endif %}>{{ route.expires }}</span></td> - <td style="text-align: center;">{{ route.response }}</td> + {% endif %}{% endif %}>{{ route.expires }}</span></td> + <td style="text-align: center;">{% if route.status == 'EXPIRED' %}Rule expired{% else %}{% if route.status == 'ADMININACTIVE' %}Suspended by administrator{% else %}{% if route.status == 'INACTIVE' %}Suspended by user{% else %}{{ route.response }}{% endif %}{% endif %}{% endif %}</td> <td style="text-align: center; width:180px;"> {% ifequal route.status 'ACTIVE' %} <a href="{% url edit-route route.name %}" class="edit_button" id="edit_button_{{route.pk}}">Edit</a> -- GitLab