changes to replace MacAddress usage and remove ipaddress module altogether

This commit is contained in:
Blake Harnden 2020-01-08 17:33:49 -08:00
parent 4db7f845a5
commit de493c810a
11 changed files with 43 additions and 83 deletions

View file

@ -11,10 +11,13 @@ import json
import logging
import logging.config
import os
import random
import shlex
import sys
from subprocess import PIPE, STDOUT, Popen
import netaddr
from core.errors import CoreCommandError
DEVNULL = open(os.devnull, "wb")
@ -408,3 +411,17 @@ def threadpool(funcs, workers=10):
except Exception as e:
exceptions.append(e)
return results, exceptions
def random_mac():
"""
Create a random mac address using Xen OID 00:16:3E.
:return: random mac address
:rtype: str
"""
value = random.randint(0, 0xFFFFFF)
value |= 0x00163E << 24
mac = netaddr.EUI(value)
mac.dialect = netaddr.mac_unix
return str(mac)