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
A prog2-höz tartozó friss repo anyagok itt elérhetőek:
https://git.iit.bme.hu/
Commit
aea8a13b
authored
Oct 30, 2013
by
Dudás Ádám
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fw: fix Vlan.get_new_address
parent
668d3099
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
8 deletions
+11
-8
circle/firewall/models.py
+11
-8
No files found.
circle/firewall/models.py
View file @
aea8a13b
# -*- coding: utf-8 -*-
from
itertools
import
islice
import
logging
from
netaddr
import
IPSet
from
django.contrib.auth.models
import
User
from
django.db
import
models
from
django.forms
import
ValidationError
...
...
@@ -13,6 +17,7 @@ from django.db.models.signals import post_save, post_delete
import
random
from
firewall.tasks.local_tasks
import
reloadtask
logger
=
logging
.
getLogger
(
__name__
)
settings
=
django
.
conf
.
settings
.
FIREWALL_SETTINGS
...
...
@@ -277,20 +282,18 @@ class Vlan(models.Model):
return
self
.
network6
.
prefixlen
def
get_new_address
(
self
):
i
=
0
hosts
=
Host
.
objects
.
filter
(
vlan
=
self
)
used_v4
=
hosts
.
values_list
(
'ipv4'
,
flat
=
True
)
used_v6
=
hosts
.
values_list
(
'ipv6'
,
flat
=
True
)
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
self
.
network4
.
iter_hosts
():
i
+=
1
if
i
>
10000
:
break
for
ipv4
in
islice
(
self
.
network4
.
iter_hosts
(),
10000
):
ipv4
=
str
(
ipv4
)
if
ipv4
not
in
used_v4
:
print
ipv4
logger
.
debug
(
"Found unused IPv4 address
%
s."
,
ipv4
)
ipv6
=
ipv4_2_ipv6
(
ipv4
)
if
ipv6
not
in
used_v6
:
logger
.
debug
(
"Found unused IPv6 address
%
s."
,
ipv6
)
return
{
'ipv4'
:
ipv4
,
'ipv6'
:
ipv6
}
raise
ValidationError
(
_
(
"All IP addresses are already in use."
))
...
...
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