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
62e29870
Commit
62e29870
authored
Sep 01, 2010
by
Martín Ferrari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change the semantics of the migrate flag, to make it more intuitive
parent
3103ec9f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
19 deletions
+20
-19
src/netns/interface.py
src/netns/interface.py
+19
-18
src/netns/node.py
src/netns/node.py
+1
-1
No files found.
src/netns/interface.py
View file @
62e29870
...
@@ -182,38 +182,39 @@ class P2PInterface(NSInterface):
...
@@ -182,38 +182,39 @@ class P2PInterface(NSInterface):
class
ImportedNodeInterface
(
NSInterface
):
class
ImportedNodeInterface
(
NSInterface
):
"""Class to handle already existing interfaces inside a name space:
"""Class to handle already existing interfaces inside a name space:
real devices, tun devices, etc.
real devices, tun devices, etc.
The flag 'migrate' in the constructor indicates that the interface
wa
s
The flag 'migrate' in the constructor indicates that the interface
need
s
migrat
ed inside the name space.
to be mov
ed inside the name space.
On destruction, the interface will be restored to the original name space
On destruction, the interface will be restored to the original name space
and will try to restore the original state."""
and will try to restore the original state."""
def
__init__
(
self
,
node
,
iface
,
migrate
=
Fals
e
):
def
__init__
(
self
,
node
,
iface
,
migrate
=
Tru
e
):
self
.
_slave
=
None
self
.
_slave
=
None
self
.
_migrate
=
migrate
self
.
_migrate
=
migrate
if
self
.
_migrate
:
if
self
.
_migrate
:
iface
=
node
.
_slave
.
get_if_data
(
iface
)
self
.
_original_state
=
iface
.
copy
()
else
:
iface
=
netns
.
iproute
.
get_if
(
iface
)
iface
=
netns
.
iproute
.
get_if
(
iface
)
self
.
_original_state
=
iface
.
copy
()
self
.
_original_state
=
iface
.
copy
()
# Change the name to avoid clashes
# Change the name to avoid clashes
iface
.
name
=
self
.
_gen_if_name
()
iface
.
name
=
self
.
_gen_if_name
()
netns
.
iproute
.
set_if
(
iface
)
netns
.
iproute
.
set_if
(
iface
)
# Migrate it
netns
.
iproute
.
change_netns
(
iface
,
node
.
pid
)
netns
.
iproute
.
change_netns
(
iface
,
node
.
pid
)
else
:
iface
=
node
.
_slave
.
get_if_data
(
iface
)
self
.
_original_state
=
iface
.
copy
()
super
(
ImportedNodeInterface
,
self
).
__init__
(
node
,
iface
.
index
)
super
(
ImportedNodeInterface
,
self
).
__init__
(
node
,
iface
.
index
)
def
destroy
(
self
):
# override: restore as much as possible
def
destroy
(
self
):
# override: restore as much as possible
if
self
.
_slave
:
if
not
self
.
_slave
:
if
self
.
index
in
self
.
_slave
.
get_if_data
():
return
if
self
.
_migrate
:
if
self
.
index
in
self
.
_slave
.
get_if_data
():
self
.
_slave
.
set_if
(
self
.
_original_state
)
if
self
.
_migrate
:
else
:
self
.
_slave
.
change_netns
(
self
.
index
,
os
.
getpid
())
self
.
_slave
.
change_netns
(
self
.
index
,
os
.
getpid
())
else
:
if
not
self
.
_migrate
:
self
.
_slave
.
set_if
(
self
.
_original_state
)
# else, assume it is in the main name space
if
self
.
_migrate
:
netns
.
iproute
.
set_if
(
self
.
_original_state
)
# else, assume it is already in the main name space
self
.
_slave
=
None
netns
.
iproute
.
set_if
(
self
.
_original_state
)
self
.
_slave
=
None
class
TapNodeInterface
(
NSInterface
):
class
TapNodeInterface
(
NSInterface
):
"""Class to create a tap interface inside a name space, it
"""Class to create a tap interface inside a name space, it
...
...
src/netns/node.py
View file @
62e29870
...
@@ -120,7 +120,7 @@ class Node(object):
...
@@ -120,7 +120,7 @@ class Node(object):
for
i
in
ifaces
:
for
i
in
ifaces
:
if
i
not
in
self
.
_interfaces
:
if
i
not
in
self
.
_interfaces
:
iface
=
netns
.
interface
.
ImportedNodeInterface
(
self
,
i
,
iface
=
netns
.
interface
.
ImportedNodeInterface
(
self
,
i
,
migrate
=
Tru
e
)
migrate
=
Fals
e
)
self
.
_auto_interfaces
.
append
(
iface
)
# keep it referenced!
self
.
_auto_interfaces
.
append
(
iface
)
# keep it referenced!
self
.
_interfaces
[
i
]
=
iface
self
.
_interfaces
[
i
]
=
iface
# by the way, clean up _interfaces
# by the way, clean up _interfaces
...
...
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