diff --git a/flowspec/serializers.py b/flowspec/serializers.py index 89fef85f7b52aa7d67326c99ac1dc08c88f1b9cc..a6039ec83c211025352b01a2c24b4e5f9e2ffee2 100644 --- a/flowspec/serializers.py +++ b/flowspec/serializers.py @@ -70,6 +70,9 @@ class RouteSerializer(serializers.HyperlinkedModelSerializer): if "applier" not in validated_data: u = self.context.get('request').user validated_data["applier"] = u + if "expires" not in validated_data and "isnonexpire" not in validated_data : + #validated_data["isnonexpire"] = True + validated_data["expires"] = "2999-01-01" protocol = validated_data.pop('protocol', set()) then = validated_data.pop('then') fragmenttype = validated_data.pop('fragmenttype', set()) @@ -140,6 +143,9 @@ class RouteSerializer(serializers.HyperlinkedModelSerializer): def update(self, instance, validated_data): if 'name' in validated_data: del validated_data["name"] + if "expires" not in validated_data and "isnonexpire" not in validated_data : + #validated_data["isnonexpire"] = True + validated_data["expires"] = "2999-01-01" protocol = validated_data.pop('protocol', None) if protocol: instance.protocol.set(protocol) diff --git a/flowspec/tasks.py b/flowspec/tasks.py index 243c17c54cddcbfd80d502e141c31ae7bccdf5de..3e850641198396ced27cfbdc060135f54bfb680b 100644 --- a/flowspec/tasks.py +++ b/flowspec/tasks.py @@ -130,10 +130,10 @@ def delete(routepk, **kwargs): commit, response = applier.apply(operation="delete") reason_text = '' logger.info("tasks::delete(): initial_status="+str(initial_status)) - if commit: + if commit and initial_status == "PENDING_TODELETE": # special new case for fully deleting a rule via REST API (only for users/admins authorized by special settings) route.status="INACTIVE" msg1 = "[%s] Fully deleted route : %s%s- Result %s" % (route.applier, route.name, reason_text, response) - logger.info("tasks::delete(): DELETED msg="+msg1) + logger.info("tasks::delete(): FULLY DELETED msg="+msg1) announce(msg1, route.applier, route) try: snmp_add_initial_zero_value(str(route.id), False) @@ -141,7 +141,19 @@ def delete(routepk, **kwargs): logger.error("edit(): route="+str(route)+", INACTIVE, add_null_value failed: "+str(e)) route.delete() return - else: + elif commit: # commit worked, but rule should stay in DB (NOT PENDING_TODELETE) + route.status="INACTIVE" + msg1 = "[%s] Deleted route : %s%s- Result %s" % (route.applier, route.name, reason_text, response) + logger.info("tasks::delete(): DELETED msg="+msg1) + announce(msg1, route.applier, route) + try: + snmp_add_initial_zero_value(str(route.id), False) + except Exception as e: + logger.error("edit(): route="+str(route)+", INACTIVE, add_null_value failed: "+str(e)) + route.response = response + route.save() + return + else: # removing rule in NETCONF failed, it is still ACTIVE and also collects statistics # NETCONF "delete" operation failed, keep the object in DB if "reason" in kwargs and kwargs['reason'] == 'EXPIRED': status = 'EXPIRED' diff --git a/templates/flowspy/route_details.html b/templates/flowspy/route_details.html index e34c16ded3aba51dc4c77aef1e7818f2e308d9f4..4d842b813869e76daea0048a310ca261b1b88148 100644 --- a/templates/flowspy/route_details.html +++ b/templates/flowspy/route_details.html @@ -21,7 +21,7 @@ function myreloadPage() { <div class="row"> <div class="col-md-12"> <div> - <i class="fa fa-clock-o"></i> {% trans "Expires" %}: {{ route.expires|date:"d M y" }} + <i class="fa fa-clock-o"></i> {% trans "Expires" %}: {% if not route.is_no_expire %}{{ route.expires|date:"d M y" }}{% else %}{% trans "No" %}{% endif %} </div> </div> <div class="col-md-12">