Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a method gen_vm_mac() to generate valid mac for QEMU/KVM virtual machines #78

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 22 additions & 0 deletions fauxfactory/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,28 @@ def gen_mac(delimiter=":"):
return _make_unicode(mac)


def gen_vm_mac(delimiter=":"):
"""Generates a random MAC address for QEMU/KVM VM's.

:param str delimeter: Valid MAC delimeter (e.g ':', '-').
:returns: A random MAC address.
:rtype: str

"""

if delimiter not in [":", "-"]:
raise ValueError("Delimiter is not a valid option: %s" % delimiter)

chars = ['a', 'b', 'c', 'd', 'e', 'f',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9']

mac = delimiter.join(
chars[random.randrange(0, len(chars), 1)]+chars[random.randrange(
0, len(chars), 1)] for x in range(3))
vm_mac = '54:52:00:{0}'.format(mac)

return _make_unicode(vm_mac)

def gen_netmask(min_cidr=1, max_cidr=31):
"""Generates a random valid netmask.

Expand Down