Hello Expert,
When I call rest api to create a disk for vm, the api response with an error body:
2018-04-17T13:47:42.539Z+08:00 ▶ INFO >> e8da8850209f method: POST, path: rest/vcenter/vm/vm-xxxxx/hardware/disk, headers: map[content-type:application/json accept:application/json vmware-api-session-id:xxxxxxxxx], body: {"spec":{"type":"SCSI","ide":{"primary":true,"master":true},"scsi":{"bus":0,"unit":0},"sata":{"bus":0,"unit":0},"backing":{"type":""},"new_vmdk":{"name":"Hard disk 2","capacity":1073741824}}}
2018-04-17T13:47:42.945Z+08:00 ▶ ERRO << e8da8850209f status: 400, response: {"type":"com.vmware.vapi.std.errors.invalid_argument","value":{"messages":[{"args":["com.vmware.vcenter.vm.hardware.disk.create_spec","sata"],"default_message":"Structure com.vmware.vcenter.vm.hardware.disk.create_spec has a union with a field not allowed for this case: sata","id":"vapi.data.structure.union.extra"}]}}
For your convenience of view, the request json body:
{
"spec": {
"backing": {
"type": ""
},
"ide": {
"master": true,
"primary": true
},
"new_vmdk": {
"capacity": 1073741824,
"name": "Hard disk 2"
},
"sata": {
"bus": 0,
"unit": 0
},
"scsi": {
"bus": 0,
"unit": 0
},
"type": "SCSI"
}
}
response:
{
"type": "com.vmware.vapi.std.errors.invalid_argument",
"value": {
"messages": [
{
"args": [
"com.vmware.vcenter.vm.hardware.disk.create_spec",
"sata"
],
"default_message": "Structure com.vmware.vcenter.vm.hardware.disk.create_spec has a union with a field not allowed for this case: sata",
"id": "vapi.data.structure.union.extra"
}
]
}
}
What's wrong with my calling to the api? I also tried type: "IDE", reporting sata too, or type: "SATA", reporting "scsi"
Thanks for any advice.
Well, I got the root cause for this issue:
In the response, it reports "Structure com.vmware.vcenter.vm.hardware.disk.create_spec has a union with a field not allowed for this case" The message are same when we assign "SCSI", "SATA", "IDE" to "type". That is because definition of "com.vmware.vcenter.vm.hardware.disk.create_spec" has a union struct which union "SCSI", "SATA", "IDE".
So it's only allowed one of these 3 struct exists in the json body, for instance:
{ "spec":{ "ide":{ "primary":true, "master":true }, "type":"IDE", "new_vmdk":{ "name":"Hard disk 4", "capacity":1073741824 } } }
Or:
{ "spec":{ "type":"SCSI", "new_vmdk":{ "name":"Hard disk 4", "capacity":1073741824 } } }
(The 3 struct part are all optional, so only provide type and new_vmdk would create new disk. Even, type is also optional, vcenter would use guest default type.)