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
83a42262
Commit
83a42262
authored
Jun 10, 2010
by
Martín Ferrari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SlaveNode class
parent
04392c11
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
1 deletion
+40
-1
src/netns/__init__.py
src/netns/__init__.py
+40
-1
No files found.
src/netns/__init__.py
View file @
83a42262
...
...
@@ -3,6 +3,13 @@
import
os
try
:
from
yaml
import
CLoader
as
Loader
from
yaml
import
CDumper
as
Dumper
except
ImportError
:
from
yaml
import
Loader
,
Dumper
#yaml.load(stream, Loader = Loader)
class
__Config
(
object
):
def
__init__
(
self
):
self
.
run_as
=
None
...
...
@@ -16,7 +23,8 @@ def set_cleanup_hooks(on_exit = False, on_signals = []):
class
Node
(
object
):
def
__init__
(
self
):
self
.
pid
=
0
self
.
slave
=
SlaveNode
()
self
.
valid
=
True
def
add_if
(
self
,
mac_address
=
None
,
mtu
=
None
):
return
Interface
(
mac_address
,
mtu
)
def
add_route
(
self
,
prefix
,
prefix_len
,
nexthop
=
None
,
interface
=
None
):
...
...
@@ -39,6 +47,7 @@ class Interface(object):
self
.
name
=
None
self
.
mac_address
=
mac_address
self
.
mtu
=
mtu
self
.
valid
=
True
def
add_v4_address
(
self
,
address
,
prefix_len
,
broadcast
=
None
):
pass
def
add_v6_address
(
self
,
address
,
prefix_len
):
...
...
@@ -47,3 +56,33 @@ class Interface(object):
class
Process
(
object
):
def
__init__
(
self
):
self
.
pid
=
os
.
getpid
()
self
.
valid
=
True
import
os
,
socket
,
sys
class
SlaveNode
(
object
):
def
__init__
(
self
):
(
s0
,
s1
)
=
socket
.
socketpair
(
socket
.
AF_UNIX
,
socket
.
SOCK_STREAM
,
0
)
ppid
=
os
.
getpid
()
pid
=
os
.
fork
()
if
pid
:
self
.
pid
=
pid
self
.
sock
=
s0
s1
.
close
()
return
s0
.
close
()
self
.
sock
=
s1
.
makefile
(
"r+"
)
self
.
ppid
=
ppid
try
:
self
.
run
()
except
BaseException
,
e
:
sys
.
stderr
.
write
(
"Error in slave node: %s
\
n
"
%
str
(
e
))
os
.
_exit
(
1
)
os
.
_exit
(
0
)
def
run
(
self
):
self
.
sock
.
write
(
"220 Hello.
\
n
"
);
while
True
:
line
=
self
.
sock
.
readline
()
if
not
line
:
break
self
.
sock
.
write
(
"ECHO: %s
\
n
"
%
line
.
rstrip
())
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