From 696bce3094f51860a3df0aa4aaf354caa8f06aa6 Mon Sep 17 00:00:00 2001
From: Czémán Arnold <czeman.arnold@cloud.bme.hu>
Date: Mon, 17 Aug 2015 16:27:47 +0200
Subject: [PATCH] firewall: add --timeout switch for reload_firewall_command

---
 circle/firewall/management/commands/reload_firewall.py | 18 +++++++++++++++++-
 circle/firewall/tasks/local_tasks.py                   |  2 +-
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/circle/firewall/management/commands/reload_firewall.py b/circle/firewall/management/commands/reload_firewall.py
index 43d3176..8ed5bd8 100644
--- a/circle/firewall/management/commands/reload_firewall.py
+++ b/circle/firewall/management/commands/reload_firewall.py
@@ -21,6 +21,8 @@ from django.core.management.base import BaseCommand
 
 from firewall.tasks.local_tasks import reloadtask
 
+from argparse import ArgumentTypeError
+
 
 class Command(BaseCommand):
 
@@ -33,6 +35,20 @@ class Command(BaseCommand):
                             default=False,
                             help='synchronous reload')
 
+        parser.add_argument('--timeout',
+                            action='store',
+                            dest='timeout',
+                            default=15,
+                            type=self.positive_int,
+                            help='timeout for synchronous reload')
+
     def handle(self, *args, **options):
 
-        reloadtask('Vlan', sync=options["sync"])
+        reloadtask('Vlan', sync=options["sync"], timeout=options["timeout"])
+
+    def positive_int(self, val):
+
+        if not val.isdigit():
+            raise ArgumentTypeError("'%s' is not a valid positive int" % val)
+
+        return int(val)
diff --git a/circle/firewall/tasks/local_tasks.py b/circle/firewall/tasks/local_tasks.py
index 3d40563..7c3c2d1 100644
--- a/circle/firewall/tasks/local_tasks.py
+++ b/circle/firewall/tasks/local_tasks.py
@@ -109,4 +109,4 @@ def reloadtask(type='Host', timeout=15, sync=False):
     if all([cache.add("%s_lock" % i, 'true', 30) for i in reload]):
         res = reloadtask_worker.apply_async(queue='localhost.man', countdown=5)
         if sync:
-            res.get(15)
+            res.get(timeout)
--
libgit2 0.26.0