mininet / examples / bind.py @ 7c5d2771
History | View | Annotate | Download (2.37 KB)
1 |
#!/usr/bin/python
|
---|---|
2 |
|
3 |
"""
|
4 |
bind.py: Bind mount example
|
5 |
|
6 |
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 |
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 |
"""
|
36 |
|
37 |
from mininet.net import Mininet |
38 |
from mininet.node import Host, HostWithPrivateDirs |
39 |
from mininet.cli import CLI |
40 |
from mininet.topo import SingleSwitchTopo |
41 |
from mininet.log import setLogLevel, info, debug |
42 |
|
43 |
from functools import partial |
44 |
|
45 |
|
46 |
# Sample usage
|
47 |
|
48 |
def testHostWithPrivateDirs(): |
49 |
"Test bind mounts"
|
50 |
topo = SingleSwitchTopo( 10 )
|
51 |
privateDirs = [ ( '/var/log', '/tmp/%(name)s/var/log' ), |
52 |
( '/var/run', '/tmp/%(name)s/var/run' ), |
53 |
'/var/mn' ]
|
54 |
host = partial( HostWithPrivateDirs, |
55 |
privateDirs=privateDirs ) |
56 |
net = Mininet( topo=topo, host=host ) |
57 |
net.start() |
58 |
directories = [] |
59 |
for directory in privateDirs: |
60 |
directories.append( directory[ 0 ]
|
61 |
if isinstance( directory, tuple ) |
62 |
else directory )
|
63 |
info( 'Private Directories:', directories, '\n' ) |
64 |
CLI( net ) |
65 |
net.stop() |
66 |
|
67 |
if __name__ == '__main__': |
68 |
setLogLevel( 'info' )
|
69 |
testHostWithPrivateDirs() |
70 |
info( 'Done.\n')
|
71 |
|
72 |
|