Revision 736db20c mininet/node.py

View differences:

mininet/node.py
75 75
    def __init__( self, name, inNamespace=True, **params ):
76 76
        """name: name of node
77 77
           inNamespace: in network namespace?
78
           privateDirs: list of private directory strings or tuples
78 79
           params: Node parameters (see config() for details)"""
79 80

  
80 81
        # Make sure class actually works
81 82
        self.checkSetup()
82 83

  
83 84
        self.name = params.get( 'name', name )
85
        self.privateDirs = params.get( 'privateDirs', [] )
84 86
        self.inNamespace = params.get( 'inNamespace', inNamespace )
85 87

  
86 88
        # Stash configuration parameters for future reference
......
100 102

  
101 103
        # Start command interpreter shell
102 104
        self.startShell()
105
        self.mountPrivateDirs()
103 106

  
104 107
    # File descriptor to node mapping support
105 108
    # Class variables and methods
......
161 164
        self.cmd( 'stty -echo' )
162 165
        self.cmd( 'set +m' )
163 166

  
167
    def mountPrivateDirs( self ):
168
        "mount private directories"
169
        for directory in self.privateDirs:
170
            if isinstance( directory, tuple ):
171
                # mount given private directory
172
                privateDir = directory[ 1 ] % self.__dict__ 
173
                mountPoint = directory[ 0 ]
174
                self.cmd( 'mkdir -p %s' % privateDir )
175
                self.cmd( 'mkdir -p %s' % mountPoint )
176
                self.cmd( 'mount --bind %s %s' %
177
                               ( privateDir, mountPoint ) )
178
            else:
179
                # mount temporary filesystem on directory
180
                self.cmd( 'mkdir -p %s' % directory ) 
181
                self.cmd( 'mount -n -t tmpfs tmpfs %s' % directory )
182

  
164 183
    def _popen( self, cmd, **params ):
165 184
        """Internal method: spawn and return a process
166 185
            cmd: command to run (list)
......
590 609
        "Make sure our class dependencies are available"
591 610
        pathCheck( 'mnexec', 'ifconfig', moduleName='Mininet')
592 611

  
593

  
594 612
class Host( Node ):
595 613
    "A host is simply a Node"
596 614
    pass
597 615

  
598

  
599 616
class CPULimitedHost( Host ):
600 617

  
601 618
    "CPU limited host"
......
762 779
        mountCgroups()
763 780
        cls.inited = True
764 781

  
765
class HostWithPrivateDirs( Host ):
766
    "Host with private directories"
767

  
768
    def __init__( self, name, *args, **kwargs ):
769
        "privateDirs: list of private directory strings or tuples"
770
        self.name = name
771
        self.privateDirs = kwargs.pop( 'privateDirs', [] )
772
        Host.__init__( self, name, *args, **kwargs )
773
        self.mountPrivateDirs()
774

  
775
    def mountPrivateDirs( self ):
776
        "mount private directories"
777
        for directory in self.privateDirs:
778
            if isinstance( directory, tuple ):
779
                # mount given private directory
780
                privateDir = directory[ 1 ] % self.__dict__ 
781
                mountPoint = directory[ 0 ]
782
                self.cmd( 'mkdir -p %s' % privateDir )
783
                self.cmd( 'mkdir -p %s' % mountPoint )
784
                self.cmd( 'mount --bind %s %s' %
785
                               ( privateDir, mountPoint ) )
786
            else:
787
                # mount temporary filesystem on directory
788
                self.cmd( 'mkdir -p %s' % directory ) 
789
                self.cmd( 'mount -n -t tmpfs tmpfs %s' % directory )
790

  
791

  
792 782

  
793 783
# Some important things to note:
794 784
#

Also available in: Unified diff