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
620446da
Commit
620446da
authored
Jul 22, 2010
by
Martín Ferrari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reorder function
parent
2564750f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
22 deletions
+22
-22
src/netns/iproute.py
src/netns/iproute.py
+22
-22
No files found.
src/netns/iproute.py
View file @
620446da
...
@@ -40,28 +40,6 @@ def get_if(iface):
...
@@ -40,28 +40,6 @@ def get_if(iface):
return
ifdata
[
0
][
iface
]
return
ifdata
[
0
][
iface
]
return
ifdata
[
1
][
iface
]
return
ifdata
[
1
][
iface
]
def
get_addr_data
():
ipcmd
=
subprocess
.
Popen
([
"ip"
,
"-o"
,
"addr"
,
"list"
],
stdout
=
subprocess
.
PIPE
)
ipdata
=
ipcmd
.
communicate
()[
0
]
assert
ipcmd
.
wait
()
==
0
byidx
=
{}
bynam
=
{}
for
line
in
ipdata
.
split
(
"
\
n
"
):
if
line
==
""
:
continue
match
=
re
.
search
(
r'^(\
d+):
\s+(\
S+?)(:?)
\s+(.*)'
,
line
)
if
not
match
:
raise
RuntimeError
(
"Invalid `ip' command output"
)
idx
=
int
(
match
.
group
(
1
))
name
=
match
.
group
(
2
)
if
match
.
group
(
3
):
bynam
[
name
]
=
byidx
[
idx
]
=
[]
continue
# link info
bynam
[
name
].
append
(
netns
.
interface
.
address
.
parse_ip
(
match
.
group
(
4
)))
return
byidx
,
bynam
def
create_if_pair
(
if1
,
if2
):
def
create_if_pair
(
if1
,
if2
):
assert
if1
.
name
and
if2
.
name
assert
if1
.
name
and
if2
.
name
...
@@ -149,6 +127,28 @@ def change_netns(iface, netns):
...
@@ -149,6 +127,28 @@ def change_netns(iface, netns):
# Address handling
# Address handling
def
get_addr_data
():
ipcmd
=
subprocess
.
Popen
([
"ip"
,
"-o"
,
"addr"
,
"list"
],
stdout
=
subprocess
.
PIPE
)
ipdata
=
ipcmd
.
communicate
()[
0
]
assert
ipcmd
.
wait
()
==
0
byidx
=
{}
bynam
=
{}
for
line
in
ipdata
.
split
(
"
\
n
"
):
if
line
==
""
:
continue
match
=
re
.
search
(
r'^(\
d+):
\s+(\
S+?)(:?)
\s+(.*)'
,
line
)
if
not
match
:
raise
RuntimeError
(
"Invalid `ip' command output"
)
idx
=
int
(
match
.
group
(
1
))
name
=
match
.
group
(
2
)
if
match
.
group
(
3
):
bynam
[
name
]
=
byidx
[
idx
]
=
[]
continue
# link info
bynam
[
name
].
append
(
netns
.
interface
.
address
.
parse_ip
(
match
.
group
(
4
)))
return
byidx
,
bynam
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
]
...
...
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