Bug 1369753 - It is not possible to deach CD from a VM
Summary: It is not possible to deach CD from a VM
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Virtualization Manager
Classification: Red Hat
Component: ovirt-engine
Version: 3.6.8
Hardware: Unspecified
OS: Unspecified
unspecified
medium
Target Milestone: ovirt-4.1.0-beta
: ---
Assignee: Juan Hernández
QA Contact: Aleksei Slaikovskii
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2016-08-24 10:33 UTC by Roman Hodain
Modified: 2019-11-14 09:01 UTC (History)
9 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2017-04-25 00:47:10 UTC
oVirt Team: Infra
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHEA-2017:0997 0 normal SHIPPED_LIVE Red Hat Virtualization Manager (ovirt-engine) 4.1 GA 2017-04-18 20:11:26 UTC
oVirt gerrit 62848 0 None MERGED Improve the documentation of the VM CDROMs services 2021-02-19 16:30:40 UTC

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


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