tasks.py 1.68 KB
Newer Older
1
from celery.task import Task, PeriodicTask
2
import celery
3 4
from django.core.cache import cache
import os
5
import time
6
from firewall.fw import *
Őry Máté committed
7 8 9
import django.conf

settings = django.conf.settings.FIREWALL_SETTINGS
10

11 12 13 14 15 16 17 18 19
@celery.task
def reload_dns_task(data):
    pass
@celery.task
def reload_firewall_task(data4, data6):
    pass
@celery.task
def reload_dhcp_task(data):
    pass
20 21 22
@celery.task
def reload_blacklist_task(data):
    pass
23

24
class Periodic(PeriodicTask):
Bach Dániel committed
25
    run_every = timedelta(seconds=10)
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50

    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"

51
class ReloadTask(Task):
Bach Dániel committed
52 53
    def run(self, type='Host'):

54
        if type in ["Host", "Records", "Domain", "Vlan"]:
55
            cache.add("dns_lock", "true", 30)
x committed
56

57
        if type == "Host":
58
            cache.add("dhcp_lock", "true", 30)
x committed
59

60
        if type in ["Host", "Rule", "Firewall"]:
61
            cache.add("firewall_lock", "true", 30)
x committed
62

63
        if type == "Blacklist":
64
            cache.add("blacklist_lock", "true", 30)
65

66
        print type
x committed
67