Java layer changes for adding customization spec
This commit is contained in:
Родитель
86b97cf42e
Коммит
b4d2a1a1cb
|
@ -20,6 +20,7 @@ public class Constants {
|
|||
public static final String CREATE_SNAPSHOT_ACTION = "create";
|
||||
public static final String VM_OPS_TOOL = "vmOpsTool-1.0.jar";
|
||||
public static final String DESCRIPTION = "-description";
|
||||
public static final String CUSTOMIZATIONSPEC = "-customizationspec";
|
||||
public static final String QUIESCE_VM_FS = "-quiesceVmFs";
|
||||
public static final String SAVE_VM_MEMORY = "-saveVmMemory";
|
||||
public static final String DELETE_SNAPSHOT_ACTION = "delete";
|
||||
|
|
|
@ -67,15 +67,16 @@ public interface IVMWare {
|
|||
boolean isVMPoweredOn(String vmName, boolean defaultValue, ConnectionData connData) throws Exception;
|
||||
|
||||
/**
|
||||
* @param templateName name of the virtual machine template to be cloned
|
||||
* @param vmName name of the virtual machine
|
||||
* @param computeType type of the compute esxi/cluster/resourcepool
|
||||
* @param computeName name of the compute resouce
|
||||
* @param description optional description for create operation
|
||||
* @param templateName name of the virtual machine template to be cloned
|
||||
* @param vmName name of the virtual machine
|
||||
* @param computeType type of the compute esxi/cluster/resourcepool
|
||||
* @param computeName name of the compute resouce
|
||||
* @param description optional description for create operation
|
||||
* @param customizationSpec name of the customization specification to be used during clone vm
|
||||
* @param connData connection information for vCenter
|
||||
* @throws Exception
|
||||
*/
|
||||
void cloneVMFromTemplate(String templateName, String vmName, String computeType, String computeName, String datastore, String description, ConnectionData connData) throws Exception;
|
||||
void cloneVMFromTemplate(String templateName, String vmName, String computeType, String computeName, String datastore, String customizationSpec, String description, ConnectionData connData) throws Exception;
|
||||
|
||||
/**
|
||||
* @param vmName name of the virtual machine
|
||||
|
|
|
@ -67,12 +67,13 @@ public class VMWareImpl implements IVMWare {
|
|||
}
|
||||
|
||||
public void cloneVMFromTemplate(String templateName, String vmName, String computeType,
|
||||
String computeName, String targetDS, String description, ConnectionData connData) throws Exception {
|
||||
String computeName, String targetDS, String customizationSpec,
|
||||
String description, ConnectionData connData) throws Exception {
|
||||
connect(connData);
|
||||
System.out.println(String.format("Finding template [ %s ] on vCenter server.", templateName));
|
||||
ManagedObjectReference templateMor = getMorByName(targetDCMor, templateName, VIRTUAL_MACHINE, true);
|
||||
ManagedObjectReference targetVmFolder = (ManagedObjectReference) getMorProperties(targetDCMor, new String[]{VM_FOLDER}).get(VM_FOLDER);
|
||||
VirtualMachineCloneSpec cloneSpec = getVirtualMachineCloneSpec(computeType, computeName, targetDS, description);
|
||||
VirtualMachineCloneSpec cloneSpec = getVirtualMachineCloneSpec(computeType, computeName, targetDS, customizationSpec, description);
|
||||
|
||||
System.out.println(String.format("Creating new virtual machine [ %s ] using template [ %s ].", vmName, templateName));
|
||||
ManagedObjectReference task = vimPort.cloneVMTask(templateMor, targetVmFolder, vmName, cloneSpec);
|
||||
|
@ -573,12 +574,21 @@ public class VMWareImpl implements IVMWare {
|
|||
}
|
||||
}
|
||||
|
||||
private VirtualMachineCloneSpec getVirtualMachineCloneSpec(String computeType, String computeName, String targetDS, String description) throws Exception {
|
||||
private VirtualMachineCloneSpec getVirtualMachineCloneSpec(String computeType, String computeName, String targetDS,
|
||||
String customizationSpec, String description) throws Exception {
|
||||
|
||||
VirtualMachineRelocateSpec relocSpec = getVirtualMachineRelocationSpec(computeType, computeName, targetDS);
|
||||
VirtualMachineConfigSpec configSpec = new VirtualMachineConfigSpec();
|
||||
configSpec.setAnnotation(description);
|
||||
VirtualMachineCloneSpec cloneSpec = new VirtualMachineCloneSpec();
|
||||
|
||||
if(!customizationSpec.isEmpty()){
|
||||
System.out.println(String.format("Fetching customization specification with name [ %s ].", customizationSpec));
|
||||
CustomizationSpecItem customizationSpecItem = vimPort.getCustomizationSpec(
|
||||
serviceContent.getCustomizationSpecManager(), customizationSpec);
|
||||
cloneSpec.setCustomization(customizationSpecItem.getSpec());
|
||||
}
|
||||
|
||||
cloneSpec.setConfig(configSpec);
|
||||
cloneSpec.setLocation(relocSpec);
|
||||
cloneSpec.setPowerOn(false);
|
||||
|
|
|
@ -179,10 +179,12 @@ public class VmOpsTool {
|
|||
String computeType = argsMap.get(Constants.COMPUTE_TYPE);
|
||||
String computeName = argsMap.get(Constants.COMPUTE_NAME);
|
||||
String datastore = argsMap.get(Constants.DATASTORE);
|
||||
String customizationspec = argsMap.get(Constants.CUSTOMIZATIONSPEC);
|
||||
String description = argsMap.get(Constants.DESCRIPTION);
|
||||
|
||||
try {
|
||||
vmwareFactory.call().cloneVMFromTemplate(templateName, vmName, computeType, computeName, datastore, description, connData);
|
||||
vmwareFactory.call().cloneVMFromTemplate(templateName, vmName, computeType, computeName, datastore,
|
||||
customizationspec, description, connData);
|
||||
} catch (Exception exp) {
|
||||
System.out.println(exp.getMessage() != null ? exp.getMessage() : "Unknown error occurred.");
|
||||
failedVm = vmName + " ";
|
||||
|
|
|
@ -165,7 +165,7 @@ public class InMemoryVMWareImpl implements IVMWare {
|
|||
}
|
||||
|
||||
public synchronized void cloneVMFromTemplate(String templateName, String vmName, String computeType, String computeName,
|
||||
String datastore, String description, ConnectionData connData) throws Exception {
|
||||
String datastore, String customizationSpec, String description, ConnectionData connData) throws Exception {
|
||||
if (vmName.equals("VMNameThatFailsInClone")) {
|
||||
throw new Exception("Clone VM from template operation failed for VMNameThatFailsInClone");
|
||||
}
|
||||
|
@ -186,7 +186,6 @@ public class InMemoryVMWareImpl implements IVMWare {
|
|||
throw new Exception("Invalid compute resource");
|
||||
}
|
||||
|
||||
|
||||
vmSnapshotInfo.put(vmName, new ArrayList<>());
|
||||
vmActiveSnapshot.put(vmName, "");
|
||||
}
|
||||
|
|
|
@ -10,7 +10,8 @@ public abstract class VMWarePlatformTests {
|
|||
private ConnectionData connData = new ConnectionData(vCenterUrl, vCenterUserName, vCenterPassword, defaultTargetDC, true);
|
||||
private IVMWare vmWareImpl = getVmWareImpl();
|
||||
private String snapshotOne = "Snapshot1";
|
||||
private String templateName = "Ubuntu";
|
||||
private String ubuntuTemplate = "Ubuntu";
|
||||
String linuxCustomizationSpec = "Linux Spec";
|
||||
private String snapshotTwo = "Snapshot2";
|
||||
|
||||
public abstract IVMWare getVmWareImpl();
|
||||
|
@ -35,7 +36,7 @@ public abstract class VMWarePlatformTests {
|
|||
String description = "Creating new VM from ubuntuVM template on ESXi host";
|
||||
connData.setTargetDC(targetDC);
|
||||
|
||||
vmWareImpl.cloneVMFromTemplate(templateName, newVmName, computeType, computeName, datastore, description, connData);
|
||||
vmWareImpl.cloneVMFromTemplate(ubuntuTemplate, newVmName, computeType, computeName, datastore, linuxCustomizationSpec, description, connData);
|
||||
|
||||
assertThat(vmWareImpl.isVMExists(newVmName, connData)).isEqualTo(true);
|
||||
|
||||
|
@ -54,7 +55,7 @@ public abstract class VMWarePlatformTests {
|
|||
String description = "Creating new VM from ubuntuVM template on cluster";
|
||||
connData.setTargetDC(targetDC);
|
||||
|
||||
vmWareImpl.cloneVMFromTemplate(templateName, newVmName, computeType, computeName, datastore, description, connData);
|
||||
vmWareImpl.cloneVMFromTemplate(ubuntuTemplate, newVmName, computeType, computeName, datastore, linuxCustomizationSpec, description, connData);
|
||||
|
||||
assertThat(vmWareImpl.isVMExists(newVmName, connData)).isEqualTo(true);
|
||||
|
||||
|
@ -73,7 +74,7 @@ public abstract class VMWarePlatformTests {
|
|||
String description = "Creating new VM from ubuntuVM template on resource pool";
|
||||
connData.setTargetDC(targetDC);
|
||||
|
||||
vmWareImpl.cloneVMFromTemplate(templateName, newVmName, computeType, computeName, datastore, description, connData);
|
||||
vmWareImpl.cloneVMFromTemplate(ubuntuTemplate, newVmName, computeType, computeName, datastore, linuxCustomizationSpec, description, connData);
|
||||
|
||||
assertThat(vmWareImpl.isVMExists(newVmName, connData)).isEqualTo(true);
|
||||
|
||||
|
@ -94,7 +95,7 @@ public abstract class VMWarePlatformTests {
|
|||
|
||||
Exception exp = null;
|
||||
try {
|
||||
vmWareImpl.cloneVMFromTemplate(templateName, newVmName, computeType, computeName, datastore, description, connData);
|
||||
vmWareImpl.cloneVMFromTemplate(ubuntuTemplate, newVmName, computeType, computeName, datastore, linuxCustomizationSpec, description, connData);
|
||||
} catch (Exception e) {
|
||||
exp = e;
|
||||
}
|
||||
|
@ -114,7 +115,7 @@ public abstract class VMWarePlatformTests {
|
|||
|
||||
Exception exp = null;
|
||||
try {
|
||||
vmWareImpl.cloneVMFromTemplate(nonExistingTemplate, newVmName, computeType, computeName, datastore, description, connData);
|
||||
vmWareImpl.cloneVMFromTemplate(nonExistingTemplate, newVmName, computeType, computeName, datastore, linuxCustomizationSpec, description, connData);
|
||||
} catch (Exception e) {
|
||||
exp = e;
|
||||
}
|
||||
|
@ -133,7 +134,7 @@ public abstract class VMWarePlatformTests {
|
|||
|
||||
Exception exp = null;
|
||||
try {
|
||||
vmWareImpl.cloneVMFromTemplate(templateName, newVmName, computeType, computeName, datastore, description, connData);
|
||||
vmWareImpl.cloneVMFromTemplate(ubuntuTemplate, newVmName, computeType, computeName, datastore, linuxCustomizationSpec, description, connData);
|
||||
} catch (Exception e) {
|
||||
exp = e;
|
||||
}
|
||||
|
@ -152,7 +153,7 @@ public abstract class VMWarePlatformTests {
|
|||
|
||||
Exception exp = null;
|
||||
try {
|
||||
vmWareImpl.cloneVMFromTemplate(templateName, newVmName, computeType, computeName, datastore, description, connData);
|
||||
vmWareImpl.cloneVMFromTemplate(ubuntuTemplate, newVmName, computeType, computeName, datastore, linuxCustomizationSpec, description, connData);
|
||||
} catch (Exception e) {
|
||||
exp = e;
|
||||
}
|
||||
|
@ -171,7 +172,7 @@ public abstract class VMWarePlatformTests {
|
|||
|
||||
Exception exp = null;
|
||||
try {
|
||||
vmWareImpl.cloneVMFromTemplate(templateName, newVmName, computeType, computeName, datastore, description, connData);
|
||||
vmWareImpl.cloneVMFromTemplate(ubuntuTemplate, newVmName, computeType, computeName, datastore, linuxCustomizationSpec, description, connData);
|
||||
} catch (Exception e) {
|
||||
exp = e;
|
||||
}
|
||||
|
@ -190,7 +191,7 @@ public abstract class VMWarePlatformTests {
|
|||
|
||||
Exception exp = null;
|
||||
try {
|
||||
vmWareImpl.cloneVMFromTemplate(templateName, newVmName, computeType, computeName, datastore, description, connData);
|
||||
vmWareImpl.cloneVMFromTemplate(ubuntuTemplate, newVmName, computeType, computeName, datastore, linuxCustomizationSpec, description, connData);
|
||||
} catch (Exception e) {
|
||||
exp = e;
|
||||
}
|
||||
|
|
|
@ -47,7 +47,8 @@ public class VmOpsToolUnitTests {
|
|||
@Test
|
||||
public void executeActionInParallelShouldSucceedForCloneAndDeleteVMActionWithValidInputs() throws Exception {
|
||||
String[] cmdArgs = getCmdArgs("newVM1, newVM2", Constants.CLONE_TEMPLATE, "dummyTemplate",
|
||||
Constants.COMPUTE_TYPE, "DummyCompute", Constants.COMPUTE_NAME, "DummyName", Constants.DESCRIPTION, "Dummy description");
|
||||
Constants.COMPUTE_TYPE, "DummyCompute", Constants.COMPUTE_NAME, "DummyName",
|
||||
Constants.CUSTOMIZATIONSPEC, "Dummy Customization Spec", Constants.DESCRIPTION, "Dummy description");
|
||||
|
||||
vmOpsTool.executeActionOnVmsInParallel(cmdArgs);
|
||||
|
||||
|
@ -140,7 +141,8 @@ public class VmOpsToolUnitTests {
|
|||
@Test
|
||||
public void executeActionInParallelShouldThrowForCloneAndDeleteVMFailureOnAVM() throws Exception {
|
||||
String[] cmdArgs = getCmdArgs("newVM1, VMNameThatFailsInClone", Constants.CLONE_TEMPLATE, "dummyTemplate",
|
||||
Constants.COMPUTE_TYPE, "DummyCompute", Constants.COMPUTE_NAME, "DummyName", Constants.DESCRIPTION, "Dummy description");
|
||||
Constants.COMPUTE_TYPE, "DummyCompute", Constants.COMPUTE_NAME, "DummyName",
|
||||
Constants.CUSTOMIZATIONSPEC, "Dummy Customization Spec", Constants.DESCRIPTION, "Dummy description");
|
||||
|
||||
Exception exp = null;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче