Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
circlestack
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
3d3bfaae
authored
Oct 08, 2013
by
Bach Dániel
Committed by
Bach Dániel
Oct 14, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
firewall: new models: SwitchPort, EthernetDevice
parent
e23b3021
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
68 additions
and
7 deletions
+68
-7
circle/firewall/fields.py
+4
-2
circle/firewall/fw.py
+22
-4
circle/firewall/migrations/0035_auto__add_switchport__add_ethernetdevice.py
+0
-0
circle/firewall/migrations/0036_auto__chg_field_switchport_tagged_vlans.py
+0
-0
circle/firewall/models.py
+41
-0
circle/firewall/tasks/local_tasks.py
+1
-1
No files found.
circle/firewall/fields.py
View file @
3d3bfaae
...
@@ -91,9 +91,11 @@ class IPNetworkField(models.Field):
...
@@ -91,9 +91,11 @@ class IPNetworkField(models.Field):
if
isinstance
(
value
,
IPNetwork
):
if
isinstance
(
value
,
IPNetwork
):
if
self
.
version
==
4
:
if
self
.
version
==
4
:
return
'.'
.
join
(
map
(
lambda
x
:
"
%03
d"
%
x
,
value
.
ip
.
words
))
+
'/
%
d'
%
value
.
prefixlen
return
(
'.'
.
join
([
"
%03
d"
%
x
for
x
in
value
.
ip
.
words
])
+
'/
%02
d'
%
value
.
prefixlen
)
else
:
else
:
return
':'
.
join
(
map
(
lambda
x
:
"
%04
X"
%
x
,
value
.
ip
.
words
))
+
'/
%
d'
%
value
.
prefixlen
return
(
':'
.
join
([
"
%04
X"
%
x
for
x
in
value
.
ip
.
words
])
+
'/
%03
d'
%
value
.
prefixlen
)
return
value
return
value
def
value_to_string
(
self
,
obj
):
def
value_to_string
(
self
,
obj
):
...
...
circle/firewall/fw.py
View file @
3d3bfaae
...
@@ -440,7 +440,25 @@ def dhcp():
...
@@ -440,7 +440,25 @@ def dhcp():
def
vlan
():
def
vlan
():
obj
=
models
.
Vlan
.
objects
.
values
(
'vid'
,
'name'
,
'network4'
,
'network6'
)
obj
=
models
.
Vlan
.
objects
.
values
(
'vid'
,
'name'
,
'network4'
,
'network6'
)
return
{
x
[
'name'
]:
{
'tag'
:
x
[
'vid'
],
retval
=
{
x
[
'name'
]:
{
'tag'
:
x
[
'vid'
],
'addresses'
:
[
str
(
x
[
'network4'
]),
'type'
:
'internal'
,
str
(
x
[
'network6'
])]}
'interfaces'
:
[
x
[
'name'
]],
for
x
in
obj
}
'addresses'
:
[
str
(
x
[
'network4'
]),
str
(
x
[
'network6'
])]}
for
x
in
obj
}
for
p
in
models
.
SwitchPort
.
objects
.
all
():
eth_count
=
p
.
ethernet_devices
.
count
()
if
eth_count
>
1
:
name
=
'bond
%
d'
%
p
.
id
elif
eth_count
==
1
:
name
=
p
.
ethernet_devices
.
get
()
.
name
else
:
# 0
continue
tag
=
p
.
untagged_vlan
.
vid
retval
[
name
]
=
{
'tag'
:
tag
}
if
p
.
tagged_vlans
is
not
None
:
trunk
=
list
(
p
.
tagged_vlans
.
vlans
.
values_list
(
'vid'
,
flat
=
True
))
retval
[
name
][
'trunks'
]
=
sorted
(
trunk
)
retval
[
name
][
'interfaces'
]
=
list
(
p
.
ethernet_devices
.
values_list
(
'name'
,
flat
=
True
))
return
retval
circle/firewall/migrations/0035_auto__add_switchport__add_ethernetdevice.py
0 → 100644
View file @
3d3bfaae
This diff is collapsed.
Click to expand it.
circle/firewall/migrations/0036_auto__chg_field_switchport_tagged_vlans.py
0 → 100644
View file @
3d3bfaae
This diff is collapsed.
Click to expand it.
circle/firewall/models.py
View file @
3d3bfaae
...
@@ -768,6 +768,47 @@ class Record(models.Model):
...
@@ -768,6 +768,47 @@ class Record(models.Model):
)
)
class
SwitchPort
(
models
.
Model
):
untagged_vlan
=
models
.
ForeignKey
(
'Vlan'
,
related_name
=
'untagged_ports'
,
verbose_name
=
_
(
'untagged vlan'
))
tagged_vlans
=
models
.
ForeignKey
(
'VlanGroup'
,
blank
=
True
,
null
=
True
,
related_name
=
'tagged_ports'
,
verbose_name
=
_
(
'tagged vlans'
))
description
=
models
.
TextField
(
blank
=
True
,
verbose_name
=
_
(
'description'
))
created_at
=
models
.
DateTimeField
(
auto_now_add
=
True
,
verbose_name
=
_
(
'created_at'
))
modified_at
=
models
.
DateTimeField
(
auto_now
=
True
,
verbose_name
=
_
(
'modified_at'
))
def
__unicode__
(
self
):
devices
=
','
.
join
(
self
.
ethernet_devices
.
values_list
(
'name'
,
flat
=
True
))
tagged_vlans
=
self
.
tagged_vlans
.
name
if
self
.
tagged_vlans
else
''
return
'devices=
%
s untagged=
%
s tagged=
%
s'
%
(
devices
,
self
.
untagged_vlan
,
tagged_vlans
)
class
EthernetDevice
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
20
,
unique
=
True
,
verbose_name
=
_
(
'interface'
),
help_text
=
_
(
'The name of network interface the '
'gateway should serve this network '
'on. For example eth2.'
))
switch_port
=
models
.
ForeignKey
(
'SwitchPort'
,
related_name
=
'ethernet_devices'
,
verbose_name
=
_
(
'switch port'
))
created_at
=
models
.
DateTimeField
(
auto_now_add
=
True
,
verbose_name
=
_
(
'created_at'
))
modified_at
=
models
.
DateTimeField
(
auto_now
=
True
,
verbose_name
=
_
(
'modified_at'
))
def
__unicode__
(
self
):
return
self
.
name
class
Blacklist
(
models
.
Model
):
class
Blacklist
(
models
.
Model
):
CHOICES_type
=
((
'permban'
,
'permanent ban'
),
(
'tempban'
,
'temporary ban'
),
CHOICES_type
=
((
'permban'
,
'permanent ban'
),
(
'tempban'
,
'temporary ban'
),
(
'whitelist'
,
'whitelist'
),
(
'tempwhite'
,
'tempwhite'
))
(
'whitelist'
,
'whitelist'
),
(
'tempwhite'
,
'tempwhite'
))
...
...
circle/firewall/tasks/local_tasks.py
View file @
3d3bfaae
...
@@ -56,7 +56,7 @@ def reloadtask(type='Host'):
...
@@ -56,7 +56,7 @@ def reloadtask(type='Host'):
if
type
==
"Blacklist"
:
if
type
==
"Blacklist"
:
cache
.
add
(
"blacklist_lock"
,
"true"
,
30
)
cache
.
add
(
"blacklist_lock"
,
"true"
,
30
)
if
type
==
"Vlan"
:
if
type
in
[
"Vlan"
,
"SwitchPort"
,
"EthernetDevice"
]
:
cache
.
add
(
"firewall_vlan_lock"
,
"true"
,
30
)
cache
.
add
(
"firewall_vlan_lock"
,
"true"
,
30
)
print
type
print
type
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