Revision 736db20c examples/miniedit.py

View differences:

examples/miniedit.py
43 43
from mininet.util import custom, customConstructor
44 44
from mininet.term import makeTerm, cleanUpScreens
45 45
from mininet.node import Controller, RemoteController, NOX, OVSController
46
from mininet.node import CPULimitedHost, Host, Node, HostWithPrivateDirs
46
from mininet.node import CPULimitedHost, Host, Node
47 47
from mininet.node import OVSKernelSwitch, OVSSwitch, UserSwitch
48 48
from mininet.link import TCLink, Intf, Link
49 49
from mininet.cli import CLI
......
78 78
          'cfs': custom( CPULimitedHost, sched='cfs' ) }
79 79

  
80 80

  
81
class CPULimitedHostWithPrivateDirs( CPULimitedHost ):
82
    "Host with private directories"
83

  
84
    def __init__( self, name, sched='cfs', **kwargs ):
85
        "privateDirs: list of private directory strings or tuples"
86
        self.name = name
87
        self.privateDirs = kwargs.pop( 'privateDirs', [] )
88
        CPULimitedHost.__init__( self, name, sched, **kwargs )
89
        self.mountPrivateDirs()
90

  
91
    def mountPrivateDirs( self ):
92
        "mount private directories"
93
        for directory in self.privateDirs:
94
            if isinstance( directory, tuple ):
95
                # mount given private directory
96
                privateDir = directory[ 1 ] % self.__dict__
97
                mountPoint = directory[ 0 ]
98
                self.cmd( 'mkdir -p %s' % privateDir )
99
                self.cmd( 'mkdir -p %s' % mountPoint )
100
                self.cmd( 'mount --bind %s %s' %
101
                               ( privateDir, mountPoint ) )
102
            else:
103
                # mount temporary filesystem on directory
104
                self.cmd( 'mkdir -p %s' % directory )
105
                self.cmd( 'mount -n -t tmpfs tmpfs %s' % directory )
106

  
107 81
class InbandController( RemoteController ):
108 82

  
109 83
    def checkListening( self ):
......
2784 2758
                # Create the correct host class
2785 2759
                if 'cores' in opts or 'cpu' in opts:
2786 2760
                    if ('privateDirectory' in opts):
2787
                        hostCls = partial( CPULimitedHostWithPrivateDirs,
2761
                        hostCls = partial( CPULimitedHost,
2788 2762
                                           privateDirs=opts['privateDirectory'] )
2789 2763
                    else:
2790 2764
                        hostCls=CPULimitedHost
2791 2765
                else:
2792 2766
                    if ('privateDirectory' in opts):
2793
                        hostCls = partial( HostWithPrivateDirs,
2767
                        hostCls = partial( Host,
2794 2768
                                           privateDirs=opts['privateDirectory'] )
2795 2769
                    else:
2796 2770
                        hostCls=Host
2771
                print hostCls
2797 2772
                newHost = net.addHost( name,
2798 2773
                                       cls=hostCls,
2799 2774
                                       ip=ip,

Also available in: Unified diff