Bug 1369753

Summary: It is not possible to deach CD from a VM
Product: Red Hat Enterprise Virtualization Manager Reporter: Roman Hodain <rhodain>
Component: ovirt-engineAssignee: Juan Hernández <juan.hernandez>
Status: CLOSED ERRATA QA Contact: Aleksei Slaikovskii <aslaikov>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 3.6.8CC: gklein, juan.hernandez, lsurette, pstehlik, rbalakri, Rhev-m-bugs, rhodain, srevivo, ykaul
Target Milestone: ovirt-4.1.0-beta   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-04-25 00:47:10 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: Infra RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description Roman Hodain 2016-08-24 10:33:40 UTC
Description of problem:
It is not possible to detach CD from a VM via API

Version-Release number of selected component (if applicable):
RHEV 3.6.8

How reproducible:
100%

Steps to Reproduce:
 curl -X POST -H "Accept: application/xml" -H "Content-Type: application/xml" -u admin@internal:romanroman --cacert /etc/pki/ovirt-engine/ca.pem -d "<cdrom><file id=''/></cdrom>" 


Actual results:
'https://rhevm36/api/vms/82a00273-5e64-4c68-87b4-3cf78bb8d47d/cdroms;current=True'
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<fault>
    <reason>Incomplete parameters</reason>
    <detail>CdRom [file.id] required for add</detail>
</fault>

Expected results:
CD is detached from the VM

Additional info:
This should work according to the Bug 1135970 .

The python SDK fails with 'str' object has no attribute 'export_'

params.py(27184):             self.file.export_(outfile, level, namespace_, name_='file', pretty_print=pretty_print)

The rsdl shows 
                    <type>CdRom</type>
                    <parameters_set>
                        <description>update the cdrom for a virtual machine identified by the given id with a new file</description>
                        <parameter required="false" type="xs:string">
                            <name>cdrom.file.id</name>
                        </parameter>
                    </parameters_set>

Comment 3 Juan Hernández 2016-08-25 11:42:58 UTC
It is important to understand the difference between the CDROM device and the CDROM disk. The operations that you most likely want to perform is inserting, changing or ejecting the CDROM disk. To do so you should always use the /vms/{vm:id}/cdrom/{cdrom:id} resource, and the PUT method. It is also important to understand that you can manage the CDROM disk that is currently visible to the running VM, the "current" CDROM disk, and the CDROM disk that will be visible next time the VM is started.

To insert/change a disk visible to the running VM:

  PUT /vms/{vm:id}/cdroms/{cdrom:id};current=true
  <cdrom>
    <file id="mycd.iso"/>
  </cdrom>

To eject the disk currently visible to the running VM:

  PUT /vms/{vm:id}/cdroms/{cdrom:id};current=true
  <cdrom>
    <file id=""/>
  </cdrom>

None of these persists, it only affects the currently running VM. To make the change persistent, after the next boot of the virtual machine, add the "current=false" parameter (or just omit it).

To persistently set the CDROM disk visible after next boot:

  PUT /vms/{vm:id}/cdrom/{cdrom:id}
  <cdrom>
    <file id="mycd.iso"/>
  </cdrom>

To persistently remove the CDROM visible after next boot:

  PUT /vms/{vm:id}/cdrom/{cdrom:id}
  <cdrom>
    <file id=""/>
  </cdrom>

Note that in all cases you should use the PUT method.

The POST and DELETE methods should work with the CDROM devices, but the don't because virtual machines have exactly one CDROM device. These methods try instead to insert and eject the disks, which causes confusion. They should probably be removed.

The DELETE method has also other problem, derived from its implementation in Resteasy, it won't be selected if you specify a "Content-Type" header. You can try it without header, and should work, but it isn't the recommended way to eject the disk, try PUT with an empty <file id=""/> instead.

With the Python SDK the way to do this is to first get the CDROM device:

  cd = vm.cdroms.list()[0]

And then update it.

To insert/change the current disk:

  cd.set_file(params.File(id="mycd.iso"))
  cd.update(current=True)
  
To eject the current disk:

  cd.set_file(params.File(id=""));
  cd.update(current=True)

To insert/change the persisted disk:

  cd.set_file(params.File(id="mycd.iso"))
  cd.update()

To eject the persisted disk:

  cd.set_file(params.File(id=""))
  cd.update()

Please check if this works correctly.

Comment 4 Juan Hernández 2016-08-25 12:50:31 UTC
I'm trying to clarify the usage of this part of the API here:

  Improve the documentation of the VM CDROMs services
  https://gerrit.ovirt.org/62848

Comment 5 Roman Hodain 2016-08-29 07:23:33 UTC
(In reply to Juan Hernández from comment #3)
> It is important to understand the difference between the CDROM device and
> the CDROM disk. The operations that you most likely want to perform is
> inserting, changing or ejecting the CDROM disk. To do so you should always
> use the /vms/{vm:id}/cdrom/{cdrom:id} resource, and the PUT method. It is
> also important to understand that you can manage the CDROM disk that is
> currently visible to the running VM, the "current" CDROM disk, and the CDROM
> disk that will be visible next time the VM is started.
> 
> To insert/change a disk visible to the running VM:
> 
>   PUT /vms/{vm:id}/cdroms/{cdrom:id};current=true
>   <cdrom>
>     <file id="mycd.iso"/>
>   </cdrom>
> 
> To eject the disk currently visible to the running VM:
> 
>   PUT /vms/{vm:id}/cdroms/{cdrom:id};current=true
>   <cdrom>
>     <file id=""/>
>   </cdrom>
> 
> None of these persists, it only affects the currently running VM. To make
> the change persistent, after the next boot of the virtual machine, add the
> "current=false" parameter (or just omit it).
> 
> To persistently set the CDROM disk visible after next boot:
> 
>   PUT /vms/{vm:id}/cdrom/{cdrom:id}
>   <cdrom>
>     <file id="mycd.iso"/>
>   </cdrom>
> 
> To persistently remove the CDROM visible after next boot:
> 
>   PUT /vms/{vm:id}/cdrom/{cdrom:id}
>   <cdrom>
>     <file id=""/>
>   </cdrom>
> 
> Note that in all cases you should use the PUT method.
> 
> The POST and DELETE methods should work with the CDROM devices, but the
> don't because virtual machines have exactly one CDROM device. These methods
> try instead to insert and eject the disks, which causes confusion. They
> should probably be removed.
> 
> The DELETE method has also other problem, derived from its implementation in
> Resteasy, it won't be selected if you specify a "Content-Type" header. You
> can try it without header, and should work, but it isn't the recommended way
> to eject the disk, try PUT with an empty <file id=""/> instead.
> 
> With the Python SDK the way to do this is to first get the CDROM device:
> 
>   cd = vm.cdroms.list()[0]
> 
> And then update it.
> 
> To insert/change the current disk:
> 
>   cd.set_file(params.File(id="mycd.iso"))
>   cd.update(current=True)
>   
> To eject the current disk:
> 
>   cd.set_file(params.File(id=""));
>   cd.update(current=True)
> 
> To insert/change the persisted disk:
> 
>   cd.set_file(params.File(id="mycd.iso"))
>   cd.update()
> 
> To eject the persisted disk:
> 
>   cd.set_file(params.File(id=""))
>   cd.update()
> 
> Please check if this works correctly.

Works as as explained. Thank you.

Comment 6 Juan Hernández 2016-08-29 08:13:32 UTC
The documentation has been improved in the specification of the API. This bug will be moved to MODIFIED when the server is updated to use the version 4.1.11 or newer of the specification.

Comment 8 Aleksei Slaikovskii 2017-01-31 18:07:08 UTC
Verified on ovirt-engine-setup-4.1.1-0.0.master