[ovirt-users] JavaAPI exporting VM
Juan Hernández
jhernand at redhat.com
Fri Apr 7 15:29:54 UTC 2017
On 04/07/2017 03:04 PM, David David wrote:
> Hello.
>
> Can't reexport a VM if this VM is already present in the export domain
>
> With Java api:
>
> *VM vm = api.getVMs().get("vm01");
>
> StorageDomain exportDomain = api.getStorageDomains().get("export"); *
>
> *Action act = vm.exportVm(new Action() {
> {
> setExclusive(True);
> setDiscardSnapshots(True);
> setStorageDomain(exportDomain);
> }
> });*
>
> And following error is returned:
>
> Exception in thread "main"
> code : 409
> reason: Conflict
> detail: Cannot export VM. VM with the same identifier already exists.
> at org.ovirt.engine.sdk.web.HttpProxy.execute(HttpProxy.java:120)
> at
> org.ovirt.engine.sdk.web.HttpProxyBroker.add(HttpProxyBroker.java:209)
> at
> org.ovirt.engine.sdk.web.HttpProxyBroker.action(HttpProxyBroker.java:153)
> at org.ovirt.engine.sdk.decorators.VM.exportVm(VM.java:784)
>
That should have worked. What version of the SDK and what version of the
engine are you using? Can you run the example with debug model enabled
and share the debug output?
Also, are you completely sure you actual compiled and run that versoin
of the code? I ask because it uses "True" instead of "true", which
should fail to compile.
I see that you are using version 3.6 of the Java SDK. That version of
the SDK and the version of the API it uses (version 3) are deprecated
since version 4 of the engine. Please consider using version 4 of the
SDK instead. With version 4 of the SDK you can do that as follows:
---8<---
package org.ovirt.engine.sdk4.examples;
import static org.ovirt.engine.sdk4.ConnectionBuilder.connection;
import static org.ovirt.engine.sdk4.builders.Builders.storageDomain;
import org.ovirt.engine.sdk4.Connection;
import org.ovirt.engine.sdk4.services.SystemService;
import org.ovirt.engine.sdk4.services.VmService;
import org.ovirt.engine.sdk4.services.VmsService;
import org.ovirt.engine.sdk4.types.Vm;
// This example shows how to export a virtual machine.
public class ExportVm {
public static void main(String[] args) throws Exception {
// Create the connection to the server:
Connection connection = connection()
.url("https://engine40.local/ovirt-engine/api")
.user("admin at internal")
.password("redhat123")
//.trustStoreFile("truststore.jks")
.insecure(true)
.build();
// Get the reference to the root of the services tree:
SystemService systemService = connection.systemService();
// Find the virtual machine:
VmsService vmsService = systemService.vmsService();
Vm vm = vmsService.list()
.search("name=myvm")
.send()
.vms()
.get(0);
// Export the virtual machine:
VmService vmService = vmsService.vmService(vm.id());
vmService.export()
.exclusive(true)
.discardSnapshots(true)
.storageDomain(
storageDomain()
.name("myexport")
)
.send();
// Close the connection to the server:
connection.close();
}
}
--->8---
The documentation of version 4 of the SDK is available here:
https://github.com/oVirt/ovirt-engine-sdk-java/tree/master/sdk
https://github.com/oVirt/ovirt-engine-sdk-java/tree/master/sdk/src/test/java/org/ovirt/engine/sdk4/examples
http://www.javadoc.io/doc/org.ovirt.engine.api/sdk/4.1.3
More information about the Users
mailing list