Rest API v3 updating vm settings

  • 30 September 2017
  • 7 replies

Badge +3
I am trying to update VM settings according to this acrticle I put this code for updating vm:
{ "api_version": "3.0", "metadata": { "kind": "vm", "spec_version": 0, "categories": {} }, "spec": { "cluster_reference": { "kind": "cluster", "uuid": "0005558c-536f-7adc-2348-001fc69c242b" }, "name": "ansible-client110", "resources": { "disk_list": [ { "device_properties": { "disk_address": { "device_index": 0, "adapter_type": "SCSI" }, "device_type": "DISK" }, "disk_size_mib": 50984 } ] } }}i got error :
"message": "The VM guest customization configuration cannot be changed after VM creation.", "reason": "INVALID_REQUEST" The issue is connected with cloud-config, if i get information from restapi about vm i see information that clodu-config is still exist:
"cloud_init": { "user_data": "I2Nsb3VkLWNvbmZpZwoKaG9zdG5hbWU6IGFuc2libGUtY2xpZW50MTAKZnFkbjogYW5zaWJsZS1jbGllbnQxMC5sb2NhbApjaHBhc3N3ZDoKICBsaXN0OiB8CiAgICByb290OjFxYXpAV1NYCiAgZXhwaXJlOiBGYWxzZQoKcnVuY21kOgogIC0gc2VkIC1pIC1lICdzL09OQk9PVD1uby9PTkJPT1Q9eWVzL2cnIC9ldGMvc3lzY29uZmlnL25ldHdvcmstc2NyaXB0cy9pZmNmZy1ldGgwCiAgLSBzZXJ2aWNlIG5ldHdvcmsgcmVzdGFydAogIC0gc2VkIC1pIC1lICdzL1Bhc3N3b3JkQXV0aGVudGljYXRpb24gbm8vUGFzc3dvcmRBdXRoZW50aWNhdGlvbiB5ZXMvZycgL2V0Yy9zc2gvc3NoZF9jb25maWcKICAtIHNlcnZpY2Ugc3NoZCByZXN0YXJ0CiAgLSB1bmxpbmsgL2V0Yy9sb2NhbHRpbWUKICAtIGxuIC1zIC91c3Ivc2hhcmUvem9uZWluZm8vRXVyb3BlL01vc2NvdyAvZXRjL2xvY2FsdGltZQ==" } },But vm has been already customized. How to update VM settings via RestApi v3 after creation?

7 replies

Badge +5
Hi navi86

What is the spec returned by GET for that VM? Does it include cloud_init config in a guest_customization section?

My expectation is that it does, and for your PUT you should continue to include that configuration (and everything else in the spec) in your PUT. v3 APIs follow a declarative approach, where the spec describes the (complete) VM in the state you'd like it to be. An attribute that was previously present but removed from your spec is interpreted as a user's intent to change that attribute by removing it.

For guest customization, we only support performing that operation once. This is a limitation of our implementation, as it may be possible in future releases to allow a user to provide a different cloud_init config such as to customize the guest a second time. For now, we validate that any guest customization attributes, once acted upon in a VM's spec, remain unchanged forever. Removal from a spec is equivalent to change in a declarative model. Just like removing disks from the disk_list of a VM specifies intent to delete a disk, removing cloud_init specifies intent to undo cloud_init, which is an operation that cannot be performed.
Badge +3
thank you for explanation,
Do you have a full description of Rest API v3 ? Because I couldn't find that information here:
I think there might be other unpredictable things for me.
Badge +5
navi86 You're looking at the right place for documentation, but the level of detail isn't suffient for you to have gleaned this. While the top-level description of intentful covers what I said regarding the declarative approach in v3, I admit that guest_customization is special-enough to warrant some extra attention in the docs.

tarak let's include this level of detail in the documentation for the guest_customization attributes.
Badge +3
It doesn't work.
Cloud-init create a CDROM where configuration files are located but get vm by uuid method doesn't return CDROM in spec settings(CDROM located in status settings) therefore it means removing CDROM with cloud-init configs and corrupt VM after upgrading settings.
If I copy CDROM settings from status to spec settings and update VM it corrupts VM too because cloud init can't access to configration files.
If I don't use cloud-init configs i can update VM without issue.
How to update VM when VM was created with cloud-init ?
I am using following code in python for updating VM settings:
result['spec']['resources']['disk_list'][0]['disk_size_mib'] = 55000result.pop('status', None)after that I use result as a body for update VM.
Badge +5
The first issue you described, where the spec is missing the CDROM device added automatically for cloud-init, is being fixed as we prepare the v3 APIs for GA.

You are attempting the workaround the right way, though you should try copying the entire disk definition from disk_list in the status to the spec before popping status from the response. On current builds of 5.5 I verified that doing so preserves the CDROM added for cloud-init, but I'm not sure if 5.1 had different behavior.
Badge +3
Actually i tried to copy all disk_list definition
result['spec']['resources']['disk_list'] = result['status']['resources']['disk_list']but it didn't help, cloud-init could't get access to the config files.
Userlevel 2
Badge +6
Hi @navi86 ! :)

Quick question - are you still experiencing errors with this? I ask as AOS 5.6 was released for download today. The v3 APIs are updated to GA status as part of that release.

If you still have questions about this, could you please advise? I'm going through some of the old responses and replying where I can. I'll just mention that @ckousoulis is pretty much the man when it comes to this stuff, so if he can't help, I have no hope at all ... haha. :)

Chris R @ Nutanix