Statistics
| Branch: | Tag: | Revision:

mininet / examples / bind.py @ e0bf8ece

History | View | Annotate | Download (2.26 KB)

1 5ae8c936 Bob Lantz
#!/usr/bin/python
2
3
"""
4 af2f67d9 Cody Burkard
bind.py: Bind mount example
5 5ae8c936 Bob Lantz

6 af2f67d9 Cody Burkard
This creates hosts with private directories that the user specifies.
7
These hosts may have persistent directories that will be available
8
across multiple mininet session, or temporary directories that will
9
only last for one mininet session. To specify a persistent
10
directory, add a tuple to a list of private directories:
11

12
    [ ( 'directory to be mounted on', 'directory to be mounted' ) ]
13

14
String expansion may be used to create a directory template for
15
each host. To do this, add a %(name)s in place of the host name
16
when creating your list of directories:
17

18
    [ ( '/var/run', '/tmp/%(name)s/var/run' ) ]
19

20
If no persistent directory is specified, the directories will default
21
to temporary private directories. To do this, simply create a list of
22
directories to be made private. A tmpfs will then be mounted on them.
23

24
You may use both temporary and persistent directories at the same
25
time. In the following privateDirs string, each host will have a 
26
persistent directory in the root filesystem at
27
"/tmp/(hostname)/var/run" mounted on "/var/run". Each host will also
28
have a temporary private directory mounted on "/var/log".
29

30
    [ ( '/var/run', '/tmp/%(name)s/var/run' ), '/var/log' ]
31

32 40a4a25d Cody Burkard
This example has both persistent directories mounted on '/var/log'
33
and '/var/run'. It also has a temporary private directory mounted
34
on '/var/mn'
35 5ae8c936 Bob Lantz
"""
36
37
from mininet.net import Mininet
38 736db20c cody burkard
from mininet.node import Host
39 5ae8c936 Bob Lantz
from mininet.cli import CLI
40
from mininet.topo import SingleSwitchTopo
41 e0bf8ece Bob Lantz
from mininet.log import setLogLevel, info
42 5ae8c936 Bob Lantz
43
from functools import partial
44
45 f3442903 Bob Lantz
46 40a4a25d Cody Burkard
# Sample usage
47 5ae8c936 Bob Lantz
48 40a4a25d Cody Burkard
def testHostWithPrivateDirs():
49 5ae8c936 Bob Lantz
    "Test bind mounts"
50 f3442903 Bob Lantz
    topo = SingleSwitchTopo( 10 )
51 af2f67d9 Cody Burkard
    privateDirs = [ ( '/var/log', '/tmp/%(name)s/var/log' ), 
52 40a4a25d Cody Burkard
                    ( '/var/run', '/tmp/%(name)s/var/run' ), 
53
                      '/var/mn' ]
54 736db20c cody burkard
    host = partial( Host,
55 91092338 Cody Burkard
                    privateDirs=privateDirs )
56 5ae8c936 Bob Lantz
    net = Mininet( topo=topo, host=host )
57
    net.start()
58 736db20c cody burkard
    directories = [ directory[ 0 ] if isinstance( directory, tuple )
59
                    else directory for directory in privateDirs ]
60 40a4a25d Cody Burkard
    info( 'Private Directories:',  directories, '\n' )
61 af2f67d9 Cody Burkard
    CLI( net )
62
    net.stop()
63 5ae8c936 Bob Lantz
64
if __name__ == '__main__':
65
    setLogLevel( 'info' )
66 40a4a25d Cody Burkard
    testHostWithPrivateDirs()
67
    info( 'Done.\n')
68 5ae8c936 Bob Lantz