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
6af18e45
Commit
6af18e45
authored
Jul 12, 2010
by
Martín Ferrari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
High level interface to subprocess
parent
75cb3572
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
12 deletions
+21
-12
sample-api.py
sample-api.py
+6
-11
src/netns/node.py
src/netns/node.py
+15
-1
No files found.
sample-api.py
View file @
6af18e45
...
...
@@ -78,19 +78,14 @@ stats = link0.get_stats()
# IDEA: implement Node.popen and build the others upon it.
# IDEA: use SCM_RIGHTS to pass filedescriptors instead of using pipes/sockets
# Run a process in background, associate its stdio to three named pipes
app0
=
a
.
start_process
(
"ping -c 3 10.0.0.2"
)
print
"ping command PIPES at (%s, %s, %s)"
%
app0
.
pipes
app0
.
kill
(
15
)
# The same, but directly as python file objects
app1
=
a
.
start_process
([
"ping"
,
"-c"
,
"3"
,
"10.0.0.2"
])
buf
=
app1
.
stdout
.
read
()
app1
.
wait
()
# Run a process in background
import
subprocess
app0
=
a
.
Popen
(
"ping -c 3 10.0.0.2"
,
shell
=
True
,
stdout
=
subprocess
.
PIPE
)
print
app0
.
stdout
.
readline
()
app0
.
wait
()
# Run, capture output and wait()
(
stdout
,
stderr
)
=
a
.
run_process
([
"ping"
,
"-c"
,
"3"
,
"10.0.0.2"
])
# stdout, stderr are strings
stdout
=
a
.
backticks
([
"ping"
,
"-c"
,
"3"
,
"10.0.0.2"
])
# Run an process with a pseudo-tty associated to it; provide a UNIX socket to
# interact with the process
...
...
src/netns/node.py
View file @
6af18e45
...
...
@@ -2,7 +2,7 @@
# vim:ts=4:sw=4:et:ai:sts=4
import
os
,
socket
,
sys
,
traceback
,
unshare
,
weakref
import
netns.protocol
import
netns.protocol
,
netns
.
subprocess_
class
Node
(
object
):
_nodes
=
weakref
.
WeakValueDictionary
()
...
...
@@ -37,11 +37,25 @@ class Node(object):
self
.
_slave
.
shutdown
()
del
self
.
_slave
# Subprocesses
def
_add_subprocess
(
self
,
subprocess
):
self
.
_processes
[
subprocess
.
pid
]
=
subprocess
def
Subprocess
(
self
,
*
kargs
,
**
kwargs
):
return
netns
.
subprocess_
.
Subprocess
(
self
,
*
kargs
,
**
kwargs
)
def
Popen
(
self
,
*
kargs
,
**
kwargs
):
return
netns
.
subprocess_
.
Popen
(
self
,
*
kargs
,
**
kwargs
)
def
system
(
self
,
*
kargs
,
**
kwargs
):
return
netns
.
subprocess_
.
system
(
self
,
*
kargs
,
**
kwargs
)
def
backticks
(
self
,
*
kargs
,
**
kwargs
):
return
netns
.
subprocess_
.
backticks
(
self
,
*
kargs
,
**
kwargs
)
def
backticks_raise
(
self
,
*
kargs
,
**
kwargs
):
return
netns
.
subprocess_
.
backticks_raise
(
self
,
*
kargs
,
**
kwargs
)
@
property
def
pid
(
self
):
return
self
.
_pid
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
):
...
...
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