use of com.vmware.vim25.DuplicateName in project photon-model by vmware.
the class VimUtilsTest method convertToFault.
@Test
public void convertToFault() {
DuplicateName fault = new DuplicateName();
String msg = "msg";
Exception e = new DuplicateNameFaultMsg(msg, fault);
LocalizedMethodFault lmf = VimUtils.convertExceptionToFault(e);
assertSame(fault, lmf.getFault());
assertSame(msg, lmf.getLocalizedMessage());
}
use of com.vmware.vim25.DuplicateName in project photon-model by vmware.
the class VimUtilsTest method retrhowKnownException.
@Test
public void retrhowKnownException() {
DuplicateName dn = new DuplicateName();
LocalizedMethodFault lmf = new LocalizedMethodFault();
lmf.setLocalizedMessage("msg");
lmf.setFault(dn);
try {
VimUtils.rethrow(lmf);
fail();
} catch (DuplicateNameFaultMsg msg) {
assertSame(dn, msg.getFaultInfo());
assertSame(lmf.getLocalizedMessage(), msg.getMessage());
} catch (Exception e) {
fail();
}
}
use of com.vmware.vim25.DuplicateName in project photon-model by vmware.
the class InstanceClient method replicateVMTemplate.
private ManagedObjectReference replicateVMTemplate(ManagedObjectReference resourcePool, ManagedObjectReference datastore, List<VirtualMachineDefinedProfileSpec> pbmSpec, ManagedObjectReference vmFolder, String vmName, ManagedObjectReference vm, GetMoRef get) throws Exception {
logger.info("Template lives on a different datastore, looking for a local copy of: {}.", vmName);
String replicatedName = vmName;
if (datastore != null) {
replicatedName = replicatedName + "_" + datastore.getValue();
}
ManagedObjectReference repVm = findTemplateByName(replicatedName, get);
if (repVm != null) {
return repVm;
}
logger.info("Replicating {} ({}) to {}", vmName, vm.getValue(), replicatedName);
Lock lock = getLock(replicatedName);
lock.lock();
try {
VirtualMachineRelocateSpec spec = new VirtualMachineRelocateSpec();
spec.setPool(resourcePool);
if (datastore != null) {
spec.setDatastore(datastore);
}
if (pbmSpec != null) {
pbmSpec.stream().forEach(sp -> {
spec.getProfile().add(sp);
});
}
spec.setFolder(vmFolder);
spec.setDiskMoveType(VirtualMachineRelocateDiskMoveOptions.MOVE_ALL_DISK_BACKINGS_AND_DISALLOW_SHARING.value());
VirtualMachineCloneSpec cloneSpec = new VirtualMachineCloneSpec();
cloneSpec.setLocation(spec);
cloneSpec.setTemplate(false);
cloneSpec.setPowerOn(false);
ManagedObjectReference cloneTask = getVimPort().cloneVMTask(vm, vmFolder, replicatedName, cloneSpec);
TaskInfo info = VimUtils.waitTaskEnd(this.connection, cloneTask);
if (info.getState() == TaskInfoState.ERROR) {
MethodFault fault = info.getError().getFault();
if (fault instanceof DuplicateName) {
logger.info("Template is being replicated by another thread, waiting for {} to be ready", replicatedName);
return awaitVM(replicatedName, vmFolder, get);
} else {
return VimUtils.rethrow(info.getError());
}
}
ManagedObjectReference rvm = (ManagedObjectReference) info.getResult();
logger.info("Replicated {} ({}) to {} ({})", vmName, vm.getValue(), replicatedName, rvm.getValue());
logger.info("Creating initial snapshot for linked clones on {}", rvm.getValue());
ManagedObjectReference snapshotTask = getVimPort().createSnapshotTask(rvm, "initial", null, false, false);
VimUtils.waitTaskEnd(this.connection, snapshotTask);
logger.info("Created initial snapshot for linked clones on {}", rvm.getValue());
return rvm;
} finally {
lock.unlock();
}
}
Aggregations