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
089dbd85
Commit
089dbd85
authored
Jul 22, 2010
by
Martín Ferrari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Try to handle pre-existing interfaces. Add del_if
parent
ba49ec6d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
7 deletions
+47
-7
src/netns/interface.py
src/netns/interface.py
+21
-2
src/netns/node.py
src/netns/node.py
+26
-4
src/netns/protocol.py
src/netns/protocol.py
+0
-1
No files found.
src/netns/interface.py
View file @
089dbd85
...
@@ -5,8 +5,6 @@ import netns.iproute
...
@@ -5,8 +5,6 @@ import netns.iproute
__all__
=
[
'NodeInterface'
,
'P2PInterface'
,
'ExternalInterface'
]
__all__
=
[
'NodeInterface'
,
'P2PInterface'
,
'ExternalInterface'
]
# FIXME: should nodes register interfaces?
class
_Interface
(
object
):
class
_Interface
(
object
):
"""Just a base class for the *Interface classes: assign names and handle
"""Just a base class for the *Interface classes: assign names and handle
destruction."""
destruction."""
...
@@ -167,6 +165,7 @@ class ExternalInterface(_Interface):
...
@@ -167,6 +165,7 @@ class ExternalInterface(_Interface):
self
.
_ctl_if
=
iface
.
index
self
.
_ctl_if
=
iface
.
index
self
.
_original_state
=
iface
self
.
_original_state
=
iface
# FIXME: register somewhere for destruction!
def
destroy
(
self
):
# override: restore as much as possible
def
destroy
(
self
):
# override: restore as much as possible
try
:
try
:
netns
.
iproute
.
set_if
(
self
.
_original_state
)
netns
.
iproute
.
set_if
(
self
.
_original_state
)
...
@@ -177,6 +176,26 @@ class ExternalInterface(_Interface):
...
@@ -177,6 +176,26 @@ class ExternalInterface(_Interface):
def
control_index
(
self
):
def
control_index
(
self
):
return
self
.
_ctl_if
return
self
.
_ctl_if
class
ExternalNodeInterface
(
_NSInterface
):
"""Class to handle already existing interfaces inside a name space, usually
just the loopback device, but it can be other user-created interfaces. On
destruction, the code will try to restore the interface to the state it was
in before being imported into netns."""
def
__init__
(
self
,
node
,
iface
):
iface
=
node
.
_slave
.
get_if_data
(
iface
)
self
.
_original_state
=
iface
self
.
_ns_if
=
iface
.
index
self
.
_slave
=
node
.
_slave
node
.
_add_interface
(
self
)
# FIXME: register somewhere for destruction!
def
destroy
(
self
):
# override: restore as much as possible
try
:
self
.
_slave
.
set_if
(
self
.
_original_state
)
except
:
pass
# don't look after this :-)
# don't look after this :-)
# helpers
# helpers
...
...
src/netns/node.py
View file @
089dbd85
...
@@ -54,12 +54,16 @@ class Node(object):
...
@@ -54,12 +54,16 @@ class Node(object):
def
Subprocess
(
self
,
*
kargs
,
**
kwargs
):
def
Subprocess
(
self
,
*
kargs
,
**
kwargs
):
return
netns
.
subprocess_
.
Subprocess
(
self
,
*
kargs
,
**
kwargs
)
return
netns
.
subprocess_
.
Subprocess
(
self
,
*
kargs
,
**
kwargs
)
def
Popen
(
self
,
*
kargs
,
**
kwargs
):
def
Popen
(
self
,
*
kargs
,
**
kwargs
):
return
netns
.
subprocess_
.
Popen
(
self
,
*
kargs
,
**
kwargs
)
return
netns
.
subprocess_
.
Popen
(
self
,
*
kargs
,
**
kwargs
)
def
system
(
self
,
*
kargs
,
**
kwargs
):
def
system
(
self
,
*
kargs
,
**
kwargs
):
return
netns
.
subprocess_
.
system
(
self
,
*
kargs
,
**
kwargs
)
return
netns
.
subprocess_
.
system
(
self
,
*
kargs
,
**
kwargs
)
def
backticks
(
self
,
*
kargs
,
**
kwargs
):
def
backticks
(
self
,
*
kargs
,
**
kwargs
):
return
netns
.
subprocess_
.
backticks
(
self
,
*
kargs
,
**
kwargs
)
return
netns
.
subprocess_
.
backticks
(
self
,
*
kargs
,
**
kwargs
)
def
backticks_raise
(
self
,
*
kargs
,
**
kwargs
):
def
backticks_raise
(
self
,
*
kargs
,
**
kwargs
):
return
netns
.
subprocess_
.
backticks_raise
(
self
,
*
kargs
,
**
kwargs
)
return
netns
.
subprocess_
.
backticks_raise
(
self
,
*
kargs
,
**
kwargs
)
...
@@ -72,11 +76,29 @@ class Node(object):
...
@@ -72,11 +76,29 @@ class Node(object):
for
k
,
v
in
kwargs
.
items
():
for
k
,
v
in
kwargs
.
items
():
setattr
(
i
,
k
,
v
)
setattr
(
i
,
k
,
v
)
return
i
return
i
def
get_interfaces
(
self
):
# FIXME: loopback et al
s
=
sorted
(
self
.
_interfaces
.
items
(),
key
=
lambda
x
:
x
[
0
])
return
[
x
[
1
]
for
x
in
s
]
def
del_if
(
self
,
iface
):
"""Doesn't destroy the interface if it wasn't created by us."""
del
self
.
_interfaces
[
iface
.
index
]
iface
.
destroy
()
def
get_interfaces
(
self
):
ifaces
=
self
.
_slave
.
get_if_data
()
ret
=
[]
for
i
in
ifaces
:
if
i
not
in
self
.
_interfaces
:
ret
.
append
(
netns
.
interface
.
ExternalNodeInterface
(
self
,
i
))
else
:
ret
.
append
(
self
.
_interfaces
[
i
])
# by the way, clean up _interfaces
for
i
in
self
.
_interfaces
:
if
i
not
in
ifaces
:
sys
.
stderr
.
write
(
"WARNING: interface #%d went away."
%
i
)
del
self
.
_interfaces
[
i
]
return
sorted
(
ret
,
key
=
lambda
x
:
x
.
index
)
# FIXME: Routing
def
add_route
(
self
,
prefix
,
prefix_len
,
nexthop
=
None
,
interface
=
None
):
def
add_route
(
self
,
prefix
,
prefix_len
,
nexthop
=
None
,
interface
=
None
):
assert
nexthop
or
interface
assert
nexthop
or
interface
def
add_default_route
(
self
,
nexthop
,
interface
=
None
):
def
add_default_route
(
self
,
nexthop
,
interface
=
None
):
...
...
src/netns/protocol.py
View file @
089dbd85
...
@@ -422,7 +422,6 @@ class Client(object):
...
@@ -422,7 +422,6 @@ class Client(object):
e
=
yaml
.
load
(
text
)
e
=
yaml
.
load
(
text
)
raise
e
raise
e
if
code
/
100
!=
expected
:
if
code
/
100
!=
expected
:
# FIXME: shuld try to save and re-create exceptions
raise
RuntimeError
(
"Error from slave: %d %s"
%
(
code
,
text
))
raise
RuntimeError
(
"Error from slave: %d %s"
%
(
code
,
text
))
return
text
return
text
...
...
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