Statistics
| Branch: | Tag: | Revision:

mininet / examples / baresshd.py @ 7c5d2771

History | View | Annotate | Download (1.05 KB)

1
#!/usr/bin/python
2

    
3
"This example doesn't use OpenFlow, but attempts to run sshd in a namespace."
4

    
5
import sys
6
from mininet.node import Host
7
from mininet.util import ensureRoot, waitListening
8

    
9
ensureRoot()
10
timeout = 5
11

    
12
print "*** Creating nodes"
13
h1 = Host( 'h1' )
14

    
15
root = Host( 'root', inNamespace=False )
16

    
17
print "*** Creating links"
18
h1.linkTo( root )
19

    
20
print h1
21

    
22
print "*** Configuring nodes"
23
h1.setIP( '10.0.0.1', 8 )
24
root.setIP( '10.0.0.2', 8 )
25

    
26
print "*** Creating banner file"
27
f = open( '/tmp/%s.banner' % h1.name, 'w' )
28
f.write( 'Welcome to %s at %s\n' % ( h1.name, h1.IP() ) )
29
f.close()
30

    
31
print "*** Running sshd"
32
cmd = '/usr/sbin/sshd -o UseDNS=no -u0 -o "Banner /tmp/%s.banner"' % h1.name
33
# add arguments from the command line
34
if len( sys.argv ) > 1:
35
    cmd += ' ' + ' '.join( sys.argv[ 1: ] )
36
h1.cmd( cmd )
37
listening = waitListening( server=h1, port=22, timeout=timeout )
38

    
39
if listening:
40
    print "*** You may now ssh into", h1.name, "at", h1.IP()
41
else:
42
    print ( "*** Warning: after %s seconds, %s is not listening on port 22"
43
            % ( timeout, h1.name ) )