<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">&lt;<a href="mailto:jhernand@redhat.com" target="_blank">jhernand@redhat.com</a>&gt;</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>
&gt; Hello virt folks,<br>
&gt;<br>
&gt; Background:<br>
&gt;<br>
&gt; I&#39;m using the REST API to import a VM from an attached export domain.<br>
&gt; The VM was imported using the virt-v2v tool. I&#39;ve tried this with cURL<br>
&gt; and with the python SDK, both yield the same error message.<br>
&gt;<br>
&gt; RHEVM Version: 3.5.6.0-1<br>
&gt; Python SDK Version: 3.5.6.0-1<br>
&gt;<br>
&gt; According to the documentation, importing should follow this syntax:<br>
&gt;<br>
&gt;&gt; POST<br>
&gt; /ovirt-engine/api/storagedomains/{storagedomain:id}/vms/{vm:id}/import<br>
&gt;<br>
&gt; With a small &lt;action&gt; body attached. In theory (by the documentation and<br>
&gt; bug tracker [1]) either of these XML documents (both in the same paste)<br>
&gt; should work:<br>
&gt;<br>
&gt; <a href="http://fpaste.org/309944/52627148/" rel="noreferrer" target="_blank">http://fpaste.org/309944/52627148/</a><br>
&gt;<br>
&gt; However, this fails with the following error message (full response in [2])<br>
&gt;<br>
&gt;&gt; Cannot import VM. Storage Domain type not specified.<br>
&gt;<br>
&gt;<br>
&gt; Steps to reproduce:<br>
&gt;<br>
&gt; 1. Import a VM into an export storage domain<br>
&gt; 2. Create an XML document with an action like this (filling in the<br>
&gt; correct values for the ID variables)<br>
&gt;<br>
&gt;     &lt;action&gt;<br>
&gt;       &lt;cluster id=&quot;&lt;CLUSTER_ID&gt;&quot;/&gt;<br>
&gt;       &lt;storage_domain id=&quot;&lt;STORAGE_DOMAIN_ID&gt;&quot;&gt;<br>
&gt;         &lt;type&gt;export&lt;/type&gt;<br>
&gt;       &lt;/storage_domain&gt;<br>
&gt;       &lt;clone&gt;True&lt;/clone&gt;<br>
&gt;       &lt;vm&gt;<br>
&gt;         &lt;name&gt;IMPORTED_VM&lt;/name&gt;<br>
&gt;       &lt;/vm&gt;<br>
&gt;     &lt;/action&gt;<br>
&gt;<br>
&gt;<br>
&gt; 3. POST to the import location (again, substitute the correct ID<br>
&gt; variables in the location)<br>
&gt;<br>
&gt;     /ovirt-engine/api/storagedomains/&lt;STORAGE_DOMAIN_ID&gt;/vms/&lt;VM_ID&gt;/import<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; Where is this storage domain type supposed to be defined, if not inside<br>
&gt; of the storage_domain element as demonstrated in the documentation?<br>
&gt;<br>
&gt; I would appreciate any advice you can offer or pointers to useful<br>
&gt; resources/documentation.<br>
&gt;<br>
&gt; Thanks!<br>
&gt;<br>
&gt;<br>
&gt; [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>
&gt; [2] <a href="http://fpaste.org/309949/14526274/" rel="noreferrer" target="_blank">http://fpaste.org/309949/14526274/</a><br>
&gt;<br>
&gt; --<br>
&gt; Tim Bielawa<br>
&gt; 1BA0 4FAB 4C13 FBA0 A036  4958 AD05 E75E 0333 AE37<br>
&gt;<br>
<br>
</div></div>The bug that you are referring to (bug 1147011) isn&#39;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>
  &lt;action&gt;<br>
    &lt;cluster id=&quot;00000001-0001-0001-0001-000000000001&quot;/&gt;<br>
    &lt;storage_domain id=&quot;00000001-0001-0001-0001-000000000002&quot;/&gt;<br>
    &lt;clone&gt;true&lt;/clone&gt;<br>
    &lt;vm&gt;<br>
      &lt;name&gt;TBIELAWA_IMPORTED_VM&lt;/name&gt;<br>
<br>
      &lt;!-- Note that this &quot;snapshot&quot; element is needed to avoid<br>
           the bug, even if the VM doesn&#39;t have any snapshot. --&gt;<br>
      &lt;snapshots&gt;<br>
        &lt;collapse_snapshots&gt;true&lt;/collapse_snapshots&gt;<br>
      &lt;/snapshots&gt;<br>
<br>
    &lt;/vm&gt;<br>
  &lt;/action&gt;<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=&quot;mycluster&quot;).get_id()<br>
  target_sd_id = api.storagedomains.get(name=&quot;mydata&quot;).get_id()<br>
<br>
  # Find the export storage domain:<br>
  export_sd = api.storagedomains.get(name=&quot;myexport&quot;)<br>
<br>
  # Find the VM:<br>
  vm = export_sd.vms.get(name=&quot;myvm&quot;)<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=&quot;TBIELAWA_IMPORTED_VM&quot;,<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&#39;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&#39;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>&gt; &lt;action&gt;</div><div>&gt;     &lt;storage_domain id=&quot;27b5c6eb-ae68-4e85-930d-01bba13c07fc&quot;/&gt;</div><div>&gt;     &lt;cluster id=&quot;00000001-0001-0001-0001-000000000159&quot;/&gt;</div><div>&gt;     &lt;vm&gt;</div><div>&gt;         &lt;name&gt;<a href="http://vm.example.com">vm.example.com</a>&lt;/name&gt;</div><div>&gt;         &lt;snapshots&gt;</div><div>&gt;             &lt;collapse_snapshots&gt;true&lt;/collapse_snapshots&gt;</div><div>&gt;         &lt;/snapshots&gt;</div><div>&gt;     &lt;/vm&gt;</div><div> &gt;    &lt;clone&gt;true&lt;/clone&gt;</div><div>&gt; &lt;/action&gt;</div></div><div><br></div><div>It&#39;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 &quot;./rhev-test.py&quot;, line 300, in &lt;module&gt;<br>    result = latest_image.import_vm(import_params)<br>  File &quot;/usr/lib/python2.7/site-packages/ovirtsdk/infrastructure/brokers.py&quot;, line 18763, in import_vm<br>    headers={&quot;Correlation-Id&quot;:correlation_id}<br>  File &quot;/usr/lib/python2.7/site-packages/ovirtsdk/infrastructure/proxy.py&quot;, line 118, in request<br>    persistent_auth=self._persistent_auth)<br>  File &quot;/usr/lib/python2.7/site-packages/ovirtsdk/infrastructure/proxy.py&quot;, line 146, in __doRequest<br>    persistent_auth=persistent_auth<br>  File &quot;/usr/lib/python2.7/site-packages/ovirtsdk/web/connection.py&quot;, 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 &lt;type&gt; element in the storage domain, second test with a &lt;type&gt; 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>&lt;action&gt;<br>    &lt;storage_domain id=&quot;27b5c6eb-ae68-4e85-930d-01bba13c07fc&quot;/&gt;<br>    &lt;cluster id=&quot;00000001-0001-0001-0001-000000000159&quot;/&gt;<br>    &lt;vm&gt;<br>        &lt;name&gt;<a href="http://vm.example.com">vm.example.com</a>&lt;/name&gt;<br>        &lt;snapshots&gt;<br>            &lt;collapse_snapshots&gt;true&lt;/collapse_snapshots&gt;<br>        &lt;/snapshots&gt;<br>    &lt;/vm&gt;<br>    &lt;clone&gt;true&lt;/clone&gt;<br>&lt;/action&gt;<br><br>$ curl -X POST -H &quot;Accept: application/xml&quot; -H &quot;Content-type: application/xml&quot; -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 &#39;<a href="mailto:tbielawa@redhat.com">tbielawa@redhat.com</a>&#39;:<br>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;<br>&lt;action&gt;<br>    &lt;storage_domain id=&quot;27b5c6eb-ae68-4e85-930d-01bba13c07fc&quot;/&gt;<br>    &lt;cluster id=&quot;00000001-0001-0001-0001-000000000159&quot;/&gt;<br>    &lt;vm&gt;<br>        &lt;name&gt;<a href="http://vm.example.com">vm.example.com</a>&lt;/name&gt;<br>        &lt;snapshots&gt;<br>            &lt;collapse_snapshots&gt;true&lt;/collapse_snapshots&gt;<br>        &lt;/snapshots&gt;<br>    &lt;/vm&gt;<br>    &lt;clone&gt;true&lt;/clone&gt;<br>    &lt;status&gt;<br>        &lt;state&gt;failed&lt;/state&gt;<br>    &lt;/status&gt;<br>    &lt;fault&gt;<br>        &lt;reason&gt;Operation Failed&lt;/reason&gt;<br>        &lt;detail&gt;[Cannot import VM. Storage Domain type not specified.]&lt;/detail&gt;<br>    &lt;/fault&gt;<br>&lt;/action&gt; </blockquote></div><div><br></div><div><br></div><div>Second test with the &lt;type&gt; 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>&lt;action&gt;<br>    &lt;storage_domain id=&quot;27b5c6eb-ae68-4e85-930d-01bba13c07fc&quot;&gt;<br>        &lt;type&gt;export&lt;/type&gt;<br>    &lt;/storage_domain&gt;<br>    &lt;cluster id=&quot;00000001-0001-0001-0001-000000000159&quot;/&gt;<br>    &lt;vm&gt;<br>        &lt;name&gt;<a href="http://vm.example.com">vm.example.com</a>&lt;/name&gt;<br>        &lt;snapshots&gt;<br>            &lt;collapse_snapshots&gt;true&lt;/collapse_snapshots&gt;<br>        &lt;/snapshots&gt;<br>    &lt;/vm&gt;<br>    &lt;clone&gt;true&lt;/clone&gt;<br>&lt;/action&gt;<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 &quot;Accept: application/xml&quot; -H &quot;Content-type: application/xml&quot; -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 &#39;<a href="mailto:tbielawa@redhat.com">tbielawa@redhat.com</a>&#39;:<br>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;<br>&lt;action&gt;<br>    &lt;storage_domain id=&quot;27b5c6eb-ae68-4e85-930d-01bba13c07fc&quot;&gt;<br>        &lt;type&gt;export&lt;/type&gt;<br>    &lt;/storage_domain&gt;<br>    &lt;cluster id=&quot;00000001-0001-0001-0001-000000000159&quot;/&gt;<br>    &lt;vm&gt;<br>        &lt;name&gt;<a href="http://vm.example.com">vm.example.com</a>&lt;/name&gt;<br>        &lt;snapshots&gt;<br>            &lt;collapse_snapshots&gt;true&lt;/collapse_snapshots&gt;<br>        &lt;/snapshots&gt;<br>    &lt;/vm&gt;<br>    &lt;clone&gt;true&lt;/clone&gt;<br>    &lt;status&gt;<br>        &lt;state&gt;failed&lt;/state&gt;<br>    &lt;/status&gt;<br>    &lt;fault&gt;<br>        &lt;reason&gt;Operation Failed&lt;/reason&gt;<br>        &lt;detail&gt;[Cannot import VM. Storage Domain type not specified.]&lt;/detail&gt;<br>    &lt;/fault&gt;<br>&lt;/action&gt;</blockquote></div><div><br></div><div><br></div><div>I&#39;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>