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
a69a8cbf
Commit
a69a8cbf
authored
Jul 29, 2010
by
Martín Ferrari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix destroy() issues. Add import_if()
parent
564e6000
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
8 deletions
+14
-8
src/netns/node.py
src/netns/node.py
+14
-8
No files found.
src/netns/node.py
View file @
a69a8cbf
...
@@ -14,15 +14,16 @@ class Node(object):
...
@@ -14,15 +14,16 @@ class Node(object):
s
=
sorted
(
Node
.
_nodes
.
items
(),
key
=
lambda
x
:
x
[
0
])
s
=
sorted
(
Node
.
_nodes
.
items
(),
key
=
lambda
x
:
x
[
0
])
return
[
x
[
1
]
for
x
in
s
]
return
[
x
[
1
]
for
x
in
s
]
def
__init__
(
self
,
debug
=
False
,
nonetns
=
False
):
def
__init__
(
self
,
debug
=
0
,
nonetns
=
False
):
"""Create a new node in the emulation. Implemented as a separate
"""Create a new node in the emulation. Implemented as a separate
process in a new network name space. Requires root privileges to run.
process in a new network name space. Requires root privileges to run.
If keepns is true, the network name space is not created and can be run
If keepns is true, the network name space is not created and can be run
as a normal user, for testing. If debug is true, details of the
as a normal user, for testing. If debug is true, details of the
communication protocol are printed on stderr."""
communication protocol are printed on stderr."""
# Initialize attributes, in case something fails during __init__
# Initialize attributes, in case something fails during __init__
self
.
_pid
=
self
.
_
debug
=
self
.
_
slave
=
None
self
.
_pid
=
self
.
_slave
=
None
self
.
_processes
=
weakref
.
WeakValueDictionary
()
self
.
_processes
=
weakref
.
WeakValueDictionary
()
self
.
_interfaces
=
weakref
.
WeakValueDictionary
()
self
.
_interfaces
=
weakref
.
WeakValueDictionary
()
...
@@ -42,18 +43,19 @@ class Node(object):
...
@@ -42,18 +43,19 @@ class Node(object):
def
destroy
(
self
):
def
destroy
(
self
):
if
self
.
_debug
:
# pragma: no cover
if
self
.
_debug
:
# pragma: no cover
sys
.
stderr
.
write
(
"*** Node(%s) destroy
\
n
"
%
self
.
pid
)
sys
.
stderr
.
write
(
"*** Node(%s) destroy
\
n
"
%
self
.
pid
)
for
p
in
self
.
_processes
.
values
():
for
p
in
self
.
_processes
.
values
():
p
.
destroy
()
p
.
destroy
()
self
.
_processes
.
clear
()
# Use get_interfaces to force a rescan
# Use get_interfaces to force a rescan
for
i
in
self
.
get_interfaces
():
for
i
in
self
.
get_interfaces
():
i
.
destroy
()
i
.
destroy
()
self
.
_interfaces
.
clear
()
if
self
.
_slave
:
if
self
.
_slave
:
self
.
_slave
.
shutdown
()
self
.
_slave
.
shutdown
()
self
.
_pid
=
self
.
_slave
=
None
del
self
.
_processes
del
self
.
_interfaces
del
self
.
_pid
del
self
.
_slave
@
property
@
property
def
pid
(
self
):
def
pid
(
self
):
...
@@ -88,6 +90,9 @@ class Node(object):
...
@@ -88,6 +90,9 @@ class Node(object):
setattr
(
i
,
k
,
v
)
setattr
(
i
,
k
,
v
)
return
i
return
i
def
import_if
(
self
,
interface
):
return
netns
.
interface
.
ImportedNodeInterface
(
self
,
interface
)
def
del_if
(
self
,
iface
):
def
del_if
(
self
,
iface
):
"""Doesn't destroy the interface if it wasn't created by us."""
"""Doesn't destroy the interface if it wasn't created by us."""
del
self
.
_interfaces
[
iface
.
index
]
del
self
.
_interfaces
[
iface
.
index
]
...
@@ -107,7 +112,8 @@ class Node(object):
...
@@ -107,7 +112,8 @@ class Node(object):
for
i
in
list
(
self
.
_interfaces
):
# copy before deleting!
for
i
in
list
(
self
.
_interfaces
):
# copy before deleting!
if
i
not
in
ifaces
:
if
i
not
in
ifaces
:
if
self
.
_debug
:
if
self
.
_debug
:
sys
.
stderr
.
write
(
"WARNING: interface #%d went away."
%
i
)
sys
.
stderr
.
write
(
"WARNING: interface #%d went away.
\
n
"
%
i
)
self
.
_interfaces
[
i
].
destroy
()
del
self
.
_interfaces
[
i
]
del
self
.
_interfaces
[
i
]
return
sorted
(
ret
,
key
=
lambda
x
:
x
.
index
)
return
sorted
(
ret
,
key
=
lambda
x
:
x
.
index
)
...
...
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