Commit 0d875b08 by Czémán Arnold

firewall: add logger for add_rule command

parent 8dd2391b
...@@ -15,10 +15,13 @@ ...@@ -15,10 +15,13 @@
from __future__ import unicode_literals, absolute_import from __future__ import unicode_literals, absolute_import
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand, CommandError
import logging
from firewall.models import Vlan, VlanGroup, Rule from firewall.models import Vlan, VlanGroup, Rule
from django.contrib.auth.models import User from django.contrib.auth.models import User
logger = logging.getLogger(__name__)
class Command(BaseCommand): class Command(BaseCommand):
...@@ -103,8 +106,12 @@ class Command(BaseCommand): ...@@ -103,8 +106,12 @@ class Command(BaseCommand):
if port: if port:
self.validate_port(port) self.validate_port(port)
rule = self.make_rule(port, proto, action, dir, owner, vlan, fnet) try:
rule = self.make_rule(port, proto, action,
dir, owner, vlan, fnet)
rule.save() rule.save()
except Warning as e:
logger.warning(e)
else: else:
lower = min(range) lower = min(range)
higher = max(range) higher = max(range)
...@@ -114,9 +121,12 @@ class Command(BaseCommand): ...@@ -114,9 +121,12 @@ class Command(BaseCommand):
rules = [] rules = []
for port in xrange(lower, higher+1): for port in xrange(lower, higher+1):
try:
rule = self.make_rule(port, proto, action, dir, rule = self.make_rule(port, proto, action, dir,
owner, vlan, fnet) owner, vlan, fnet)
rules.append(rule) rules.append(rule)
except Warning as e:
logger.warning(e)
Rule.objects.bulk_create(rules) Rule.objects.bulk_create(rules)
...@@ -126,7 +136,8 @@ class Command(BaseCommand): ...@@ -126,7 +136,8 @@ class Command(BaseCommand):
vlan=vlan, foreign_network=fnet, owner=owner) vlan=vlan, foreign_network=fnet, owner=owner)
if self.is_exist(port, proto, action, dir, owner, vlan, fnet): if self.is_exist(port, proto, action, dir, owner, vlan, fnet):
raise CommandError('Rule does exist, yet: %s' % unicode(rule)) raise Warning(('Rule does exist: %s' %
unicode(rule)).encode('utf-8'))
rule.full_clean() rule.full_clean()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment