foreman_fog_proxmox icon indicating copy to clipboard operation
foreman_fog_proxmox copied to clipboard

Mac Address Change when Edit Host

Open danielgohlke opened this issue 2 years ago • 10 comments

Describe the bug If values such as CPU, memory or similar are changed in a VM via the WebUI of foreman (Edit VM), a new NIC Mac address is generated each time. This Mac address is not known to foreman and its DHCP, so the VM in question gets a new IP from the DHCP and the name resolution no longer works.

Foreman Version Foreman 2.5.4

Proxmox Version 7.0-8

To Reproduce Steps to reproduce the behavior:

  1. Go to Foreman -> Hosts -> All Hosts
  2. Click on a Host
  3. Click on Edit
  4. Click on Virtual Machine Tab
  5. Check the CPU Box for example
  6. Edit CPU Core count value
  7. Scroll down to Submit
  8. Click on Submit

Expected behavior The MAC Address should not be changed

Screenshots pve2 - Proxmox Virtual Environment 2021-10-26 12-37-30

Desktop (please complete the following information):

  • OS: MacOS
  • Browser chrome
  • Version 95.0.4638.54

danielgohlke avatar Oct 26 '21 10:10 danielgohlke

Hello @tristanrobert,

Have you had a chance to look at the issue?

danielgohlke avatar Nov 09 '21 11:11 danielgohlke

I experienced the same bug while building a lab setup. I have near to zero ruby programming skills but feel free to reach out to me, if I can support you in solving this bug.

bk-lg avatar Nov 17 '21 13:11 bk-lg

@tristanrobert is thera any update on this issue or a way to help you with this?

bk-lg avatar Feb 02 '22 18:02 bk-lg

would also like to help you if you tell me where I can start to look (file)

danielgohlke avatar Feb 04 '22 09:02 danielgohlke

Not to bring up old issues, but I also ran into this recently, and I did some digging. This seems to be a behavior of the Proxmox API whenever an edit to networking is done without supplying the MAC address.

This issue on their forum from 2020 shows it happens even from the CLI: https://forum.proxmox.com/threads/proxmox-api-change-vm-network-configuration.68764/

As does this from 2015: https://forum.proxmox.com/threads/api-changes-mac-address-unessescarily.21625/

I believe the previous behavior was for the plugin to return the MAC address back to the API on update calls, to avoid having Proxmox regenerate new MAC addresses like this, but that seems to have broken (likely due to other changes related to things like #223). The "fix" should be to ensure the MAC (upper or lower case, from my CLI tests) is always given back to the API when any other edit of the VM is done (as this happens even when editing number of CPU cores as the original issue shows).

mleo2003 avatar May 17 '22 17:05 mleo2003

@mleo2003 thank you for researching this behaviour. I hope there will now a way to fix this.

bk-lg avatar May 18 '22 13:05 bk-lg

This definitely seems to be an issue with Proxmox's API, but surprisingly it doesn't happen when using pvesh.

I tested on both 6.2-4 and 7.1-7 (seen in example below)

From api:

root@foreman:~# curl -s -k -H "$PROXMOX_HEADER" -X GET $PMX/api2/json/nodes/$NODE/qemu/100/config|jq .data.net0
"virtio=62:75:64:B5:E5:0F"
root@foreman:~# curl -s -k -H "$PROXMOX_HEADER" -X POST $PMX/api2/json/nodes/$NODE/qemu/100/config -d 'net0=virtio=52:54:00:de:bc:20' 
{"data":"UPID:$PMX:002FE784:05A46643:62858671:qmconfig:100:root@pam!foreman-test:"}
root@foreman:~# curl -s -k -H "$PROXMOX_HEADER" -X GET $PMX/api2/json/nodes/$NODE/qemu/100/config|jq .data.net0
"virtio=DA:72:1D:D6:8A:65"
root@foreman:~# curl -s -k -H "$PROXMOX_HEADER" -X POST $PMX/api2/json/nodes/$NODE/qemu/100/config -d 'net0=virtio=52:54:00:de:bc:20' 
{"data":"UPID:$PMX:002FE7DE:05A46AF9:6285867D:qmconfig:100:root@pam!foreman-test:"}
root@foreman:~# curl -s -k -H "$PROXMOX_HEADER" -X GET $PMX/api2/json/nodes/$NODE/qemu/100/config|jq .data.net0
"virtio=FE:A7:79:11:E5:01"

Using pvesh:

root@proxmox:~# pvesh get /nodes/$PMX/qemu/100/config --output-format=json|jq .net0
"virtio=FE:A7:79:11:E5:01"
root@proxmox:~# pvesh set /nodes/$PMX/qemu/100/config -net0 virtio=52:54:00:de:bc:20
update VM 100: -net0 virtio=52:54:00:de:bc:20
root@proxmox:~# pvesh get /nodes/$PMX/qemu/100/config --output-format=json|jq .net0
"virtio=52:54:00:de:bc:20"

According to the Proxmox API docs pvesh set is the equivalent of PUT, while pvesh create is a POST. I attempted the curl command above with a PUT, but unfortunately no dice.

I think we're at the mercy of proxmox on this one, I'm personally looking into some sort of remote execution to reactively change the mac back using pvesh, at least for now.

As long as hotswapping the nic is disabled, having it changed back shortly after editing the host shouldn't cause an issue. With hotswapping enabled the MAC changes go through while the system is running, which isn't ideal in a prod environment, ha.

gerg91 avatar May 19 '22 00:05 gerg91

I think this is no real solution. Many networks requires specific mac adresses. Wouldn't if better to read the mac before each request and set it explicitly with every call to the api or do I understand this wrong?

bk-lg avatar May 19 '22 07:05 bk-lg

I was just showing when you make command line calls to the Proxmox API it still behaves the same. Meaning this is a bug with Proxmox's API.

In the top example I made two calls to the api asking for a specific MAC, it ignored the requested MAC changed to another random one each time.

gerg91 avatar May 19 '22 12:05 gerg91

Just to follow up again, I now see this behavior on any change to the managed host, including just adding or removing classes, etc. I even tried to not manage the network card details, and it still does this.

At this point, I may have to unmanage hosts to keep this from constantly making changes.

mleo2003 avatar May 27 '22 22:05 mleo2003