use of com.vmware.vim25.VirtualMachineCloneSpec in project CloudStack-archive by CloudStack-extras.
the class VirtualMachineMO method createFullClone.
public boolean createFullClone(String cloneName, ManagedObjectReference morFolder, ManagedObjectReference morResourcePool, ManagedObjectReference morDs) throws Exception {
VirtualMachineCloneSpec cloneSpec = new VirtualMachineCloneSpec();
VirtualMachineRelocateSpec relocSpec = new VirtualMachineRelocateSpec();
cloneSpec.setLocation(relocSpec);
cloneSpec.setPowerOn(false);
cloneSpec.setTemplate(false);
relocSpec.setDatastore(morDs);
relocSpec.setPool(morResourcePool);
ManagedObjectReference morTask = _context.getService().cloneVM_Task(_mor, morFolder, cloneName, cloneSpec);
String result = _context.getServiceUtil().waitForTask(morTask);
if (result.equals("sucess")) {
_context.waitForTaskProgressDone(morTask);
return true;
} else {
s_logger.error("VMware cloneVM_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
return false;
}
use of com.vmware.vim25.VirtualMachineCloneSpec in project cloudstack by apache.
the class VirtualMachineMO method createFullClone.
public boolean createFullClone(String cloneName, ManagedObjectReference morFolder, ManagedObjectReference morResourcePool, ManagedObjectReference morDs) throws Exception {
VirtualMachineCloneSpec cloneSpec = new VirtualMachineCloneSpec();
VirtualMachineRelocateSpec relocSpec = new VirtualMachineRelocateSpec();
cloneSpec.setLocation(relocSpec);
cloneSpec.setPowerOn(false);
cloneSpec.setTemplate(false);
relocSpec.setDatastore(morDs);
relocSpec.setPool(morResourcePool);
ManagedObjectReference morTask = _context.getService().cloneVMTask(_mor, morFolder, cloneName, cloneSpec);
boolean result = _context.getVimClient().waitForTask(morTask);
if (result) {
_context.waitForTaskProgressDone(morTask);
return true;
} else {
s_logger.error("VMware cloneVM_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
return false;
}
use of com.vmware.vim25.VirtualMachineCloneSpec in project cloudstack by apache.
the class VirtualMachineMO method createFullCloneWithSpecificDisk.
public VirtualMachineMO createFullCloneWithSpecificDisk(String cloneName, ManagedObjectReference morFolder, ManagedObjectReference morResourcePool, VirtualDisk requiredDisk) throws Exception {
assert (morFolder != null);
assert (morResourcePool != null);
VirtualMachineRuntimeInfo runtimeInfo = getRuntimeInfo();
HostMO hostMo = new HostMO(_context, runtimeInfo.getHost());
DatacenterMO dcMo = new DatacenterMO(_context, hostMo.getHyperHostDatacenter());
DatastoreMO dsMo = new DatastoreMO(_context, morResourcePool);
VirtualMachineRelocateSpec rSpec = new VirtualMachineRelocateSpec();
VirtualDisk[] vmDisks = getAllDiskDevice();
VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
s_logger.debug(String.format("Removing the disks other than the required disk with key %s to the cloned VM", requiredDisk.getKey()));
for (VirtualDisk disk : vmDisks) {
s_logger.debug(String.format("Original disk with key %s found in the VM %s", disk.getKey(), getName()));
if (requiredDisk.getKey() != disk.getKey()) {
VirtualDeviceConfigSpec virtualDeviceConfigSpec = new VirtualDeviceConfigSpec();
virtualDeviceConfigSpec.setDevice(disk);
virtualDeviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.REMOVE);
vmConfigSpec.getDeviceChange().add(virtualDeviceConfigSpec);
}
}
rSpec.setPool(morResourcePool);
VirtualMachineCloneSpec cloneSpec = new VirtualMachineCloneSpec();
cloneSpec.setPowerOn(false);
cloneSpec.setTemplate(false);
cloneSpec.setLocation(rSpec);
cloneSpec.setMemory(false);
cloneSpec.setConfig(vmConfigSpec);
ManagedObjectReference morTask = _context.getService().cloneVMTask(_mor, morFolder, cloneName, cloneSpec);
boolean result = _context.getVimClient().waitForTask(morTask);
if (result) {
_context.waitForTaskProgressDone(morTask);
VirtualMachineMO clonedVm = dcMo.findVm(cloneName);
if (clonedVm == null) {
s_logger.error(String.format("Failed to clone VM %s", cloneName));
return null;
}
s_logger.debug(String.format("Cloned VM: %s as %s", getName(), cloneName));
clonedVm.tagAsWorkerVM();
makeSureVMHasOnlyRequiredDisk(clonedVm, requiredDisk, dsMo, dcMo);
return clonedVm;
} else {
s_logger.error("VMware cloneVM_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
return null;
}
}
use of com.vmware.vim25.VirtualMachineCloneSpec in project cloudstack by apache.
the class VirtualMachineMO method createFullClone.
public boolean createFullClone(String cloneName, ManagedObjectReference morFolder, ManagedObjectReference morResourcePool, ManagedObjectReference morDs, Storage.ProvisioningType diskProvisioningType) throws Exception {
VirtualMachineCloneSpec cloneSpec = new VirtualMachineCloneSpec();
VirtualMachineRelocateSpec relocSpec = new VirtualMachineRelocateSpec();
cloneSpec.setLocation(relocSpec);
cloneSpec.setPowerOn(false);
cloneSpec.setTemplate(false);
relocSpec.setDatastore(morDs);
relocSpec.setPool(morResourcePool);
setDiskProvisioningType(relocSpec, morDs, diskProvisioningType);
ManagedObjectReference morTask = _context.getService().cloneVMTask(_mor, morFolder, cloneName, cloneSpec);
boolean result = _context.getVimClient().waitForTask(morTask);
if (result) {
_context.waitForTaskProgressDone(morTask);
return true;
} else {
s_logger.error("VMware cloneVM_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
return false;
}
use of com.vmware.vim25.VirtualMachineCloneSpec 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