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
a260b16e
Commit
a260b16e
authored
Jul 26, 2010
by
Martín Ferrari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add and delete routes
parent
05772b1d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
2 deletions
+29
-2
src/netns/iproute.py
src/netns/iproute.py
+29
-2
No files found.
src/netns/iproute.py
View file @
a260b16e
...
@@ -550,6 +550,7 @@ def del_bridge_port(br, iface):
...
@@ -550,6 +550,7 @@ def del_bridge_port(br, iface):
_execute
([
'brctl'
,
'delif'
,
brname
,
ifname
])
_execute
([
'brctl'
,
'delif'
,
brname
,
ifname
])
def
get_all_route_data
():
def
get_all_route_data
():
# FIXME: should be two calls or something else...
ipcmd
=
subprocess
.
Popen
([
"ip"
,
"-o"
,
"route"
,
"list"
,
"table"
,
"all"
],
ipcmd
=
subprocess
.
Popen
([
"ip"
,
"-o"
,
"route"
,
"list"
,
"table"
,
"all"
],
stdout
=
subprocess
.
PIPE
)
stdout
=
subprocess
.
PIPE
)
ipdata
=
ipcmd
.
communicate
()[
0
]
ipdata
=
ipcmd
.
communicate
()[
0
]
...
@@ -565,11 +566,37 @@ def get_all_route_data():
...
@@ -565,11 +566,37 @@ def get_all_route_data():
r'(\
S+)(?:
via (\
S+))? de
v (\
S+)
', line)
r'(\
S+)(?:
via (\
S+))? de
v (\
S+)
', line)
if not match:
if not match:
raise RuntimeError("Invalid output from `ip route'")
raise RuntimeError("Invalid output from `ip route'")
t
y
pe = match.group(1) or 'unicast'
t
i
pe = match.group(1) or 'unicast'
prefix = match.group(2)
prefix = match.group(2)
nexthop = match.group(3)
nexthop = match.group(3)
device = ifdata[match.group(4)]
device = ifdata[match.group(4)]
if prefix == 'default' or re.search(r'/0$', prefix):
if prefix == 'default' or re.search(r'/0$', prefix):
prefix = None
prefix = None
ret.append((t
y
pe, prefix, nexthop, device))
ret.append((t
i
pe, prefix, nexthop, device))
return ret
return ret
def get_route_data():
# filter out non-unicast routes
return [x for x in get_all_route_data() if x[0] == 'unicast']
def del_route(tipe, prefix, nexthop, device):
_add_del_route('del', tipe, prefix, nexthop, device)
def add_route(tipe, prefix, nexthop, device):
_add_del_route('add', tipe, prefix, nexthop, device)
def _add_del_route(action, tipe, prefix, nexthop, device):
cmd = ['ip', 'route', action]
if device:
device = _get_if_name(device)
if tipe and tipe != 'unicast':
cmd += [tipe]
if prefix:
cmd += [prefix]
else:
cmd += ['default']
if nexthop:
cmd += ['via', nexthop]
if device:
cmd += ['dev', device]
_execute(cmd)
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