Revision 723d068c mininet/util.py

View differences:

mininet/util.py
99 99
# live in the root namespace and thus do not have to be
100 100
# explicitly moved.
101 101

  
102

  
102 103
def makeIntfPair(intf1, intf2):
103 104
    '''Make a veth pair.
104 105

  
......
111 112
    quietRun('ip link del ' + intf2)
112 113
    # Create new pair
113 114
    cmd = 'ip link add name ' + intf1 + ' type veth peer name ' + intf2
114
    return checkRun( cmd )
115
    return checkRun(cmd)
115 116

  
116 117

  
117 118
def moveIntf(intf, node, print_error = False):
......
132 133
    return True
133 134

  
134 135

  
135
def retry(n, retry_delay, fn, *args):
136
def retry(n, retry_delay, fn, *args, **keywords):
136 137
    '''Try something N times before giving up.
137 138

  
138 139
    @param n number of times to retry
......
141 142
    @param args args to apply to function call
142 143
    '''
143 144
    tries = 0
144
    while not apply(fn, args) and tries < n:
145
    while not fn(*args, **keywords) and tries < n:
145 146
        sleep(retry_delay)
146 147
        tries += 1
147 148
    if tries >= n:
148 149
        lg.error("*** gave up after %i retries\n" % tries)
149
        exit( 1 )
150
        exit(1)
150 151

  
151 152

  
152 153
# delay between interface move checks in seconds
......
154 155

  
155 156
CREATE_LINK_RETRIES = 10
156 157

  
158

  
157 159
def createLink(node1, node2):
158 160
    '''Create a link between nodes, making an interface for each.
159 161

  
......
174 176

  
175 177
def fixLimits():
176 178
    '''Fix ridiculously small resource limits.'''
177
    setrlimit( RLIMIT_NPROC, (4096, 8192))
178
    setrlimit( RLIMIT_NOFILE, (16384, 32768))
179
    setrlimit(RLIMIT_NPROC, (4096, 8192))
180
    setrlimit(RLIMIT_NOFILE, (16384, 32768))
179 181

  
180 182

  
181 183
def _colonHex(val, bytes):
......
186 188
    @return ch_str colon-hex string
187 189
    '''
188 190
    pieces = []
189
    for i in range (bytes - 1, -1, -1):
191
    for i in range(bytes - 1, -1, -1):
190 192
        pieces.append('%02x' % (((0xff << (i * 8)) & val) >> (i * 8)))
191 193
    ch_str = ':'.join(pieces)
192 194
    return ch_str
......
209 211
    hi = (ip & 0xff0000) >> 16
210 212
    mid = (ip & 0xff00) >> 8
211 213
    lo = ip & 0xff
212
    return "10.%i.%i.%i" % (hi, mid, lo)
214
    return "10.%i.%i.%i" % (hi, mid, lo)

Also available in: Unified diff