Bug 1269898 - REST: can not create a VM disk via json (it's possible via XML fine)
Summary: REST: can not create a VM disk via json (it's possible via XML fine)
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Virtualization Manager
Classification: Red Hat
Component: ovirt-engine-restapi
Version: 3.6.0
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ovirt-3.6.0-rc3
: 3.6.0
Assignee: Juan Hernández
QA Contact: Pavel Stehlik
URL:
Whiteboard: infra
: 1269899 (view as bug list)
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2015-10-08 12:45 UTC by David Jaša
Modified: 2016-02-10 19:09 UTC (History)
8 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2015-10-09 20:47:21 UTC
oVirt Team: Infra
Target Upstream Version:


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

Description David Jaša 2015-10-08 12:45:17 UTC
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 14:22:35 UTC
*** Bug 1269899 has been marked as a duplicate of this bug. ***

Comment 2 Juan Hernández 2015-10-08 14:50:22 UTC
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 20:47:21 UTC
> 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.