246
246
random.choice(alphanumeric_chars) for _ in range(length)]
247
247
return(''.join(random_chars))
250
def list_nics(nic_type):
251
'''Return a list of nics of given type(s)'''
252
if isinstance(nic_type, basestring):
253
int_types = [nic_type]
257
for int_type in int_types:
258
cmd = ['ip', 'addr', 'show', 'label', int_type + '*']
259
ip_output = subprocess.check_output(cmd).split('\n')
260
ip_output = (line for line in ip_output if line)
261
for line in ip_output:
262
if line.split()[1].startswith(int_type):
263
interfaces.append(line.split()[1].replace(":", ""))
267
def set_nic_mtu(nic, mtu):
268
'''Set MTU on a network interface'''
269
cmd = ['ip', 'link', 'set', nic, 'mtu', mtu]
270
subprocess.check_call(cmd)
273
def get_nic_mtu(nic):
274
cmd = ['ip', 'addr', 'show', nic]
275
ip_output = subprocess.check_output(cmd).split('\n')
277
for line in ip_output:
280
mtu = words[words.index("mtu") + 1]
284
def get_nic_hwaddr(nic):
285
cmd = ['ip', '-o', '-0', 'addr', 'show', nic]
286
ip_output = subprocess.check_output(cmd)
288
words = ip_output.split()
289
if 'link/ether' in words:
290
hwaddr = words[words.index('link/ether') + 1]