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
af581ee6
authored
Feb 28, 2014
by
Bach Dániel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
firewall: add new IP allocation policy
fixes #88
parent
0dce6c0d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
3 deletions
+18
-3
circle/firewall/models.py
+18
-3
circle/firewall/tests/test_firewall.py
+0
-0
No files found.
circle/firewall/models.py
View file @
af581ee6
# -*- coding: utf-8 -*-
from
itertools
import
islice
from
itertools
import
islice
,
chain
import
logging
from
netaddr
import
IPSet
...
...
@@ -298,13 +298,28 @@ class Vlan(AclBase, models.Model):
def
prefix6
(
self
):
return
self
.
network6
.
prefixlen
def
get_next_address
(
self
,
used_v4
):
try
:
last_address
=
list
(
used_v4
)[
-
1
]
except
IndexError
:
return
[]
next_address
=
last_address
+
1
if
next_address
in
self
.
network4
.
iter_hosts
():
logger
.
debug
(
"Found unused IPv4 address
%
s after
%
s."
,
next_address
,
last_address
)
return
[
next_address
]
else
:
return
[]
def
get_new_address
(
self
):
hosts
=
Host
.
objects
.
filter
(
vlan
=
self
)
hosts
=
self
.
host_set
used_v4
=
IPSet
(
hosts
.
values_list
(
'ipv4'
,
flat
=
True
))
used_v6
=
IPSet
(
hosts
.
exclude
(
ipv6__isnull
=
True
)
.
values_list
(
'ipv6'
,
flat
=
True
))
for
ipv4
in
islice
(
self
.
network4
.
iter_hosts
(),
10000
):
for
ipv4
in
chain
(
self
.
get_next_address
(
used_v4
),
islice
(
self
.
network4
.
iter_hosts
(),
10000
)):
ipv4
=
str
(
ipv4
)
if
ipv4
not
in
used_v4
:
logger
.
debug
(
"Found unused IPv4 address
%
s."
,
ipv4
)
...
...
circle/firewall/tests.py
→
circle/firewall/tests
/test_firewall
.py
View file @
af581ee6
File moved
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