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
5c425930
Commit
5c425930
authored
Jul 20, 2010
by
Martín Ferrari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some minor improvements
parent
8ec800fe
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
21 deletions
+20
-21
src/netns/iproute.py
src/netns/iproute.py
+19
-19
src/netns/protocol.py
src/netns/protocol.py
+1
-2
No files found.
src/netns/iproute.py
View file @
5c425930
...
@@ -27,6 +27,17 @@ def get_if_data():
...
@@ -27,6 +27,17 @@ def get_if_data():
byidx
[
idx
]
=
bynam
[
i
.
name
]
=
i
byidx
[
idx
]
=
bynam
[
i
.
name
]
=
i
return
byidx
,
bynam
return
byidx
,
bynam
def
get_if
(
iface
):
ifdata
=
get_if_data
()
if
isinstance
(
iface
,
netns
.
interface
.
interface
):
if
iface
.
index
!=
None
:
return
ifdata
[
0
][
iface
.
index
]
else
:
return
ifdata
[
1
][
iface
.
name
]
if
isinstance
(
iface
,
int
):
return
ifdata
[
0
][
iface
]
return
ifdata
[
1
][
iface
]
def
get_addr_data
():
def
get_addr_data
():
ipcmd
=
subprocess
.
Popen
([
"ip"
,
"-o"
,
"addr"
,
"list"
],
ipcmd
=
subprocess
.
Popen
([
"ip"
,
"-o"
,
"addr"
,
"list"
],
stdout
=
subprocess
.
PIPE
)
stdout
=
subprocess
.
PIPE
)
...
@@ -80,11 +91,11 @@ def create_if_pair(if1, if2):
...
@@ -80,11 +91,11 @@ def create_if_pair(if1, if2):
return
interfaces
[
if1
.
name
],
interfaces
[
if2
.
name
]
return
interfaces
[
if1
.
name
],
interfaces
[
if2
.
name
]
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_if
(
iface
)
_ils
=
[
"ip"
,
"link"
,
"set"
,
"dev"
,
orig_iface
.
name
]
_ils
=
[
"ip"
,
"link"
,
"set"
,
"dev"
,
orig_iface
.
name
]
diff
=
iface
-
orig_iface
# Only set what's needed
diff
=
iface
-
orig_iface
# Only set what's needed
cmds
=
[]
cmds
=
[]
...
@@ -119,11 +130,11 @@ def set_if(iface, recover = True):
...
@@ -119,11 +130,11 @@ def set_if(iface, recover = True):
raise
raise
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
)
addresses
=
get_addr_data
()[
1
][
ifname
]
addresses
=
get_addr_data
()[
1
][
ifname
]
assert
address
not
in
addresses
assert
address
not
in
addresses
...
@@ -134,7 +145,7 @@ def add_addr(iface, address):
...
@@ -134,7 +145,7 @@ def add_addr(iface, address):
_execute
(
cmd
)
_execute
(
cmd
)
def
del_addr
(
iface
,
address
):
def
del_addr
(
iface
,
address
):
ifname
=
get_if_name
(
iface
)
ifname
=
_
get_if_name
(
iface
)
addresses
=
get_addr_data
()[
1
][
ifname
]
addresses
=
get_addr_data
()[
1
][
ifname
]
assert
address
in
addresses
assert
address
in
addresses
...
@@ -143,7 +154,7 @@ def del_addr(iface, address):
...
@@ -143,7 +154,7 @@ def del_addr(iface, address):
_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
)
addresses
=
get_addr_data
()[
1
][
ifname
]
addresses
=
get_addr_data
()[
1
][
ifname
]
to_remove
=
set
(
orig_addresses
)
-
set
(
addresses
)
to_remove
=
set
(
orig_addresses
)
-
set
(
addresses
)
to_add
=
set
(
addresses
)
-
set
(
orig_addresses
)
to_add
=
set
(
addresses
)
-
set
(
orig_addresses
)
...
@@ -174,21 +185,10 @@ def _execute(cmd):
...
@@ -174,21 +185,10 @@ def _execute(cmd):
if
p
.
returncode
!=
0
:
if
p
.
returncode
!=
0
:
raise
RuntimeError
(
"Error executing `%s': %s"
%
(
" "
.
join
(
cmd
),
err
))
raise
RuntimeError
(
"Error executing `%s': %s"
%
(
" "
.
join
(
cmd
),
err
))
def
get_real_if
(
iface
):
def
_get_if_name
(
iface
):
ifdata
=
get_if_data
()
if
isinstance
(
iface
,
netns
.
interface
.
interface
):
if
iface
.
index
!=
None
:
return
ifdata
[
0
][
iface
.
index
]
else
:
return
ifdata
[
1
][
iface
.
name
]
if
isinstance
(
iface
,
int
):
return
ifdata
[
0
][
iface
]
return
ifdata
[
1
][
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
.
name
return
iface
.
name
if
isinstance
(
iface
,
str
):
if
isinstance
(
iface
,
str
):
return
iface
return
iface
return
get_
real_
if
(
iface
).
name
return
get_if
(
iface
).
name
src/netns/protocol.py
View file @
5c425930
...
@@ -535,8 +535,7 @@ class Client(object):
...
@@ -535,8 +535,7 @@ class Client(object):
def
set_if
(
self
,
interface
):
def
set_if
(
self
,
interface
):
cmd
=
[
"IF"
,
"SET"
,
interface
.
index
]
cmd
=
[
"IF"
,
"SET"
,
interface
.
index
]
for
k
in
(
"name"
,
"mtu"
,
"lladdr"
,
"broadcast"
,
"up"
,
"multicast"
,
for
k
in
interface
.
changeable_attributes
:
"arp"
):
v
=
getattr
(
interface
,
k
)
v
=
getattr
(
interface
,
k
)
if
v
!=
None
:
if
v
!=
None
:
cmd
+=
[
k
,
str
(
v
)]
cmd
+=
[
k
,
str
(
v
)]
...
...
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