minimega.create_mac_addresses

This MC ensures that each VM has a unique MAC address. It works by keeping a global counter and incrementing it. For simplicity, this MC uses netaddr’s EUI library.

Users can optionally pass in an integer to the plugin to seed the starting MAC address.

Attribute Provides:
  • mac_addresses

Attribute Depends:
  • topology

Plugin

class minimega.create_mac_addresses_plugin.CreateMACAddrs(*args, **kwargs)[source]

Bases: AbstractPlugin

This plugin ensures that each VM has a unique MAC address by keeping a global counter and incrementing it. For simplicity, this plugin uses netaddr.EUI. More information can be found in the netaddr documentation.

__annotations__ = {}
__init__(*args, **kwargs)[source]

Initialize the global MAC counter and the set of existing MAC addresses.

Parameters:
  • *args – Arguments are not used for this object.

  • **kwargs – Keyword arguments are not used for this object.

_assign_macs()[source]

Iterate over the graph and add a MAC address for each interface that does not have one yet.

_convert_int_to_mac(numeric)[source]

Converts an integer to a MAC string in the format: "xx:xx:xx:xx:xx:xx".

Parameters:

numeric (int) – The integer to have converted to the MAC representation.

Returns:

MAC address string in the format: "xx:xx:xx:xx:xx:xx".

Return type:

str

_find_existing_macs()[source]

Iterate over the graph and add any existing MAC addresses to the global set.

_increment_mac()[source]

Increments the current MAC address by one and does wrap around checking.

get_unique_mac()[source]

Make sure that the current MAC hasn’t been assigned outside of this plugin. If it has, increment the MAC and check again.

Returns:

A MAC address that (at this point in the graph walk) is unique.

Return type:

str

run(mac_addr_start='')[source]

See the starting MAC address and call subsequent functions which ensure that all VM interfaces have a unique MAC address.

Parameters:

mac_addr_start (str, optional) – A seed value for the initial MAC address. Must be convertible to int. Defaults to "".

Raises:

ValueError – If the passed in value is not valid.