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 ReloadTask(Task):
Bach Dániel committed
23 24 25
    def run(self, type='Host'):

        sleep=False
26 27 28 29

        if type in ["Host", "Records", "Domain", "Vlan"]:
            lock = lambda: cache.add("dns_lock", "true", 9)
            if lock():
Bach Dániel committed
30 31 32
                if not sleep:
                    sleep = True
                    time.sleep(10)
33
                reload_dns_task.delay(dns())
x committed
34

35 36 37
        if type == "Host":
            lock = lambda: cache.add("dhcp_lock", "true", 9)
            if lock():
Bach Dániel committed
38 39 40
                if not sleep:
                    sleep = True
                    time.sleep(10)
41
                reload_dhcp_task.delay(dhcp())
x committed
42

43 44 45
        if type in ["Host", "Rule", "Firewall"]:
            lock = lambda: cache.add("firewall_lock", "true", 9)
            if lock():
Bach Dániel committed
46 47 48
                if not sleep:
                    sleep = True
                    time.sleep(10)
49 50 51
                ipv4 = firewall().get()
                ipv6 = firewall(True).get()
                reload_firewall_task.delay(ipv4, ipv6)
x committed
52

53 54 55 56 57 58
        if type == "Blacklist":
            lock = lambda: cache.add("blacklist_lock", "true", 9)
            if lock():
                if not sleep:
                    sleep = True
                    time.sleep(10)
59
                reload_blacklist_task.delay(list(ipset()))
60

61
        print type
x committed
62