API Importing a VM from an export domain fails

Hello virt folks, Background: I'm using the REST API to import a VM from an attached export domain. The VM was imported using the virt-v2v tool. I've tried this with cURL and with the python SDK, both yield the same error message. RHEVM Version: 3.5.6.0-1 Python SDK Version: 3.5.6.0-1 According to the documentation, importing should follow this syntax:
POST /ovirt-engine /api/storagedomains/{storagedomain:id}/vms/{vm:id}/import
With a small <action> body attached. In theory (by the documentation and bug tracker [1]) either of these XML documents (both in the same paste) should work: http://fpaste.org/309944/52627148/ However, this fails with the following error message (full response in [2])
Cannot import VM. Storage Domain type not specified.
Steps to reproduce: 1. Import a VM into an export storage domain 2. Create an XML document with an action like this (filling in the correct values for the ID variables) <action>
<cluster id="<CLUSTER_ID>"/> <storage_domain id="<STORAGE_DOMAIN_ID>"> <type>export</type> </storage_domain> <clone>True</clone> <vm> <name>IMPORTED_VM</name> </vm> </action>
3. POST to the import location (again, substitute the correct ID variables in the location) /ovirt-engine/api/storagedomains/<STORAGE_DOMAIN_ID>/vms/<VM_ID>/import Where is this storage domain type supposed to be defined, if not inside of the storage_domain element as demonstrated in the documentation? I would appreciate any advice you can offer or pointers to useful resources/documentation. Thanks! [1] https://bugzilla.redhat.com/show_bug.cgi?id=1147011#c13 [2] http://fpaste.org/309949/14526274/ -- Tim Bielawa 1BA0 4FAB 4C13 FBA0 A036 4958 AD05 E75E 0333 AE37

On 01/12/2016 08:44 PM, Tim Bielawa wrote:
Hello virt folks,
Background:
I'm using the REST API to import a VM from an attached export domain. The VM was imported using the virt-v2v tool. I've tried this with cURL and with the python SDK, both yield the same error message.
RHEVM Version: 3.5.6.0-1 Python SDK Version: 3.5.6.0-1
According to the documentation, importing should follow this syntax:
POST /ovirt-engine/api/storagedomains/{storagedomain:id}/vms/{vm:id}/import
With a small <action> body attached. In theory (by the documentation and bug tracker [1]) either of these XML documents (both in the same paste) should work:
http://fpaste.org/309944/52627148/
However, this fails with the following error message (full response in [2])
Cannot import VM. Storage Domain type not specified.
Steps to reproduce:
1. Import a VM into an export storage domain 2. Create an XML document with an action like this (filling in the correct values for the ID variables)
<action> <cluster id="<CLUSTER_ID>"/> <storage_domain id="<STORAGE_DOMAIN_ID>"> <type>export</type> </storage_domain> <clone>True</clone> <vm> <name>IMPORTED_VM</name> </vm> </action>
3. POST to the import location (again, substitute the correct ID variables in the location)
/ovirt-engine/api/storagedomains/<STORAGE_DOMAIN_ID>/vms/<VM_ID>/import
Where is this storage domain type supposed to be defined, if not inside of the storage_domain element as demonstrated in the documentation?
I would appreciate any advice you can offer or pointers to useful resources/documentation.
Thanks!
[1] https://bugzilla.redhat.com/show_bug.cgi?id=1147011#c13 [2] http://fpaste.org/309949/14526274/
-- Tim Bielawa 1BA0 4FAB 4C13 FBA0 A036 4958 AD05 E75E 0333 AE37
The bug that you are referring to (bug 1147011) isn't fixed in version 3.5, and there are no plans to fix it, as far as I know. It will be fixed on only in 3.6. This means that you have to apply the workaround that Sven Kieske mentions in the description of the bug. So the XML document to send should look like this: <action> <cluster id="00000001-0001-0001-0001-000000000001"/> <storage_domain id="00000001-0001-0001-0001-000000000002"/> <clone>true</clone> <vm> <name>TBIELAWA_IMPORTED_VM</name> <!-- Note that this "snapshot" element is needed to avoid the bug, even if the VM doesn't have any snapshot. --> <snapshots> <collapse_snapshots>true</collapse_snapshots> </snapshots> </vm> </action> With the Python SDK should be something like this: # Find the target cluster and storage domain: target_cluster_id = api.clusters.get(name="mycluster").get_id() target_sd_id = api.storagedomains.get(name="mydata").get_id() # Find the export storage domain: export_sd = api.storagedomains.get(name="myexport") # Find the VM: vm = export_sd.vms.get(name="myvm") # Import the VM: vm.import_vm( params.Action( cluster=params.Cluster(id=target_cluster_id), storage_domain=params.StorageDomain(id=target_sd_id), clone=True, vm=params.VM( name="TBIELAWA_IMPORTED_VM", snapshots=params.Snapshots( collapse_snapshots=True ) ) ) ) -- Dirección Comercial: C/Jose Bardasano Baos, 9, Edif. Gorbea 3, planta 3ºD, 28016 Madrid, Spain Inscrita en el Reg. Mercantil de Madrid – C.I.F. B82657941 - Red Hat S.L.

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

On 01/13/2016 05:54 PM, Tim Bielawa wrote:
On Wed, Jan 13, 2016 at 5:01 AM, Juan Hernández <jhernand@redhat.com <mailto:jhernand@redhat.com>> wrote:
On 01/12/2016 08:44 PM, Tim Bielawa wrote: > Hello virt folks, > > Background: > > I'm using the REST API to import a VM from an attached export domain. > The VM was imported using the virt-v2v tool. I've tried this with cURL > and with the python SDK, both yield the same error message. > > RHEVM Version: 3.5.6.0-1 > Python SDK Version: 3.5.6.0-1 > > According to the documentation, importing should follow this syntax: > >> POST > /ovirt-engine/api/storagedomains/{storagedomain:id}/vms/{vm:id}/import > > With a small <action> body attached. In theory (by the documentation and > bug tracker [1]) either of these XML documents (both in the same paste) > should work: > > http://fpaste.org/309944/52627148/ > > However, this fails with the following error message (full response in [2]) > >> Cannot import VM. Storage Domain type not specified. > > > Steps to reproduce: > > 1. Import a VM into an export storage domain > 2. Create an XML document with an action like this (filling in the > correct values for the ID variables) > > <action> > <cluster id="<CLUSTER_ID>"/> > <storage_domain id="<STORAGE_DOMAIN_ID>"> > <type>export</type> > </storage_domain> > <clone>True</clone> > <vm> > <name>IMPORTED_VM</name> > </vm> > </action> > > > 3. POST to the import location (again, substitute the correct ID > variables in the location) > > /ovirt-engine/api/storagedomains/<STORAGE_DOMAIN_ID>/vms/<VM_ID>/import > > > > Where is this storage domain type supposed to be defined, if not inside > of the storage_domain element as demonstrated in the documentation? > > I would appreciate any advice you can offer or pointers to useful > resources/documentation. > > Thanks! > > > [1] https://bugzilla.redhat.com/show_bug.cgi?id=1147011#c13 > [2] http://fpaste.org/309949/14526274/ > > -- > Tim Bielawa > 1BA0 4FAB 4C13 FBA0 A036 4958 AD05 E75E 0333 AE37 >
The bug that you are referring to (bug 1147011) isn't fixed in version 3.5, and there are no plans to fix it, as far as I know. It will be fixed on only in 3.6. This means that you have to apply the workaround that Sven Kieske mentions in the description of the bug. So the XML document to send should look like this:
<action> <cluster id="00000001-0001-0001-0001-000000000001"/> <storage_domain id="00000001-0001-0001-0001-000000000002"/> <clone>true</clone> <vm> <name>TBIELAWA_IMPORTED_VM</name>
<!-- Note that this "snapshot" element is needed to avoid the bug, even if the VM doesn't have any snapshot. --> <snapshots> <collapse_snapshots>true</collapse_snapshots> </snapshots>
</vm> </action>
With the Python SDK should be something like this:
# Find the target cluster and storage domain: target_cluster_id = api.clusters.get(name="mycluster").get_id() target_sd_id = api.storagedomains.get(name="mydata").get_id()
# Find the export storage domain: export_sd = api.storagedomains.get(name="myexport")
# Find the VM: vm = export_sd.vms.get(name="myvm")
# Import the VM: vm.import_vm( params.Action( cluster=params.Cluster(id=target_cluster_id), storage_domain=params.StorageDomain(id=target_sd_id), clone=True, vm=params.VM( name="TBIELAWA_IMPORTED_VM", snapshots=params.Snapshots( collapse_snapshots=True ) ) ) )
-- Dirección Comercial: C/Jose Bardasano Baos, 9, Edif. Gorbea 3, planta 3ºD, 28016 Madrid, Spain Inscrita en el Reg. Mercantil de Madrid – C.I.F. B82657941 - Red Hat S.L.
Thanks for the tips Juan, I appreciate the response.
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.
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:
<action> <storage_domain id="27b5c6eb-ae68-4e85-930d-01bba13c07fc"/> <cluster id="00000001-0001-0001-0001-000000000159"/> <vm> <name>vm.example.com <http://vm.example.com></name> <snapshots> <collapse_snapshots>true</collapse_snapshots> </snapshots> </vm> <clone>true</clone> </action>
It's basically identical to what you offered in your example. Yet still, I run into this problem:
Traceback (most recent call last): File "./rhev-test.py", line 300, in <module> result = latest_image.import_vm(import_params) File "/usr/lib/python2.7/site-packages/ovirtsdk/infrastructure/brokers.py", line 18763, in import_vm headers={"Correlation-Id":correlation_id} File "/usr/lib/python2.7/site-packages/ovirtsdk/infrastructure/proxy.py", line 118, in request persistent_auth=self._persistent_auth) File "/usr/lib/python2.7/site-packages/ovirtsdk/infrastructure/proxy.py", line 146, in __doRequest persistent_auth=persistent_auth File "/usr/lib/python2.7/site-packages/ovirtsdk/web/connection.py", line 134, in doRequest raise RequestError, response ovirtsdk.infrastructure.errors.RequestError: status: 400 reason: Bad Request detail: Cannot import VM. Storage Domain type not specified.
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.
First test failed, same error message:
$ cat import-params.xml <action> <storage_domain id="27b5c6eb-ae68-4e85-930d-01bba13c07fc"/> <cluster id="00000001-0001-0001-0001-000000000159"/> <vm> <name>vm.example.com <http://vm.example.com></name> <snapshots> <collapse_snapshots>true</collapse_snapshots> </snapshots> </vm> <clone>true</clone> </action>
$ curl -X POST -H "Accept: application/xml" -H "Content-type: application/xml" -u tbielawa@redhat.com <mailto:tbielawa@redhat.com> --cacert /home/....crt -d @import-params.xml https://...:443/ovirt-engine/api/storagedomains/27b5c6eb-ae68-4e85-930d-01bb... Enter host password for user 'tbielawa@redhat.com <mailto:tbielawa@redhat.com>': <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <action> <storage_domain id="27b5c6eb-ae68-4e85-930d-01bba13c07fc"/> <cluster id="00000001-0001-0001-0001-000000000159"/> <vm> <name>vm.example.com <http://vm.example.com></name> <snapshots> <collapse_snapshots>true</collapse_snapshots> </snapshots> </vm> <clone>true</clone> <status> <state>failed</state> </status> <fault> <reason>Operation Failed</reason> <detail>[Cannot import VM. Storage Domain type not specified.]</detail> </fault> </action>
Second test with the <type> set failed as well:
$ cat import-params.xml <action> <storage_domain id="27b5c6eb-ae68-4e85-930d-01bba13c07fc"> <type>export</type> </storage_domain> <cluster id="00000001-0001-0001-0001-000000000159"/> <vm> <name>vm.example.com <http://vm.example.com></name> <snapshots> <collapse_snapshots>true</collapse_snapshots> </snapshots> </vm> <clone>true</clone> </action>
$ curl -X POST -H "Accept: application/xml" -H "Content-type: application/xml" -u tbielawa@redhat.com <mailto:tbielawa@redhat.com> --cacert /home/....crt -d @import-params.xml https://...:443/ovirt-engine/api/storagedomains/27b5c6eb-ae68-4e85-930d-01bb... Enter host password for user 'tbielawa@redhat.com <mailto:tbielawa@redhat.com>': <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <action> <storage_domain id="27b5c6eb-ae68-4e85-930d-01bba13c07fc"> <type>export</type> </storage_domain> <cluster id="00000001-0001-0001-0001-000000000159"/> <vm> <name>vm.example.com <http://vm.example.com></name> <snapshots> <collapse_snapshots>true</collapse_snapshots> </snapshots> </vm> <clone>true</clone> <status> <state>failed</state> </status> <fault> <reason>Operation Failed</reason> <detail>[Cannot import VM. Storage Domain type not specified.]</detail> </fault> </action>
I'm stumped. Any other ideas?
In these latest examples that you sent looks like you are using the storage domain with id 27b5c6eb-ae68-4e85-930d-01bba13c07fc as both the source and the target of the import. They need to be different. The source, the one that you specify in the URL, should be the export storage domain. The target, the one you specify in <storage_domain id="...">, should be the one you want to import the VM to. Try to change that, please. -- Dirección Comercial: C/Jose Bardasano Baos, 9, Edif. Gorbea 3, planta 3ºD, 28016 Madrid, Spain Inscrita en el Reg. Mercantil de Madrid – C.I.F. B82657941 - Red Hat S.L.

Beautiful!! Oh man, thanks so much. I never would have figured that out on my own. On Wed, Jan 13, 2016 at 12:28 PM, Juan Hernández <jhernand@redhat.com> wrote:
On 01/13/2016 05:54 PM, Tim Bielawa wrote:
On Wed, Jan 13, 2016 at 5:01 AM, Juan Hernández <jhernand@redhat.com <mailto:jhernand@redhat.com>> wrote:
On 01/12/2016 08:44 PM, Tim Bielawa wrote: > Hello virt folks, > > Background: > > I'm using the REST API to import a VM from an attached export
domain.
> The VM was imported using the virt-v2v tool. I've tried this with
cURL
> and with the python SDK, both yield the same error message. > > RHEVM Version: 3.5.6.0-1 > Python SDK Version: 3.5.6.0-1 > > According to the documentation, importing should follow this
syntax:
> >> POST >
/ovirt-engine/api/storagedomains/{storagedomain:id}/vms/{vm:id}/import
> > With a small <action> body attached. In theory (by the documentation and > bug tracker [1]) either of these XML documents (both in the same paste) > should work: > > http://fpaste.org/309944/52627148/ > > However, this fails with the following error message (full response in [2]) > >> Cannot import VM. Storage Domain type not specified. > > > Steps to reproduce: > > 1. Import a VM into an export storage domain > 2. Create an XML document with an action like this (filling in the > correct values for the ID variables) > > <action> > <cluster id="<CLUSTER_ID>"/> > <storage_domain id="<STORAGE_DOMAIN_ID>"> > <type>export</type> > </storage_domain> > <clone>True</clone> > <vm> > <name>IMPORTED_VM</name> > </vm> > </action> > > > 3. POST to the import location (again, substitute the correct ID > variables in the location) > >
/ovirt-engine/api/storagedomains/<STORAGE_DOMAIN_ID>/vms/<VM_ID>/import
> > > > Where is this storage domain type supposed to be defined, if not inside > of the storage_domain element as demonstrated in the documentation? > > I would appreciate any advice you can offer or pointers to useful > resources/documentation. > > Thanks! > > > [1] https://bugzilla.redhat.com/show_bug.cgi?id=1147011#c13 > [2] http://fpaste.org/309949/14526274/ > > -- > Tim Bielawa > 1BA0 4FAB 4C13 FBA0 A036 4958 AD05 E75E 0333 AE37 >
The bug that you are referring to (bug 1147011) isn't fixed in
version
3.5, and there are no plans to fix it, as far as I know. It will be fixed on only in 3.6. This means that you have to apply the
workaround
that Sven Kieske mentions in the description of the bug. So the XML document to send should look like this:
<action> <cluster id="00000001-0001-0001-0001-000000000001"/> <storage_domain id="00000001-0001-0001-0001-000000000002"/> <clone>true</clone> <vm> <name>TBIELAWA_IMPORTED_VM</name>
<!-- Note that this "snapshot" element is needed to avoid the bug, even if the VM doesn't have any snapshot. --> <snapshots> <collapse_snapshots>true</collapse_snapshots> </snapshots>
</vm> </action>
With the Python SDK should be something like this:
# Find the target cluster and storage domain: target_cluster_id = api.clusters.get(name="mycluster").get_id() target_sd_id = api.storagedomains.get(name="mydata").get_id()
# Find the export storage domain: export_sd = api.storagedomains.get(name="myexport")
# Find the VM: vm = export_sd.vms.get(name="myvm")
# Import the VM: vm.import_vm( params.Action( cluster=params.Cluster(id=target_cluster_id), storage_domain=params.StorageDomain(id=target_sd_id), clone=True, vm=params.VM( name="TBIELAWA_IMPORTED_VM", snapshots=params.Snapshots( collapse_snapshots=True ) ) ) )
-- Dirección Comercial: C/Jose Bardasano Baos, 9, Edif. Gorbea 3, planta 3ºD, 28016 Madrid, Spain Inscrita en el Reg. Mercantil de Madrid – C.I.F. B82657941 - Red Hat S.L.
Thanks for the tips Juan, I appreciate the response.
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.
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:
<action> <storage_domain id="27b5c6eb-ae68-4e85-930d-01bba13c07fc"/> <cluster id="00000001-0001-0001-0001-000000000159"/> <vm> <name>vm.example.com <http://vm.example.com></name> <snapshots> <collapse_snapshots>true</collapse_snapshots> </snapshots> </vm> <clone>true</clone> </action>
It's basically identical to what you offered in your example. Yet still, I run into this problem:
Traceback (most recent call last): File "./rhev-test.py", line 300, in <module> result = latest_image.import_vm(import_params) File
"/usr/lib/python2.7/site-packages/ovirtsdk/infrastructure/brokers.py",
line 18763, in import_vm headers={"Correlation-Id":correlation_id} File "/usr/lib/python2.7/site-packages/ovirtsdk/infrastructure/proxy.py", line 118, in request persistent_auth=self._persistent_auth) File "/usr/lib/python2.7/site-packages/ovirtsdk/infrastructure/proxy.py", line 146, in __doRequest persistent_auth=persistent_auth File "/usr/lib/python2.7/site-packages/ovirtsdk/web/connection.py", line 134, in doRequest raise RequestError, response ovirtsdk.infrastructure.errors.RequestError: status: 400 reason: Bad Request detail: Cannot import VM. Storage Domain type not specified.
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.
First test failed, same error message:
$ cat import-params.xml <action> <storage_domain id="27b5c6eb-ae68-4e85-930d-01bba13c07fc"/> <cluster id="00000001-0001-0001-0001-000000000159"/> <vm> <name>vm.example.com <http://vm.example.com></name> <snapshots> <collapse_snapshots>true</collapse_snapshots> </snapshots> </vm> <clone>true</clone> </action>
$ curl -X POST -H "Accept: application/xml" -H "Content-type: application/xml" -u tbielawa@redhat.com <mailto:tbielawa@redhat.com> --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
Enter host password for user 'tbielawa@redhat.com <mailto:tbielawa@redhat.com>': <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <action> <storage_domain id="27b5c6eb-ae68-4e85-930d-01bba13c07fc"/> <cluster id="00000001-0001-0001-0001-000000000159"/> <vm> <name>vm.example.com <http://vm.example.com></name> <snapshots> <collapse_snapshots>true</collapse_snapshots> </snapshots> </vm> <clone>true</clone> <status> <state>failed</state> </status> <fault> <reason>Operation Failed</reason> <detail>[Cannot import VM. Storage Domain type not specified.]</detail> </fault> </action>
Second test with the <type> set failed as well:
$ cat import-params.xml <action> <storage_domain id="27b5c6eb-ae68-4e85-930d-01bba13c07fc"> <type>export</type> </storage_domain> <cluster id="00000001-0001-0001-0001-000000000159"/> <vm> <name>vm.example.com <http://vm.example.com></name> <snapshots> <collapse_snapshots>true</collapse_snapshots> </snapshots> </vm> <clone>true</clone> </action>
$ curl -X POST -H "Accept: application/xml" -H "Content-type: application/xml" -u tbielawa@redhat.com <mailto:tbielawa@redhat.com> --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
Enter host password for user 'tbielawa@redhat.com <mailto:tbielawa@redhat.com>': <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <action> <storage_domain id="27b5c6eb-ae68-4e85-930d-01bba13c07fc"> <type>export</type> </storage_domain> <cluster id="00000001-0001-0001-0001-000000000159"/> <vm> <name>vm.example.com <http://vm.example.com></name> <snapshots> <collapse_snapshots>true</collapse_snapshots> </snapshots> </vm> <clone>true</clone> <status> <state>failed</state> </status> <fault> <reason>Operation Failed</reason> <detail>[Cannot import VM. Storage Domain type not specified.]</detail> </fault> </action>
I'm stumped. Any other ideas?
In these latest examples that you sent looks like you are using the storage domain with id 27b5c6eb-ae68-4e85-930d-01bba13c07fc as both the source and the target of the import. They need to be different. The source, the one that you specify in the URL, should be the export storage domain. The target, the one you specify in <storage_domain id="...">, should be the one you want to import the VM to. Try to change that, please.
-- Dirección Comercial: C/Jose Bardasano Baos, 9, Edif. Gorbea 3, planta 3ºD, 28016 Madrid, Spain Inscrita en el Reg. Mercantil de Madrid – C.I.F. B82657941 - Red Hat S.L.
-- Tim Bielawa, Sr. ${::title} Cell: 919.332.6411 | IRC: tbielawa (#platops) 1BA0 4FAB 4C13 FBA0 A036 4958 AD05 E75E 0333 AE37
participants (2)
-
Juan Hernández
-
Tim Bielawa