<div dir="ltr">Beautiful!!<div><br></div><div>Oh man, thanks so much. I never would have figured that out on my own.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 13, 2016 at 12:28 PM, 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 01/13/2016 05:54 PM, Tim Bielawa wrote:<br>
><br>
> On Wed, Jan 13, 2016 at 5:01 AM, Juan Hernández <<a href="mailto:jhernand@redhat.com">jhernand@redhat.com</a><br>
</span><div><div class="h5">> <mailto:<a href="mailto:jhernand@redhat.com">jhernand@redhat.com</a>>> wrote:<br>
><br>
> 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<br>
> documentation and<br>
> > bug tracker [1]) either of these XML documents (both in the same<br>
> 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<br>
> 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>
> ><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<br>
> 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>
> 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>
><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<br>
> S.L.<br>
><br>
><br>
><br>
> Thanks for the tips Juan, I appreciate the response.<br>
><br>
> I didn't understand how that work-around was supposed to work the first<br>
> time I read that in the BZ, thanks for clarifying with those examples.<br>
><br>
> Unfortunately though, I've integrated what you offered into my script<br>
> and am still running into walls. I found the ParseHelper.toXml function<br>
> and used that to debug what the params.Action is evaluating to before<br>
> calling the import_vm() method on the target import VM:<br>
><br>
>> <action><br>
>> <storage_domain id="27b5c6eb-ae68-4e85-930d-01bba13c07fc"/><br>
>> <cluster id="00000001-0001-0001-0001-000000000159"/><br>
>> <vm><br>
</div></div>>> <name><a href="http://vm.example.com" rel="noreferrer" target="_blank">vm.example.com</a> <<a href="http://vm.example.com" rel="noreferrer" target="_blank">http://vm.example.com</a>></name><br>
<div><div class="h5">>> <snapshots><br>
>> <collapse_snapshots>true</collapse_snapshots><br>
>> </snapshots><br>
>> </vm><br>
> > <clone>true</clone><br>
>> </action><br>
><br>
> It's basically identical to what you offered in your example. Yet still,<br>
> I run into this problem:<br>
><br>
> Traceback (most recent call last):<br>
> File "./rhev-test.py", line 300, in <module><br>
> result = latest_image.import_vm(import_params)<br>
> File<br>
> "/usr/lib/python2.7/site-packages/ovirtsdk/infrastructure/brokers.py",<br>
> line 18763, in import_vm<br>
> headers={"Correlation-Id":correlation_id}<br>
> File<br>
> "/usr/lib/python2.7/site-packages/ovirtsdk/infrastructure/proxy.py",<br>
> line 118, in request<br>
> persistent_auth=self._persistent_auth)<br>
> File<br>
> "/usr/lib/python2.7/site-packages/ovirtsdk/infrastructure/proxy.py",<br>
> line 146, in __doRequest<br>
> persistent_auth=persistent_auth<br>
> File<br>
> "/usr/lib/python2.7/site-packages/ovirtsdk/web/connection.py", line<br>
> 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.<br>
><br>
><br>
><br>
> Just to be absolutely sure about this, I ran some tests using the API<br>
> and cURL. Two tests, first without a <type> element in the storage<br>
> domain, second test with a <type> in the storage domain.<br>
><br>
> First test failed, same error message:<br>
><br>
> $ 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>
</div></div>> <name><a href="http://vm.example.com" rel="noreferrer" target="_blank">vm.example.com</a> <<a href="http://vm.example.com" rel="noreferrer" target="_blank">http://vm.example.com</a>></name><br>
<span class="">> <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:<br>
</span>> application/xml" -u <a href="mailto:tbielawa@redhat.com">tbielawa@redhat.com</a> <mailto:<a href="mailto:tbielawa@redhat.com">tbielawa@redhat.com</a>><br>
<span class="">> --cacert /home/....crt -d @import-params.xml<br>
> 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>
</span>> <mailto:<a href="mailto:tbielawa@redhat.com">tbielawa@redhat.com</a>>':<br>
<span class="">> <?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>
</span>> <name><a href="http://vm.example.com" rel="noreferrer" target="_blank">vm.example.com</a> <<a href="http://vm.example.com" rel="noreferrer" target="_blank">http://vm.example.com</a>></name><br>
<span class="">> <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<br>
> specified.]</detail><br>
> </fault><br>
> </action><br>
><br>
><br>
><br>
> Second test with the <type> set failed as well:<br>
><br>
> $ 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>
</span>> <name><a href="http://vm.example.com" rel="noreferrer" target="_blank">vm.example.com</a> <<a href="http://vm.example.com" rel="noreferrer" target="_blank">http://vm.example.com</a>></name><br>
<span class="">> <snapshots><br>
> <collapse_snapshots>true</collapse_snapshots><br>
> </snapshots><br>
> </vm><br>
> <clone>true</clone><br>
> </action><br>
><br>
><br>
><br>
> $ curl -X POST -H "Accept: application/xml" -H "Content-type:<br>
</span>> application/xml" -u <a href="mailto:tbielawa@redhat.com">tbielawa@redhat.com</a> <mailto:<a href="mailto:tbielawa@redhat.com">tbielawa@redhat.com</a>><br>
<span class="">> --cacert /home/....crt -d @import-params.xml<br>
> 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>
</span>> <mailto:<a href="mailto:tbielawa@redhat.com">tbielawa@redhat.com</a>>':<br>
<span class="">> <?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>
</span>> <name><a href="http://vm.example.com" rel="noreferrer" target="_blank">vm.example.com</a> <<a href="http://vm.example.com" rel="noreferrer" target="_blank">http://vm.example.com</a>></name><br>
<span class="">> <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<br>
> specified.]</detail><br>
> </fault><br>
> </action><br>
><br>
><br>
><br>
> I'm stumped. Any other ideas?<br>
><br>
<br>
</span>In these latest examples that you sent looks like you are using the<br>
storage domain with id 27b5c6eb-ae68-4e85-930d-01bba13c07fc as both the<br>
source and the target of the import. They need to be different. The<br>
source, the one that you specify in the URL, should be the export<br>
storage domain. The target, the one you specify in <storage_domain<br>
id="...">, should be the one you want to import the VM to. Try to change<br>
that, please.<br>
<div class="HOEnZb"><div class="h5"><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>
</div></div></blockquote></div><br><br clear="all"><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>