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
b420be8c
Commit
b420be8c
authored
Jul 20, 2010
by
Martín Ferrari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
hide execute(), fix a bug in get_if_name
parent
d0d3ea07
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
8 deletions
+8
-8
src/netns/iproute.py
src/netns/iproute.py
+8
-8
No files found.
src/netns/iproute.py
View file @
b420be8c
...
...
@@ -64,7 +64,7 @@ def create_if_pair(if1, if2):
cmd
[
i
]
+=
[
"mtu"
,
str
(
iface
[
i
].
mtu
)]
cmd
=
[
"ip"
,
"link"
,
"add"
]
+
cmd
[
0
]
+
[
"type"
,
"veth"
,
"peer"
]
+
cmd
[
1
]
execute
(
cmd
)
_
execute
(
cmd
)
try
:
set_if
(
if1
)
set_if
(
if2
)
...
...
@@ -81,7 +81,7 @@ def create_if_pair(if1, if2):
def
del_if
(
iface
):
ifname
=
get_if_name
(
iface
)
execute
([
"ip"
,
"link"
,
"del"
,
ifname
])
_
execute
([
"ip"
,
"link"
,
"del"
,
ifname
])
def
set_if
(
iface
,
recover
=
True
):
orig_iface
=
get_real_if
(
iface
)
...
...
@@ -106,7 +106,7 @@ def set_if(iface, recover = True):
#print cmds
for
c
in
cmds
:
try
:
execute
(
c
)
_
execute
(
c
)
except
:
if
recover
:
set_if
(
orig_iface
,
recover
=
False
)
# rollback
...
...
@@ -114,7 +114,7 @@ def set_if(iface, recover = True):
def
change_netns
(
iface
,
netns
):
ifname
=
get_if_name
(
iface
)
execute
([
"ip"
,
"link"
,
"set"
,
"dev"
,
ifname
,
"netns"
,
str
(
netns
)])
_
execute
([
"ip"
,
"link"
,
"set"
,
"dev"
,
ifname
,
"netns"
,
str
(
netns
)])
def
add_addr
(
iface
,
address
):
ifname
=
get_if_name
(
iface
)
...
...
@@ -125,7 +125,7 @@ def add_addr(iface, address):
"%s/%d"
%
(
address
.
address
,
int
(
address
.
prefix_len
))]
if
hasattr
(
address
,
"broadcast"
):
cmd
+=
[
"broadcast"
,
address
.
broadcast
if
address
.
broadcast
else
"+"
]
execute
(
cmd
)
_
execute
(
cmd
)
def
del_addr
(
iface
,
address
):
ifname
=
get_if_name
(
iface
)
...
...
@@ -134,7 +134,7 @@ def del_addr(iface, address):
cmd
=
[
"ip"
,
"addr"
,
"del"
,
"dev"
,
ifname
,
"local"
,
"%s/%d"
%
(
address
.
address
,
int
(
address
.
prefix_len
))]
execute
(
cmd
)
_
execute
(
cmd
)
def
set_addr
(
iface
,
addresses
,
recover
=
True
):
ifname
=
get_if_name
(
iface
)
...
...
@@ -160,7 +160,7 @@ def set_addr(iface, addresses, recover = True):
# Useful stuff
def
execute
(
cmd
):
def
_
execute
(
cmd
):
print
" "
.
join
(
cmd
)
#; return
null
=
open
(
'/dev/null'
,
'r+'
)
p
=
subprocess
.
Popen
(
cmd
,
stdout
=
null
,
stderr
=
subprocess
.
PIPE
)
...
...
@@ -182,7 +182,7 @@ def get_real_if(iface):
def
get_if_name
(
iface
):
if
isinstance
(
iface
,
netns
.
interface
.
interface
):
if
iface
.
name
!=
None
:
return
iface
return
iface
.
name
if
isinstance
(
iface
,
str
):
return
iface
return
get_real_if
(
iface
).
name
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