Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Fukász Rómeó Ervin
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
ab7f458e
authored
Sep 02, 2014
by
Bach Dániel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
firewall: simplify Host.get_network_config()
parent
1767d22c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
6 deletions
+22
-6
circle/firewall/models.py
+22
-6
No files found.
circle/firewall/models.py
View file @
ab7f458e
...
...
@@ -530,6 +530,26 @@ class Host(models.Model):
def
incoming_rules
(
self
):
return
self
.
rules
.
filter
(
direction
=
'in'
)
@staticmethod
def
create_ipnetwork
(
ip
,
prefixlen
):
try
:
net
=
IPNetwork
(
ip
)
net
.
prefixlen
=
prefixlen
except
TypeError
:
return
None
else
:
return
net
@property
def
ipv4_with_vlan_prefixlen
(
self
):
return
Host
.
create_ipnetwork
(
self
.
ipv4
,
self
.
vlan
.
network4
.
prefixlen
)
@property
def
ipv6_with_vlan_prefixlen
(
self
):
return
Host
.
create_ipnetwork
(
self
.
ipv6
,
self
.
vlan
.
network6
.
prefixlen
)
@property
def
ipv6_with_prefixlen
(
self
):
try
:
...
...
@@ -604,15 +624,11 @@ class Host(models.Model):
interface
=
{
'addresses'
:
[]}
if
self
.
ipv4
and
self
.
vlan
.
network4
:
ipv4
=
IPNetwork
(
self
.
ipv4
)
ipv4
.
prefixlen
=
self
.
vlan
.
network4
.
prefixlen
interface
[
'addresses'
]
.
append
(
str
(
ipv4
))
interface
[
'addresses'
]
.
append
(
str
(
self
.
ipv4_with_vlan_prefixlen
))
interface
[
'gw4'
]
=
str
(
self
.
vlan
.
network4
.
ip
)
if
self
.
ipv6
and
self
.
vlan
.
network6
:
ipv6
=
IPNetwork
(
self
.
ipv6
)
ipv6
.
prefixlen
=
self
.
vlan
.
network6
.
prefixlen
interface
[
'addresses'
]
.
append
(
str
(
ipv6
))
interface
[
'addresses'
]
.
append
(
str
(
self
.
ipv4_with_vlan_prefixlen
))
interface
[
'gw6'
]
=
str
(
self
.
vlan
.
network6
.
ip
)
return
interface
...
...
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