Update and rename MantenerFIFO to MantenerFIFO.md
[vsorcdistro/.git] / mininet / examples / baresshd.py
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
7 from mininet.node import Host
8 from mininet.util import ensureRoot, waitListening
9 from mininet.log import info, warn, output
10
11
12 ensureRoot()
13 timeout = 5
14
15 info( "*** Creating nodes\n" )
16 h1 = Host( 'h1' )
17
18 root = Host( 'root', inNamespace=False )
19
20 info( "*** Creating link\n" )
21 h1.linkTo( root )
22
23 info( h1 )
24
25 info( "*** Configuring nodes\n" )
26 h1.setIP( '10.0.0.1', 8 )
27 root.setIP( '10.0.0.2', 8 )
28
29 info( "*** Creating banner file\n" )
30 f = open( '/tmp/%s.banner' % h1.name, 'w' )
31 f.write( 'Welcome to %s at %s\n' % ( h1.name, h1.IP() ) )
32 f.close()
33
34 info( "*** Running sshd\n" )
35 cmd = '/usr/sbin/sshd -o UseDNS=no -u0 -o "Banner /tmp/%s.banner"' % h1.name
36 # add arguments from the command line
37 if len( sys.argv ) > 1:
38     cmd += ' ' + ' '.join( sys.argv[ 1: ] )
39 h1.cmd( cmd )
40 listening = waitListening( server=h1, port=22, timeout=timeout )
41
42 if listening:
43     output( "*** You may now ssh into", h1.name, "at", h1.IP(), '\n' )
44 else:
45     warn( "*** Warning: after %s seconds, %s is not listening on port 22"
46             % ( timeout, h1.name ), '\n' )