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
076f013e
Commit
076f013e
authored
May 26, 2010
by
Martín Ferrari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
separate utils
parent
7239f65b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
0 deletions
+66
-0
t/test_util.py
t/test_util.py
+66
-0
No files found.
t/test_util.py
0 → 100644
View file @
076f013e
#!/usr/bin/env python
# vim:ts=4:sw=4:et:ai:sts=4
import
re
import
subprocess
def
process_ipcmd
(
str
):
cur
=
None
out
=
{}
for
line
in
str
.
split
(
"
\
n
"
):
if
line
==
""
:
cur
=
None
continue
match
=
re
.
search
(
r'^(\
d+): (
\S+): <(\
S+)> m
tu (\
d+) qdisc (
\S+)'
,
line
)
if
match
!=
None
:
cur
=
match
.
group
(
2
)
out
[
cur
]
=
{
'idx'
:
match
.
group
(
1
),
'flags'
:
match
.
group
(
3
).
split
(
","
),
'mtu'
:
match
.
group
(
4
),
'qdisc'
:
match
.
group
(
5
),
'addr'
:
[]
}
out
[
cur
][
'up'
]
=
'UP'
in
out
[
cur
][
'flags'
]
continue
# Assume cur is defined
assert
cur
!=
None
match
=
re
.
search
(
r'^\
s+li
nk/\
S* ([
0-9a-f:]+)(?: |$)'
,
line
)
if
match
!=
None
:
out
[
cur
][
'lladdr'
]
=
match
.
group
(
1
)
continue
match
=
re
.
search
(
r'^\
s+i
net ([0-9.]+)/(\
d+)(?:
brd ([0-9.]+))?'
,
line
)
if
match
!=
None
:
out
[
cur
][
'addr'
].
append
({
'addr'
:
match
.
group
(
1
),
'plen'
:
int
(
match
.
group
(
2
)),
'bcast'
:
match
.
group
(
3
),
'family'
:
'inet'
})
continue
match
=
re
.
search
(
r'^\
s+i
net6 ([0-9a-f:]+)/(\
d+)(?: |$)
', line)
if match != None:
out[cur]['
addr
'].append({
'
addr
': match.group(1),
'
plen
': int(match.group(2)),
'
family
': '
inet6
'})
continue
match = re.search(r'
^
\
s
{
6
}
', line)
assert match != None
return out
def get_devs():
ipcmd = subprocess.Popen(["ip", "addr", "list"],
stdout = subprocess.PIPE)
(outdata, errdata) = ipcmd.communicate()
ipcmd.wait()
return process_ipcmd(outdata)
def get_devs_netns(node):
(outdata, errdata) = node.run_process(["ip", "addr", "list"])
return process_ipcmd(outdata)
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