private IMachine cloneMachine(CloneSpec cloneSpec) {
VmSpec vmSpec = cloneSpec.getVmSpec();
NetworkSpec networkSpec = cloneSpec.getNetworkSpec();
boolean isLinkedClone = cloneSpec.isLinked();
IMachine master = cloneSpec.getMaster();
String flags = "";
List<String> groups = ImmutableList.of();
String group = "";
String settingsFile = manager.get().getVBox().composeMachineFilename(vmSpec.getVmName(), group , flags , workingDir);
IMachine clonedMachine = manager
.get()
.getVBox()
.createMachine(settingsFile, vmSpec.getVmName(), groups, vmSpec.getOsTypeId(), flags);
List<CloneOptions> options = Lists.newArrayList();
if (isLinkedClone)
options.add(CloneOptions.Link);
ISnapshot currentSnapshot = new TakeSnapshotIfNotAlreadyAttached(manager,
"snapshotName", "snapshotDesc", logger).apply(master);
IProgress progress = currentSnapshot.getMachine().cloneTo(clonedMachine,
CloneMode.MachineState, options);
progress.waitForCompletion(-1);
// memory may not be the same as the master vm
clonedMachine.setMemorySize(cloneSpec.getVmSpec().getMemory());
// registering
manager.get().getVBox().registerMachine(clonedMachine);
// Networking
for (NetworkInterfaceCard networkInterfaceCard : networkSpec.getNetworkInterfaceCards()) {
new AttachNicToMachine(vmSpec.getVmName(), machineUtils).apply(networkInterfaceCard);
}
// set only once the creds for this machine, same coming from its master
logger.debug("<< storing guest credentials on vm(%s) as extra data", clonedMachine.getName());
String masterUsername = master.getExtraData(GUEST_OS_USER);
String masterPassword = master.getExtraData(GUEST_OS_PASSWORD);
clonedMachine.setExtraData(GUEST_OS_USER, masterUsername);
clonedMachine.setExtraData(GUEST_OS_PASSWORD, masterPassword);
return clonedMachine;
}