Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
fwdriver
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
bbcea33e
authored
Oct 14, 2014
by
Bach Dániel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add bridge support (export BRIDGE_TYPE=BRIDGE)
parent
7597bad1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
87 additions
and
2 deletions
+87
-2
fw.py
+9
-2
ovs.py
+78
-0
No files found.
fw.py
View file @
bbcea33e
...
...
@@ -4,7 +4,7 @@ import re
import
json
import
logging
from
ovs
import
Switch
from
ovs
import
Switch
,
Bridge
from
utils
import
(
ns_exec
,
sudo
,
ADDRESSES
,
dhcp_no_free_re
,
dhcp_ack_re
)
...
...
@@ -26,6 +26,12 @@ celery.conf.update(CELERY_CACHE_BACKEND=CACHE_URI,
logger
=
logging
.
getLogger
(
__name__
)
if
getenv
(
'BRIDGE_TYPE'
,
'OVS'
)
==
'BRIDGE'
:
network_type
=
Bridge
else
:
network_type
=
Switch
@task
(
name
=
"firewall.reload_firewall"
)
def
reload_firewall
(
data4
,
data6
,
save_config
=
True
):
try
:
...
...
@@ -52,7 +58,8 @@ def reload_firewall_vlan(data, save_config=True):
if
uplink
:
data
[
uplink
]
=
{
'interfaces'
:
uplink
}
br
=
Switch
(
'firewall'
)
print
network_type
br
=
network_type
(
'firewall'
)
br
.
migrate
(
data
)
if
save_config
:
...
...
ovs.py
View file @
bbcea33e
...
...
@@ -193,3 +193,81 @@ class Switch(object):
interface
.
migrate
()
except
CalledProcessError
as
e
:
logger
.
warning
(
e
)
class
Bridge
(
Switch
):
def
__init__
(
self
,
brname
):
self
.
brname
=
brname
self
.
brifnum
=
brname
try
:
sudo
((
'brctl'
,
'addbr'
,
brname
))
sudo
((
'ip'
,
'link'
,
'set'
,
'up'
,
brname
))
except
:
pass
def
find_data
(
self
,
data
,
tok
):
try
:
masteridx
=
data
.
index
(
tok
)
return
tuple
(
data
[
masteridx
+
1
:])
except
(
ValueError
,
IndexError
):
return
(
None
,
)
def
parse_ip_link
(
self
,
data
):
port
=
None
ports
=
{}
for
line
in
data
.
splitlines
():
t
=
line
.
split
()
if
line
.
startswith
(
' '
):
vlan
=
self
.
find_data
(
t
,
'802.1Q'
)
if
port
in
ports
and
vlan
and
vlan
[
0
]
==
'id'
:
ports
[
port
][
'tag'
]
=
vlan
[
1
]
else
:
port
,
sep
,
parent
=
t
[
1
]
.
rstrip
(
':'
)
.
partition
(
'@'
)
if
self
.
find_data
(
t
,
'master'
)[
0
]
==
self
.
brname
:
type
=
'external'
elif
(
parent
in
(
self
.
brname
,
self
.
brifnum
)
or
port
==
self
.
brname
):
type
=
'internal'
else
:
continue
ports
[
port
]
=
{
'type'
:
type
,
'ifnum'
:
t
[
0
]
.
rstrip
(
':'
)}
return
ports
def
list_ports
(
self
):
ports
=
self
.
parse_ip_link
(
sudo
((
'ip'
,
'-d'
,
'link'
,
'show'
)))
brport
=
ports
.
pop
(
self
.
brname
)
self
.
brifnum
=
'if
%
s'
%
brport
[
'ifnum'
]
ports
.
update
(
self
.
parse_ip_link
(
ns_exec
((
'ip'
,
'-d'
,
'link'
,
'show'
))))
return
[
Interface
(
name
,
data
,
with_show
=
True
)
for
name
,
data
in
ports
.
items
()]
def
delete_port
(
self
,
interface
):
try
:
if
interface
.
is_internal
:
ns_exec
((
'ip'
,
'link'
,
'del'
,
interface
.
name
))
else
:
sudo
((
'brctl'
,
'delif'
,
self
.
brname
,
interface
.
name
))
except
CalledProcessError
:
pass
def
add_port
(
self
,
interface
):
try
:
if
interface
.
is_internal
:
if
not
interface
.
untagged
:
return
sudo
((
'ip'
,
'link'
,
'add'
,
'link'
,
self
.
brname
,
'name'
,
interface
.
name
,
'type'
,
'vlan'
,
'id'
,
str
(
interface
.
untagged
)))
self
.
_setns
(
interface
.
name
)
else
:
sudo
((
'brctl'
,
'addif'
,
self
.
brname
,
interface
.
name
))
except
:
logger
.
exception
(
'Unhandled exception: '
)
if
__name__
==
"__main__"
:
br
=
Bridge
(
'br0'
)
print
br
.
list_ports
()
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