Open jfpanisset opened 4 years ago
@jfpanisset Thanks for the suggestion. I don't have a Proxmox environment available right now where I could test this, but I would be surprised if the Proxmox API (which we use) does not actually take datacenter.cfg into account if their UI does. Have you verified that not setting mac_address
on the Packer builder does not respect the configured prefix?
I am currently not using mac_address
in my Packer JSON file, and can confirm that VMs created from Packer don't have the MAC prefix set in datacenter.cfg. The documentation for "mac_address" says "If not set, defaults to a random MAC", and although I don't understand Go very much, it seems that the code in function CreateQemuNetworksParams() in:
packer/vendor/github.com/Telmate/proxmox-api-go/proxmox/config_qemu.go
will "Generate Mac based on VmID and NicID so it will be the same always." if you don't specify the "macaddr" parameter rather than letting the Proxmox API do it (and thus take datacenter.cfg into consideration). Of course I could be looking in the wrong place.
@jfpanisset Thanks for verifying, and good find! Indeed, it seems the library we use is doing things before passing it on to the API, which I hadn't noticed. That logic looks a bit odd, I'll need to look at it with fresh eyes and see if it makes sense then. (Since I hadn't used that particular feature of Proxmox before, the docs I wrote for the Packer proxmox builder could very well have been wrong, was the idea behind the last comment)
It would be nice if we didn't have to reimplement random mac addresses on top of what Proxmox does itself, though. Avoiding collisions between VMs, etc. I'll try to find time to do some testing on how to get around the logic in the library, or change it.
On Proxmox it is possible to set a MAC address prefix in /etc/pve/datacenter.cfg
mac_prefix: aa:bb:01
VM and VM templates created from the cluster UI or the "qm" tool will have network interfaces with this prefix. This is documented here:
https://pve.proxmox.com/wiki/Manual:_datacenter.cfg
When using the Packer Proxmox builder, the "mac_address" option in the "network_adapters" section is documented as:
https://www.packer.io/docs/builders/proxmox.html
mac_address (string) - Give the adapter a specific MAC address. If not set, defaults to a random MAC.
It would be useful if there was also a "mac_address_prefix" option which would allow the Proxmox builder to specify a MAC address prefix and only randomly generate the suffix part of the MAC address, and optional take "cluster" as a value which would let the cluster auto-generate the MAC address based on the value set in /etc/pve/datacenter.cfg