<div dir="ltr"><div><br></div><div class="gmail_extra"><div class="gmail_quote">On Wed, Jan 13, 2016 at 5:01 AM, Juan Hernández <span dir="ltr"><<a href="mailto:jhernand@redhat.com" target="_blank">jhernand@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class=""><div class="h5">On 01/12/2016 08:44 PM, Tim Bielawa wrote:<br>
> Hello virt folks,<br>
><br>
> Background:<br>
><br>
> I'm using the REST API to import a VM from an attached export domain.<br>
> The VM was imported using the virt-v2v tool. I've tried this with cURL<br>
> and with the python SDK, both yield the same error message.<br>
><br>
> RHEVM Version: 3.5.6.0-1<br>
> Python SDK Version: 3.5.6.0-1<br>
><br>
> According to the documentation, importing should follow this syntax:<br>
><br>
>> POST<br>
> /ovirt-engine/api/storagedomains/{storagedomain:id}/vms/{vm:id}/import<br>
><br>
> With a small <action> body attached. In theory (by the documentation and<br>
> bug tracker [1]) either of these XML documents (both in the same paste)<br>
> should work:<br>
><br>
> <a href="http://fpaste.org/309944/52627148/" rel="noreferrer" target="_blank">http://fpaste.org/309944/52627148/</a><br>
><br>
> However, this fails with the following error message (full response in [2])<br>
><br>
>> Cannot import VM. Storage Domain type not specified.<br>
><br>
><br>
> Steps to reproduce:<br>
><br>
> 1. Import a VM into an export storage domain<br>
> 2. Create an XML document with an action like this (filling in the<br>
> correct values for the ID variables)<br>
><br>
> <action><br>
> <cluster id="<CLUSTER_ID>"/><br>
> <storage_domain id="<STORAGE_DOMAIN_ID>"><br>
> <type>export</type><br>
> </storage_domain><br>
> <clone>True</clone><br>
> <vm><br>
> <name>IMPORTED_VM</name><br>
> </vm><br>
> </action><br>
><br>
><br>
> 3. POST to the import location (again, substitute the correct ID<br>
> variables in the location)<br>
><br>
> /ovirt-engine/api/storagedomains/<STORAGE_DOMAIN_ID>/vms/<VM_ID>/import<br>
><br>
><br>
><br>
> Where is this storage domain type supposed to be defined, if not inside<br>
> of the storage_domain element as demonstrated in the documentation?<br>
><br>
> I would appreciate any advice you can offer or pointers to useful<br>
> resources/documentation.<br>
><br>
> Thanks!<br>
><br>
><br>
> [1] <a href="https://bugzilla.redhat.com/show_bug.cgi?id=1147011#c13" rel="noreferrer" target="_blank">https://bugzilla.redhat.com/show_bug.cgi?id=1147011#c13</a><br>
> [2] <a href="http://fpaste.org/309949/14526274/" rel="noreferrer" target="_blank">http://fpaste.org/309949/14526274/</a><br>
><br>
> --<br>
> Tim Bielawa<br>
> 1BA0 4FAB 4C13 FBA0 A036 4958 AD05 E75E 0333 AE37<br>
><br>
<br>
</div></div>The bug that you are referring to (bug 1147011) isn't fixed in version<br>
3.5, and there are no plans to fix it, as far as I know. It will be<br>
fixed on only in 3.6. This means that you have to apply the workaround<br>
that Sven Kieske mentions in the description of the bug. So the XML<br>
document to send should look like this:<br>
<br>
<action><br>
<cluster id="00000001-0001-0001-0001-000000000001"/><br>
<storage_domain id="00000001-0001-0001-0001-000000000002"/><br>
<clone>true</clone><br>
<vm><br>
<name>TBIELAWA_IMPORTED_VM</name><br>
<br>
<!-- Note that this "snapshot" element is needed to avoid<br>
the bug, even if the VM doesn't have any snapshot. --><br>
<snapshots><br>
<collapse_snapshots>true</collapse_snapshots><br>
</snapshots><br>
<br>
</vm><br>
</action><br>
<br>
With the Python SDK should be something like this:<br>
<br>
# Find the target cluster and storage domain:<br>
target_cluster_id = api.clusters.get(name="mycluster").get_id()<br>
target_sd_id = api.storagedomains.get(name="mydata").get_id()<br>
<br>
# Find the export storage domain:<br>
export_sd = api.storagedomains.get(name="myexport")<br>
<br>
# Find the VM:<br>
vm = export_sd.vms.get(name="myvm")<br>
<br>
# Import the VM:<br>
vm.import_vm(<br>
params.Action(<br>
cluster=params.Cluster(id=target_cluster_id),<br>
storage_domain=params.StorageDomain(id=target_sd_id),<br>
clone=True,<br>
vm=params.VM(<br>
name="TBIELAWA_IMPORTED_VM",<br>
snapshots=params.Snapshots(<br>
collapse_snapshots=True<br>
)<br>
)<br>
)<br>
)<br>
<span class=""><font color="#888888"><br>
--<br>
Dirección Comercial: C/Jose Bardasano Baos, 9, Edif. Gorbea 3, planta<br>
3ºD, 28016 Madrid, Spain<br>
Inscrita en el Reg. Mercantil de Madrid – C.I.F. B82657941 - Red Hat S.L.<br>
</font></span></blockquote></div><br><br>Thanks for the tips Juan, I appreciate the response.<div><br></div><div>I didn't understand how that work-around was supposed to work the first time I read that in the BZ, thanks for clarifying with those examples.</div><div><br></div><div>Unfortunately though, I've integrated what you offered into my script and am still running into walls. I found the ParseHelper.toXml function and used that to debug what the params.Action is evaluating to before calling the import_vm() method on the target import VM:</div><div><br></div><div><div>> <action></div><div>> <storage_domain id="27b5c6eb-ae68-4e85-930d-01bba13c07fc"/></div><div>> <cluster id="00000001-0001-0001-0001-000000000159"/></div><div>> <vm></div><div>> <name><a href="http://vm.example.com">vm.example.com</a></name></div><div>> <snapshots></div><div>> <collapse_snapshots>true</collapse_snapshots></div><div>> </snapshots></div><div>> </vm></div><div> > <clone>true</clone></div><div>> </action></div></div><div><br></div><div>It's basically identical to what you offered in your example. Yet still, I run into this problem:</div><div><br></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Traceback (most recent call last):<br> File "./rhev-test.py", line 300, in <module><br> result = latest_image.import_vm(import_params)<br> File "/usr/lib/python2.7/site-packages/ovirtsdk/infrastructure/brokers.py", line 18763, in import_vm<br> headers={"Correlation-Id":correlation_id}<br> File "/usr/lib/python2.7/site-packages/ovirtsdk/infrastructure/proxy.py", line 118, in request<br> persistent_auth=self._persistent_auth)<br> File "/usr/lib/python2.7/site-packages/ovirtsdk/infrastructure/proxy.py", line 146, in __doRequest<br> persistent_auth=persistent_auth<br> File "/usr/lib/python2.7/site-packages/ovirtsdk/web/connection.py", line 134, in doRequest<br> raise RequestError, response<br>ovirtsdk.infrastructure.errors.RequestError:<br>status: 400<br>reason: Bad Request<br>detail: Cannot import VM. Storage Domain type not specified.</blockquote><div><br></div><div><br>Just to be absolutely sure about this, I ran some tests using the API and cURL. Two tests, first without a <type> element in the storage domain, second test with a <type> in the storage domain.</div><div><br></div><div>First test failed, same error message:</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">$ cat import-params.xml<br><action><br> <storage_domain id="27b5c6eb-ae68-4e85-930d-01bba13c07fc"/><br> <cluster id="00000001-0001-0001-0001-000000000159"/><br> <vm><br> <name><a href="http://vm.example.com">vm.example.com</a></name><br> <snapshots><br> <collapse_snapshots>true</collapse_snapshots><br> </snapshots><br> </vm><br> <clone>true</clone><br></action><br><br>$ curl -X POST -H "Accept: application/xml" -H "Content-type: application/xml" -u <a href="mailto:tbielawa@redhat.com">tbielawa@redhat.com</a> --cacert /home/....crt -d @import-params.xml https://...:443/ovirt-engine/api/storagedomains/27b5c6eb-ae68-4e85-930d-01bba13c07fc/vms/69902f78-7dbf-45cb-a264-f29edb8e7f0a/import<br>Enter host password for user '<a href="mailto:tbielawa@redhat.com">tbielawa@redhat.com</a>':<br><?xml version="1.0" encoding="UTF-8" standalone="yes"?><br><action><br> <storage_domain id="27b5c6eb-ae68-4e85-930d-01bba13c07fc"/><br> <cluster id="00000001-0001-0001-0001-000000000159"/><br> <vm><br> <name><a href="http://vm.example.com">vm.example.com</a></name><br> <snapshots><br> <collapse_snapshots>true</collapse_snapshots><br> </snapshots><br> </vm><br> <clone>true</clone><br> <status><br> <state>failed</state><br> </status><br> <fault><br> <reason>Operation Failed</reason><br> <detail>[Cannot import VM. Storage Domain type not specified.]</detail><br> </fault><br></action> </blockquote></div><div><br></div><div><br></div><div>Second test with the <type> set failed as well:</div><div><br></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">$ cat import-params.xml<br><action><br> <storage_domain id="27b5c6eb-ae68-4e85-930d-01bba13c07fc"><br> <type>export</type><br> </storage_domain><br> <cluster id="00000001-0001-0001-0001-000000000159"/><br> <vm><br> <name><a href="http://vm.example.com">vm.example.com</a></name><br> <snapshots><br> <collapse_snapshots>true</collapse_snapshots><br> </snapshots><br> </vm><br> <clone>true</clone><br></action><br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"> </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">$ curl -X POST -H "Accept: application/xml" -H "Content-type: application/xml" -u <a href="mailto:tbielawa@redhat.com">tbielawa@redhat.com</a> --cacert /home/....crt -d @import-params.xml https://...:443/ovirt-engine/api/storagedomains/27b5c6eb-ae68-4e85-930d-01bba13c07fc/vms/69902f78-7dbf-45cb-a264-f29edb8e7f0a/import<br>Enter host password for user '<a href="mailto:tbielawa@redhat.com">tbielawa@redhat.com</a>':<br><?xml version="1.0" encoding="UTF-8" standalone="yes"?><br><action><br> <storage_domain id="27b5c6eb-ae68-4e85-930d-01bba13c07fc"><br> <type>export</type><br> </storage_domain><br> <cluster id="00000001-0001-0001-0001-000000000159"/><br> <vm><br> <name><a href="http://vm.example.com">vm.example.com</a></name><br> <snapshots><br> <collapse_snapshots>true</collapse_snapshots><br> </snapshots><br> </vm><br> <clone>true</clone><br> <status><br> <state>failed</state><br> </status><br> <fault><br> <reason>Operation Failed</reason><br> <detail>[Cannot import VM. Storage Domain type not specified.]</detail><br> </fault><br></action></blockquote></div><div><br></div><div><br></div><div>I'm stumped. Any other ideas?</div><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr">Tim Bielawa, Sr. ${::title}<br>Cell: 919.332.6411 | IRC: tbielawa (#platops)<br>1BA0 4FAB 4C13 FBA0 A036 4958 AD05 E75E 0333 AE37<br></div></div>
</div></div>