Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
94
Merge Requests
10
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
521aa877
authored
Nov 12, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
firewall: add get_dhcp_clients
parent
0dbc3afe
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
4 deletions
+22
-4
circle/firewall/models.py
+21
-4
circle/firewall/tasks/remote_tasks.py
+1
-0
No files found.
circle/firewall/models.py
View file @
521aa877
...
...
@@ -18,9 +18,9 @@
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
from
string
import
ascii_letters
from
itertools
import
islice
,
ifilter
from
itertools
import
islice
,
ifilter
,
chain
import
logging
from
netaddr
import
IPSet
,
EUI
,
IPNetwork
,
IPAddress
import
random
from
django.contrib.auth.models
import
User
from
django.db
import
models
...
...
@@ -34,10 +34,12 @@ from firewall.fields import (MACAddressField, val_alfanum, val_reverse_domain,
from
django.core.validators
import
MinValueValidator
,
MaxValueValidator
import
django.conf
from
django.db.models.signals
import
post_save
,
post_delete
import
random
from
celery.exceptions
import
TimeoutError
from
netaddr
import
IPSet
,
EUI
,
IPNetwork
,
IPAddress
from
common.models
import
method_cache
,
WorkerNotFound
,
HumanSortField
from
firewall.tasks.local_tasks
import
reloadtask
from
firewall.tasks.remote_tasks
import
get_dhcp_clients
from
.iptables
import
IptRule
from
acl.models
import
AclBase
...
...
@@ -419,6 +421,13 @@ class Vlan(AclBase, models.Model):
nums
=
{
ascii_letters
[
i
]:
int
(
ipv4
.
words
[
i
])
for
i
in
range
(
4
)}
return
IPAddress
(
self
.
ipv6_template
%
nums
)
def
get_dhcp_clients
(
self
):
macs
=
set
(
i
.
mac
for
i
in
self
.
host_set
.
all
())
return
[{
"mac"
:
k
,
"ip"
:
v
[
"ip"
],
"hostname"
:
v
[
"hostname"
]}
for
k
,
v
in
chain
(
*
(
fw
.
get_dhcp_clients
()
.
iteritems
()
for
fw
in
Firewall
.
objects
.
all
()
if
fw
))
if
v
[
"interface"
]
==
self
.
name
and
EUI
(
k
)
not
in
macs
]
class
VlanGroup
(
models
.
Model
):
"""
...
...
@@ -845,7 +854,7 @@ class Firewall(models.Model):
return
self
.
name
@method_cache
(
30
)
def
get_remote_queue_name
(
self
,
queue_id
):
def
get_remote_queue_name
(
self
,
queue_id
=
"firewall"
):
"""Returns the name of the remote celery queue for this node.
Throws Exception if there is no worker on the queue.
...
...
@@ -858,6 +867,14 @@ class Firewall(models.Model):
else
:
raise
WorkerNotFound
()
@method_cache
(
20
)
def
get_dhcp_clients
(
self
):
try
:
return
get_dhcp_clients
.
apply_async
(
queue
=
self
.
get_remote_queue_name
(),
expires
=
60
)
.
get
(
timeout
=
2
)
except
TimeoutError
:
return
None
class
Domain
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
40
,
validators
=
[
val_domain
],
...
...
circle/firewall/tasks/remote_tasks.py
View file @
521aa877
...
...
@@ -63,4 +63,5 @@ def reload_blacklist(data):
@celery.task
(
name
=
'firewall.get_dhcp_clients'
)
def
get_dhcp_clients
():
# {'00:21:5a:73:72:cd': {'interface': 'OFF', 'ip': None, 'hostname': None}}
pass
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