tasks.py 1.63 KB
Newer Older
1 2
import celery
from django.core.cache import cache
Bach Dániel committed
3
from firewall.fw import Firewall, dhcp, dns, ipset
4 5 6 7
import django.conf

settings = django.conf.settings.FIREWALL_SETTINGS

8

9 10 11
@celery.task
def reload_dns_task(data):
    pass
12 13


14 15 16
@celery.task
def reload_firewall_task(data4, data6):
    pass
17 18


19 20 21
@celery.task
def reload_dhcp_task(data):
    pass
22 23


24 25 26 27
@celery.task
def reload_blacklist_task(data):
    pass

28

29 30 31 32 33
@celery.task
def get_dhcp_clients_task(data):
    pass


Bach Dániel committed
34 35
@celery.task
def periodic_task():
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
        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"

58

Bach Dániel committed
59 60
@celery.task
def reloadtask(type='Host'):
61
        if type in ["Host", "Record", "Domain", "Vlan"]:
62 63 64 65 66 67 68 69 70 71 72 73
            cache.add("dns_lock", "true", 30)

        if type == "Host":
            cache.add("dhcp_lock", "true", 30)

        if type in ["Host", "Rule", "Firewall"]:
            cache.add("firewall_lock", "true", 30)

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

        print type