Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nemu3
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
nemu3
Commits
08af99db
Commit
08af99db
authored
Jul 22, 2010
by
Martín Ferrari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bridge commands
parent
4b8662d2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
0 deletions
+36
-0
src/netns/iproute.py
src/netns/iproute.py
+36
-0
No files found.
src/netns/iproute.py
View file @
08af99db
...
...
@@ -4,6 +4,8 @@ import re, subprocess, sys
import
netns.interface
# XXX: ideally this should be replaced by netlink communication
# Interface handling
def
get_if_data
():
"""Gets current interface information. Returns a tuple (byidx, bynam) in
which each element is a dictionary with the same data, but using different
...
...
@@ -145,6 +147,8 @@ def change_netns(iface, netns):
ifname
=
_get_if_name
(
iface
)
_execute
([
"ip"
,
"link"
,
"set"
,
"dev"
,
ifname
,
"netns"
,
str
(
netns
)])
# Address handling
def
add_addr
(
iface
,
address
):
ifname
=
_get_if_name
(
iface
)
addresses
=
get_addr_data
()[
1
][
ifname
]
...
...
@@ -187,6 +191,38 @@ def set_addr(iface, addresses, recover = True):
set_addr
(
orig_addresses
,
recover
=
False
)
# rollback
raise
# Bridge handling
def
create_bridge
(
br
):
if
isinstance
(
br
,
str
):
br
=
interface
(
name
=
br
)
assert
br
.
name
_execute
([
'brctl'
,
'addbr'
,
br
.
name
])
try
:
set_if
(
br
)
except
:
(
t
,
v
,
bt
)
=
sys
.
exc_info
()
try
:
del_bridge
(
br
)
except
:
pass
raise
t
,
v
,
bt
return
get_if_data
()[
1
][
br
.
name
]
def
del_bridge
(
br
):
brname
=
_get_if_name
(
br
)
_execute
([
"brctl"
,
"delbr"
,
brname
])
def
add_bridge_port
(
br
,
iface
):
ifname
=
_get_if_name
(
iface
)
brname
=
_get_if_name
(
br
)
_execute
([
'brctl'
,
'addif'
,
brname
,
ifname
])
def
del_bridge_port
(
br
,
iface
):
ifname
=
_get_if_name
(
iface
)
brname
=
_get_if_name
(
br
)
_execute
([
'brctl'
,
'delif'
,
brname
,
ifname
])
# Useful stuff
def
_execute
(
cmd
):
...
...
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