local_tasks.py 2.19 KB
Newer Older
1
from manager.mancelery import celery
2 3 4 5
from django.core.cache import cache
import django.conf
settings = django.conf.settings.FIREWALL_SETTINGS

6

7
@celery.task
Bach Dániel committed
8
def periodic_task():
Bach Dániel committed
9 10 11
        from firewall.fw import Firewall, dhcp, dns, ipset, vlan
        import remote_tasks

12 13
        if cache.get('dns_lock'):
            cache.delete("dns_lock")
Bach Dániel committed
14 15
            remote_tasks.reload_dns.apply_async(args=[dns()],
                                                queue='dns')
16 17 18 19
            print "dns ujratoltese kesz"

        if cache.get('dhcp_lock'):
            cache.delete("dhcp_lock")
Bach Dániel committed
20 21
            remote_tasks.reload_dhcp.apply_async(args=[dhcp()],
                                                 queue='firewall')
22 23 24 25
            print "dhcp ujratoltese kesz"

        if cache.get('firewall_lock'):
            cache.delete("firewall_lock")
26 27
            ipv4 = Firewall(proto=4).get()
            ipv6 = Firewall(proto=6).get()
Bach Dániel committed
28 29
            remote_tasks.reload_firewall.apply_async(args=[ipv4, ipv6],
                                                     queue='firewall')
30 31
            print "firewall ujratoltese kesz"

32 33 34 35 36 37
        if cache.get('firewall_vlan_lock'):
            cache.delete("firewall_vlan_lock")
            remote_tasks.reload_firewall_vlan.apply_async(args=[vlan()],
                                                          queue='firewall')
            print "firewall_vlan ujratoltese kesz"

38 39
        if cache.get('blacklist_lock'):
            cache.delete("blacklist_lock")
Bach Dániel committed
40 41
            remote_tasks.reload_blacklist.apply_async(args=[list(ipset())],
                                                      queue='firewall')
42 43
            print "blacklist ujratoltese kesz"

44

Bach Dániel committed
45 46
@celery.task
def reloadtask(type='Host'):
47
        if type in ["Host", "Record", "Domain", "Vlan"]:
48 49
            cache.add("dns_lock", "true", 30)

50
        if type in ["Host", "Vlan"]:
51 52
            cache.add("dhcp_lock", "true", 30)

53
        if type in ["Host", "Rule", "Firewall", "Vlan"]:
54 55 56 57 58
            cache.add("firewall_lock", "true", 30)

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

59
        if type in ["Vlan", "SwitchPort", "EthernetDevice"]:
60 61
            cache.add("firewall_vlan_lock", "true", 30)

62
        print type