Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gyuricska Milán
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
03024841
authored
Feb 14, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
firewall: refactor local_tasks
parent
e131b3e1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
51 deletions
+54
-51
circle/firewall/tasks/local_tasks.py
+54
-51
No files found.
circle/firewall/tasks/local_tasks.py
View file @
03024841
from
manager.mancelery
import
celery
from
django.core.cache
import
cache
from
logging
import
getLogger
from
socket
import
gethostname
import
django.conf
from
django.core.cache
import
cache
from
manager.mancelery
import
celery
settings
=
django
.
conf
.
settings
.
FIREWALL_SETTINGS
logger
=
getLogger
(
__name__
)
@celery.task
(
ignore_result
=
True
)
def
periodic_task
():
from
firewall.fw
import
Firewall
,
dhcp
,
dns
,
ipset
,
vlan
import
remote_tasks
if
cache
.
get
(
'dns_lock'
):
cache
.
delete
(
"dns_lock"
)
remote_tasks
.
reload_dns
.
apply_async
(
args
=
[
dns
()],
queue
=
'dns'
)
print
"dns ujratoltese kesz"
if
cache
.
get
(
'dhcp_lock'
):
cache
.
delete
(
"dhcp_lock"
)
remote_tasks
.
reload_dhcp
.
apply_async
(
args
=
[
dhcp
()],
queue
=
'firewall'
)
print
"dhcp ujratoltese kesz"
if
cache
.
get
(
'firewall_lock'
):
cache
.
delete
(
"firewall_lock"
)
ipv4
=
Firewall
(
proto
=
4
)
.
get
()
ipv6
=
Firewall
(
proto
=
6
)
.
get
()
remote_tasks
.
reload_firewall
.
apply_async
(
args
=
[
ipv4
,
ipv6
],
queue
=
'firewall'
)
print
"firewall ujratoltese kesz"
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"
if
cache
.
get
(
'blacklist_lock'
):
cache
.
delete
(
"blacklist_lock"
)
remote_tasks
.
reload_blacklist
.
apply_async
(
args
=
[
list
(
ipset
())],
queue
=
'firewall'
)
print
"blacklist ujratoltese kesz"
def
_apply_once
(
name
,
queues
,
task
,
data
):
"""Reload given networking component if needed.
"""
lockname
=
"
%
s_lock"
%
name
if
not
cache
.
get
(
lockname
):
return
cache
.
delete
(
lockname
)
@celery.task
def
reloadtask
(
type
=
'Host'
):
if
type
in
[
"Host"
,
"Record"
,
"Domain"
,
"Vlan"
]:
cache
.
add
(
"dns_lock"
,
"true"
,
30
)
for
queue
in
queues
:
task
.
apply_async
(
args
=
data
,
queue
=
queue
)
logger
.
info
(
"
%
s configuration is reloaded."
,
name
)
if
type
in
[
"Host"
,
"Vlan"
]:
cache
.
add
(
"dhcp_lock"
,
"true"
,
30
)
if
type
in
[
"Host"
,
"Rule"
,
"Firewall"
,
"Vlan"
]:
cache
.
add
(
"firewall_lock"
,
"true"
,
30
)
@celery.task
(
ignore_result
=
True
)
def
periodic_task
():
from
firewall.fw
import
Firewall
,
dhcp
,
dns
,
ipset
,
vlan
from
remote_tasks
import
(
reload_dns
,
reload_dhcp
,
reload_firewall
,
reload_firewall_vlan
,
reload_blacklist
)
firewall_queues
=
[(
"
%
s.firewall"
%
i
)
for
i
in
settings
.
get
(
'firewall_queues'
,
[
gethostname
()])]
dns_queues
=
[(
"
%
s.dns"
%
i
)
for
i
in
settings
.
get
(
'dns_queues'
,
[
gethostname
()])]
if
type
==
"Blacklist"
:
cache
.
add
(
"blacklist_lock"
,
"true"
,
30
)
_apply_once
(
'dns'
,
dns_queues
,
reload_dns
,
lambda
:
(
dns
(),
))
_apply_once
(
'dhcp'
,
firewall_queues
,
reload_dhcp
,
lambda
:
(
dhcp
(),
))
_apply_once
(
'firewall'
,
firewall_queues
,
reload_firewall
,
lambda
:
(
Firewall
(
proto
=
4
)
.
get
(),
Firewall
(
proto
=
6
)
.
get
()))
_apply_once
(
'firewall_vlan'
,
firewall_queues
,
reload_firewall_vlan
,
lambda
:
(
vlan
(),
))
_apply_once
(
'blacklist'
,
firewall_queues
,
reload_blacklist
,
lambda
:
(
list
(
ipset
()),
))
if
type
in
[
"Vlan"
,
"SwitchPort"
,
"EthernetDevice"
]:
cache
.
add
(
"firewall_vlan_lock"
,
"true"
,
30
)
print
type
@celery.task
def
reloadtask
(
type
=
'Host'
):
reload
=
{
'Host'
:
[
'dns'
,
'dhcp'
,
'firewall'
],
'Record'
:
[
'dns'
],
'Domain'
:
[
'dns'
],
'Vlan'
:
[
'dns'
,
'dhcp'
,
'firewall'
,
'firewall_vlan'
],
'Firewall'
:
[
'firewall'
],
'Rule'
:
[
'firewall'
],
'SwitchPort'
:
[
'firewall_vlan'
],
'EthernetDevice'
:
[
'firewall_vlan'
],
}[
type
]
logger
.
info
(
"Reload
%
s on next periodic iteration applying change to
%
s."
,
", "
.
join
(
reload
),
type
)
for
i
in
reload
:
cache
.
add
(
"
%
s_lock"
%
i
,
"true"
,
30
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment