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
5c67df1a
authored
Nov 12, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
firewall: make convert_ipv4_to_ipv6 a Vlan method
parent
260a5a7c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
13 deletions
+8
-13
circle/firewall/fields.py
+0
-9
circle/firewall/models.py
+8
-4
No files found.
circle/firewall/fields.py
View file @
5c67df1a
...
...
@@ -329,12 +329,3 @@ def val_mx(value):
domain_re
.
match
(
mx
[
1
])):
raise
ValidationError
(
_
(
"Bad MX address format. "
"Should be: <priority>:<hostname>"
))
def
convert_ipv4_to_ipv6
(
ipv6_template
,
ipv4
):
"""Convert IPv4 address string to IPv6 address string."""
m
=
ipv4
.
words
return
IPAddress
(
ipv6_template
%
{
'a'
:
int
(
m
[
0
]),
'b'
:
int
(
m
[
1
]),
'c'
:
int
(
m
[
2
]),
'd'
:
int
(
m
[
3
])})
circle/firewall/models.py
View file @
5c67df1a
...
...
@@ -29,7 +29,7 @@ from django.utils.translation import ugettext_lazy as _
from
firewall.fields
import
(
MACAddressField
,
val_alfanum
,
val_reverse_domain
,
val_ipv6_template
,
val_domain
,
val_ipv4
,
val_domain_wildcard
,
val_ipv6
,
val_mx
,
convert_ipv4_to_ipv6
,
val_ipv6
,
val_mx
,
IPNetworkField
,
IPAddressField
)
from
django.core.validators
import
MinValueValidator
,
MaxValueValidator
import
django.conf
...
...
@@ -403,7 +403,7 @@ class Vlan(AclBase, models.Model):
logger
.
debug
(
"Found unused IPv4 address
%
s."
,
ipv4
)
ipv6
=
None
if
self
.
network6
is
not
None
:
ipv6
=
convert_ipv4_to_ipv6
(
self
.
ipv6_template
,
ipv4
)
ipv6
=
self
.
convert_ipv4_to_ipv6
(
ipv4
)
if
ipv6
in
used_v6
:
continue
else
:
...
...
@@ -412,6 +412,11 @@ class Vlan(AclBase, models.Model):
else
:
raise
ValidationError
(
_
(
"All IP addresses are already in use."
))
def
convert_ipv4_to_ipv6
(
self
,
ipv4
):
"""Convert IPv4 address string to IPv6 address string."""
nums
=
{
ascii_letters
[
i
]:
int
(
ipv4
.
words
[
i
])
for
i
in
range
(
4
)}
return
IPAddress
(
self
.
ipv6_template
%
nums
)
class
VlanGroup
(
models
.
Model
):
"""
...
...
@@ -582,8 +587,7 @@ class Host(models.Model):
def
save
(
self
,
*
args
,
**
kwargs
):
if
not
self
.
id
and
self
.
ipv6
==
"auto"
:
self
.
ipv6
=
convert_ipv4_to_ipv6
(
self
.
vlan
.
ipv6_template
,
self
.
ipv4
)
self
.
ipv6
=
self
.
vlan
.
convert_ipv4_to_ipv6
(
self
.
ipv4
)
self
.
full_clean
()
super
(
Host
,
self
)
.
save
(
*
args
,
**
kwargs
)
...
...
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