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):
...
@@ -64,7 +64,7 @@ def create_if_pair(if1, if2):
cmd
[
i
]
+=
[
"mtu"
,
str
(
iface
[
i
].
mtu
)]
cmd
[
i
]
+=
[
"mtu"
,
str
(
iface
[
i
].
mtu
)]
cmd
=
[
"ip"
,
"link"
,
"add"
]
+
cmd
[
0
]
+
[
"type"
,
"veth"
,
"peer"
]
+
cmd
[
1
]
cmd
=
[
"ip"
,
"link"
,
"add"
]
+
cmd
[
0
]
+
[
"type"
,
"veth"
,
"peer"
]
+
cmd
[
1
]
execute
(
cmd
)
_
execute
(
cmd
)
try
:
try
:
set_if
(
if1
)
set_if
(
if1
)
set_if
(
if2
)
set_if
(
if2
)
...
@@ -81,7 +81,7 @@ def create_if_pair(if1, if2):
...
@@ -81,7 +81,7 @@ def create_if_pair(if1, if2):
def
del_if
(
iface
):
def
del_if
(
iface
):
ifname
=
get_if_name
(
iface
)
ifname
=
get_if_name
(
iface
)
execute
([
"ip"
,
"link"
,
"del"
,
ifname
])
_
execute
([
"ip"
,
"link"
,
"del"
,
ifname
])
def
set_if
(
iface
,
recover
=
True
):
def
set_if
(
iface
,
recover
=
True
):
orig_iface
=
get_real_if
(
iface
)
orig_iface
=
get_real_if
(
iface
)
...
@@ -106,7 +106,7 @@ def set_if(iface, recover = True):
...
@@ -106,7 +106,7 @@ def set_if(iface, recover = True):
#print cmds
#print cmds
for
c
in
cmds
:
for
c
in
cmds
:
try
:
try
:
execute
(
c
)
_
execute
(
c
)
except
:
except
:
if
recover
:
if
recover
:
set_if
(
orig_iface
,
recover
=
False
)
# rollback
set_if
(
orig_iface
,
recover
=
False
)
# rollback
...
@@ -114,7 +114,7 @@ def set_if(iface, recover = True):
...
@@ -114,7 +114,7 @@ def set_if(iface, recover = True):
def
change_netns
(
iface
,
netns
):
def
change_netns
(
iface
,
netns
):
ifname
=
get_if_name
(
iface
)
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
):
def
add_addr
(
iface
,
address
):
ifname
=
get_if_name
(
iface
)
ifname
=
get_if_name
(
iface
)
...
@@ -125,7 +125,7 @@ def add_addr(iface, address):
...
@@ -125,7 +125,7 @@ def add_addr(iface, address):
"%s/%d"
%
(
address
.
address
,
int
(
address
.
prefix_len
))]
"%s/%d"
%
(
address
.
address
,
int
(
address
.
prefix_len
))]
if
hasattr
(
address
,
"broadcast"
):
if
hasattr
(
address
,
"broadcast"
):
cmd
+=
[
"broadcast"
,
address
.
broadcast
if
address
.
broadcast
else
"+"
]
cmd
+=
[
"broadcast"
,
address
.
broadcast
if
address
.
broadcast
else
"+"
]
execute
(
cmd
)
_
execute
(
cmd
)
def
del_addr
(
iface
,
address
):
def
del_addr
(
iface
,
address
):
ifname
=
get_if_name
(
iface
)
ifname
=
get_if_name
(
iface
)
...
@@ -134,7 +134,7 @@ def del_addr(iface, address):
...
@@ -134,7 +134,7 @@ def del_addr(iface, address):
cmd
=
[
"ip"
,
"addr"
,
"del"
,
"dev"
,
ifname
,
"local"
,
cmd
=
[
"ip"
,
"addr"
,
"del"
,
"dev"
,
ifname
,
"local"
,
"%s/%d"
%
(
address
.
address
,
int
(
address
.
prefix_len
))]
"%s/%d"
%
(
address
.
address
,
int
(
address
.
prefix_len
))]
execute
(
cmd
)
_
execute
(
cmd
)
def
set_addr
(
iface
,
addresses
,
recover
=
True
):
def
set_addr
(
iface
,
addresses
,
recover
=
True
):
ifname
=
get_if_name
(
iface
)
ifname
=
get_if_name
(
iface
)
...
@@ -160,7 +160,7 @@ def set_addr(iface, addresses, recover = True):
...
@@ -160,7 +160,7 @@ def set_addr(iface, addresses, recover = True):
# Useful stuff
# Useful stuff
def
execute
(
cmd
):
def
_
execute
(
cmd
):
print
" "
.
join
(
cmd
)
#; return
print
" "
.
join
(
cmd
)
#; return
null
=
open
(
'/dev/null'
,
'r+'
)
null
=
open
(
'/dev/null'
,
'r+'
)
p
=
subprocess
.
Popen
(
cmd
,
stdout
=
null
,
stderr
=
subprocess
.
PIPE
)
p
=
subprocess
.
Popen
(
cmd
,
stdout
=
null
,
stderr
=
subprocess
.
PIPE
)
...
@@ -182,7 +182,7 @@ def get_real_if(iface):
...
@@ -182,7 +182,7 @@ def get_real_if(iface):
def
get_if_name
(
iface
):
def
get_if_name
(
iface
):
if
isinstance
(
iface
,
netns
.
interface
.
interface
):
if
isinstance
(
iface
,
netns
.
interface
.
interface
):
if
iface
.
name
!=
None
:
if
iface
.
name
!=
None
:
return
iface
return
iface
.
name
if
isinstance
(
iface
,
str
):
if
isinstance
(
iface
,
str
):
return
iface
return
iface
return
get_real_if
(
iface
).
name
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