Bug 1269898 - REST: can not create a VM disk via json (it's possible via XML fine)
REST: can not create a VM disk via json (it's possible via XML fine)
Status: CLOSED NOTABUG
Product: Red Hat Enterprise Virtualization Manager
Classification: Red Hat
Component: ovirt-engine-restapi (Show other bugs)
3.6.0
Unspecified Unspecified
unspecified Severity unspecified
: ovirt-3.6.0-rc3
: 3.6.0
Assigned To: Juan Hernández
Pavel Stehlik
infra
:
: 1269899 (view as bug list)
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2015-10-08 08:45 EDT by David Jaša
Modified: 2016-02-10 14:09 EST (History)
8 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2015-10-09 16:47:21 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: Infra
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
full error and exception (11.94 KB, text/plain)
2015-10-08 08:45 EDT, David Jaša
no flags Details

  None (edit)
Description David Jaša 2015-10-08 08:45:17 EDT
Created attachment 1080990 [details]
full error and exception

Description of problem:
REST: can not create a VM disk via json (it's possible via XML fine)

Version-Release number of selected component (if applicable):
rhevm-backend-3.6.0-0.18.el6.noarch
rhevm-restapi-3.6.0-0.18.el6.noarch

How reproducible:
always

Steps to Reproduce (substitute VM and SD UUIDs for yours):
1. try to create a VM disk using xml api:
$ curl -b .cookies/rhevm36-user -H 'filter: true' -H 'prefer: persistent-auth' https://rhevm36.example.com/ovirt-engine/api/vms/b2c9f0ca-6d8a-46c9-9503-de8e0484fa76/disks -X POST -H 'content-type: application/xml' -d '<disk><storage_domains><storage_domain id="a57f4682-87be-4902-92ee-0223ae3537be"/></storage_domains><provisioned_size>12884901888</provisioned_size><type>system</type><interface>virtio_scsi</interface><format>cow</format><bootable>false</bootable></disk>'
2. do exactly the same request using json:
$ curl -b .cookies/rhevm36-user -H 'filter: true' -H 'prefer: persistent-auth' https://rhevm36.example.com/ovirt-engine/api/vms/b2c9f0ca-6d8a-46c9-9503-de8e0484fa76/disks -X POST -H 'content-type: application/json' -d '{ "storage_domains": {"storage_domain": {"id": "a57f4682-87be-4902-92ee-0223ae3537be"}}, "provisioned_size": "12884901888", "type": "system", "interface": "virtio_scsi", "format": "cow", "bootable": "false" }'

Actual results:
1. works
2. returns:
    * "Request syntactically incorrect." message
    * log: 
> ... Can not deserialize instance of java.util.ArrayList out of START_OBJECT token
> line: 1, column: 23] (through reference chain: org.ovirt.engine.api.model.Disk["storage_domains"]->org.ovirt.engine.api.model.StorageDomains["storage_domain"]

Expected results:
the two commands work exactly the same

Additional info:
Comment 1 David Jaša 2015-10-08 10:22:35 EDT
*** Bug 1269899 has been marked as a duplicate of this bug. ***
Comment 2 Juan Hernández 2015-10-08 10:50:22 EDT
Those two requests aren't identical. In the JSON version the "storage_domain" element is an object, but it should be an array:

  {
    "storage_domains": {
      "storage_domain": [ {
        "id": "a57f4682-87be-4902-92ee-0223ae3537be"
      } ],
    },
    "provisioned_size": "12884901888",
    "type": "system",
    "interface": "virtio_scsi",
    "format": "cow",
    "bootable": "false"
  }

When in doubt about the format create the object using XML, or the GUI, and then request it with JSON format. You can do that in your browser, using an URL like the following:

  https://.../api/vms/{vm:id}/disks/{disk:id}?accept=application/json

Test this and close the bug as NOTABUG if it works correctly.
Comment 3 David Jaša 2015-10-09 16:47:21 EDT
> In the JSON version the "storage_domain" element is an object, but it should be an array

Yeah, bracket additions under storage_domains fixed the request for me.

Note You need to log in before you can comment on or make changes to this bug.