According to the documentation to eject a media from a VM we need
1. a link: POST /vApp/{id}/media/action/ejectMedia
2. a reference to a media we want to eject
However all we can find about the attached media in the VM's xml is its name.
GET /vApp/{id}/virtualHardwareSection/media
<Item>
<rasd:AddressOnParent>0</rasd:AddressOnParent>
<rasd:AutomaticAllocation>true</rasd:AutomaticAllocation>
<rasd:Description>CD/DVD Drive</rasd:Description>
<rasd:ElementName>CD/DVD Drive 1</rasd:ElementName>
<rasd:HostResource>test_disk.iso</rasd:HostResource>
<rasd:InstanceID>3002</rasd:InstanceID>
<rasd:Parent>2</rasd:Parent>
<rasd:ResourceSubType>vmware.cdrom.iso</rasd:ResourceSubType>
<rasd:ResourceType>15</rasd:ResourceType>
</Item>
So, to get an href for the "test_disk.iso" we need to go through available catalogs and look for a media with name "test_disk.iso". But likely you have more than one catalog and there's high probability they could have medias with the same name. No surprise in this case search by name won't work.
And here comes my question. Is there a way to determine an href of a media that is attached to a VM?
After looking at the code, I think this is a gap in the VCD REST API. Worse, because the <Item> comes from OVF, this might not even be easily fixable (we have a similar problem for disks, where we have a custom attribute 'storageProfileHref' to point to the corresponding vCD storage profile). Getting this to work will require a code change in vCD.
In the mean time, you can use the solution you proposed: just attempt to eject the media ID for all media with the name "test_disk.iso", some will fail (which you can ignore), but one will work.
To match the disk to storage profile, this is the API we use:
curl -sik -H "Accept:application/*+xml;version=5.6" -u admin@system -X GET https://vCD-FQDN:443/api/sessions | grep auth
curl -sik -H "Accept:application/*+xml;version=5.6" -H "x-vcloud-authorization:Auth-Token" -X GET https://vcd-fqdn:443/api/org/ | grep Org name
curl -sik -H "Accept:application/*+xml;version=5.6" -H "x-vcloud-authorization:Auth-Token" -X GET https://vCD-FQDN:443/api/org/9d0be397-4cbc-4031-a14d-431e4e4a96ca | grep vdc
curl -sik -H "Accept:application/*+xml;version=5.6" -H "x-vcloud-authorization:Auth-Token" -X GET https://vCD-FQDN:443/api/vdc/465ce840-d4a2-4222-bc8f-18f690b63772 | grep VdcStorageProfile
Output of above API calls will look like as below
<VdcStorageProfile href="https://vcd-fqdn:443/api/vdcStorageProfile/c04d697f-3194-43f8-af89-6668adaa9c54" name="Standard" type="application/vnd.vmware.vcloud.vdcStorageProfile+xml"/>
** Here c04d697f-3194-43f8-af89-6668adaa9c54 is the UUID of storage profile and Standard is the name of profile
Hi Manish,
What you posted above is a Storage Profile(Policy) list of an org vdc which is no problem to get. But how does it help to find a href of an ISO mounted to the VM?