tasks.py 1.67 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
from cloud.settings import firewall_settings as settings
8

9 10 11 12 13 14 15 16 17
@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
18 19 20
@celery.task
def reload_blacklist_task(data):
    pass
21

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

    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"

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

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

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

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

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

64
        print type
x committed
65