Add new disk on a VMWare VM using Foreman API

I successfully created a host on my vCenter with the Foreman API. Now i want to add a new disk through the Foreman API using this command :
curl -k -s -X PUT -H "Content-Type: application/json" -H "Accept: version=2,application/json" -d @file.json https://XXX.XXX.XXX.XXX/api/v2/hosts/873 -u user:password

The file “file.json” contain this :
{ "compute_attributes": { "volumes_attributes": {"1": { "thin": true, "name": "Hard disk 2", "mode": "persistent", "controller_key": 1000, "datastore": "My_datastore", "unit_number": 1, "size_gb": 50 } } } }
The curl commande works, but in the end, it does not add a new disk, and it change the VLAN of the two network card of my host to some (apparently ?) random other VLAN.
Can someone help me one this ? Is it even possible to create a new disk on a vmware host throught Foreman API ?

Expected outcome:
A new disk is added to my vmware host, 50 GB

Has it really changed the VLAN or only showing the wrong in Foreman? Because I was in the impression that changing the VLAN does not work at the moment: Feature #18304: Support updating network interfaces for VMWare - Foreman

But the disk should work, so at least from the UI it worked last time I used it and so API should also be fine.

But @ezr-ondrej can hopefully help here.

1 Like

Yes it really changed the VLAN of my VM in the vCenter. I’ve tried it on two different vSphere with two differents installation of Foreman, same problem : VLAN are changed (???) but nothing happen to the disk, even when i tried just extending the already existing disk as shown here (How to resize vmware-volume when creating host via api?) which seems to be an easier things to do, but do not work for me. I forgot to mention earlier, both Foreman are running the 1.16.2 version

I should have tried from the UI first, i can’t add a volume on an already existing host. The buttons are greyed :frowning:

1.16.2 is very old, not to say ancient. So I would recommend an upgrade and retry it afterwards. The VMware integration was one of the parts that greatly evolved over time.

Ok thank you, i’m not responsible of the Foreman in my company, i will suggested an update to the person maintaining it.

It is not possible to edit disk setup of vmware machine through foreman. I’ve currently open PR for allowing the vmware network edit, so it’s quite suspicious your network changed. But it’s possible, as 1.16 is very ancient and unless necessary, I’d like not to install it just to see how it behaves.

I’m not very aware of people wanting to do so, but if you’d like to see the change I’d be happy to hear your usecase. It’s not allowed because it’s not very error prone and not easy to do right. So I guess there was not enough push to have it so far :slight_smile:

We were actually planning to have this feature for our developers to self service, when for example needing a new or bigger disk for their VMs. This would allow self service instead of having to bug a vmware admin for such stuff. Same for networking.