----- Original Message -----
From: "Tejesh M" <tejeshmk(a)gmail.com>
To: "Moti Asayag" <masayag(a)redhat.com>, "users(a)oVirt.org"
<users(a)ovirt.org>
Sent: Wednesday, March 19, 2014 1:38:52 PM
Subject: [Users] Clone from Snapshot
Hi,
I'm trying to clone a VM from snapshot with the below code. but it is not
cloning..
org.ovirt.engine.sdk.decorators.VM vm2 = api.getVMs().get("testVM");
VM cloneVM = new VM();
cloneVM.setName("MyClonedViaAPI");
VMSnapshot snap3 = new VMSnapshot(null);
snap3 =
vm2.getSnapshots().get(UUID.fromString("7799ce3f-a007-415a-84c5-df323e8f440d"));
Action act = new Action();
act.setClone(true);
act.setVm(cloneVM);
snap3.restore(act);
Actually, my original goal is to Clone VM directly from another VM instead of
cloning from snapshot.
Can you help me?
Just pasting here code given by Juan H for Java SDK to perform that :
You will need something like this:
// Find the original VM:
VM vm = api.getVMs().get("myvm");
// Find the cluster where the cloned VM will be created:
Cluster cluster = vm.getCluster();
// Populate the parameters to create the snapshot:
Snapshot snapshot = new Snapshot();
snapshot.setDescription("My snapshot");
// Send the request to create the snapshot. Note that you need the
// returned snapshot object in order to have the id assigned to
// that snapshot by the system.
snapshot = vm.getSnapshots().add(snapshot);
String id = snapshot.getId();
UUID uuid = UUID.fromString(id);
// Wait till the snapshot creation is completed:
for ( {
snapshot = vm.getSnapshots().get(uuid);
if (!"locked".equals(snapshot.getSnapshotStatus())) {
break;
}
Thread.sleep(1 * 1000);
}
// Populate the parameters to create the cloned VM:
VM clone = new VM(null);
clone.setName("myclone");
clone.setCluster(cluster);
Snapshots snapsshots = new Snapshots();
snapsshots.getSnapshots().add(snapshot);
clone.setSnapshots(snapsshots);
// Send the request to create the cloned VM:
api.getVMs().add(clone);
--
Thanks & Regards
Tejesh
_______________________________________________
Users mailing list
Users(a)ovirt.org
http://lists.ovirt.org/mailman/listinfo/users