API

Welcome to the Nutanix NEXT community. To get started please read our short welcome post. Thanks!

cancel
Showing results for 
Search instead for 
Did you mean: 

Rest API v3 updating vm settings

Adventurer

Rest API v3 updating vm settings

Hello, 

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?

Tags (3)
6 REPLIES
Nutanix Employee

Re: Rest API v3 updating vm settings

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.

Tags (3)
Adventurer

Re: Rest API v3 updating vm settings

thank you for explanation,

Do you have a full description of Rest API v3 ? Because I couldn't find that information here:

http://developer.nutanix.com/reference/v3/#vms-uuid-put

I think there might be other unpredictable things for me.

Tags (3)
Nutanix Employee

Re: Rest API v3 updating vm settings

@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.

 

Tags (3)
Adventurer

Re: Rest API v3 updating vm settings

Hello, 

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'] = 55000
result.pop('status', None)

after that I use result as a body for update VM.

Tags (3)
Highlighted
Nutanix Employee

Re: Rest API v3 updating vm settings

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.

Tags (3)
Adventurer

Re: Rest API v3 updating vm settings

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.

 

 

 

Tags (3)