Commit ff4144e6 by Bach Dániel

firewall: celery periodic task added

parent 8b14a3f3
...@@ -187,6 +187,7 @@ CELERY_ROUTES = { ...@@ -187,6 +187,7 @@ CELERY_ROUTES = {
'firewall.tasks.reload_firewall_task': {'queue': 'firewall'}, 'firewall.tasks.reload_firewall_task': {'queue': 'firewall'},
'firewall.tasks.reload_dhcp_task': {'queue': 'dhcp'}, 'firewall.tasks.reload_dhcp_task': {'queue': 'dhcp'},
'firewall.tasks.reload_blacklist_task': {'queue': 'firewall'}, 'firewall.tasks.reload_blacklist_task': {'queue': 'firewall'},
'firewall.tasks.Periodic': {'queue': 'local'},
} }
store_settings = { store_settings = {
......
...@@ -19,44 +19,47 @@ def reload_dhcp_task(data): ...@@ -19,44 +19,47 @@ def reload_dhcp_task(data):
def reload_blacklist_task(data): def reload_blacklist_task(data):
pass pass
class Periodic(PeriodicTask):
run_every = timedelta(seconds=60)
def run(self, **kwargs):
if cache.get('dns_lock'):
cache.delete("dns_lock")
reload_dns_task.delay(dns())
print "dns ujratoltese kesz"
if cache.get('dhcp_lock'):
cache.delete("dhcp_lock")
reload_dhcp_task.delay(dhcp())
print "dhcp ujratoltese kesz"
if cache.get('firewall_lock'):
cache.delete("firewall_lock")
ipv4 = Firewall().get()
ipv6 = Firewall(True).get()
reload_firewall_task.delay(ipv4, ipv6)
print "firewall ujratoltese kesz"
if cache.get('blacklist_lock'):
cache.delete("blacklist_lock")
reload_blacklist_task.delay(list(ipset()))
print "blacklist ujratoltese kesz"
class ReloadTask(Task): class ReloadTask(Task):
def run(self, type='Host'): def run(self, type='Host'):
sleep=False
if type in ["Host", "Records", "Domain", "Vlan"]: if type in ["Host", "Records", "Domain", "Vlan"]:
lock = lambda: cache.add("dns_lock", "true", 9) cache.add("dns_lock", "true", 30)
if lock():
if not sleep:
sleep = True
time.sleep(10)
reload_dns_task.delay(dns())
if type == "Host": if type == "Host":
lock = lambda: cache.add("dhcp_lock", "true", 9) cache.add("dhcp_lock", "true", 30)
if lock():
if not sleep:
sleep = True
time.sleep(10)
reload_dhcp_task.delay(dhcp())
if type in ["Host", "Rule", "Firewall"]: if type in ["Host", "Rule", "Firewall"]:
lock = lambda: cache.add("firewall_lock", "true", 9) cache.add("firewall_lock", "true", 30)
if lock():
if not sleep:
sleep = True
time.sleep(10)
ipv4 = Firewall().get()
ipv6 = Firewall(True).get()
reload_firewall_task.delay(ipv4, ipv6)
if type == "Blacklist": if type == "Blacklist":
lock = lambda: cache.add("blacklist_lock", "true", 9) cache.add("blacklist_lock", "true", 30)
if lock():
if not sleep:
sleep = True
time.sleep(10)
reload_blacklist_task.delay(list(ipset()))
print type print type
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