Index: src/main/java/org/jenkinsci/plugins/vSphereCloud.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/main/java/org/jenkinsci/plugins/vSphereCloud.java (revision 487bb7fb9ba573aeec5a5feb43d249164ce352d5)
+++ src/main/java/org/jenkinsci/plugins/vSphereCloud.java (revision 3ba76f8d0ebabaaafd5e498d0c3efc438ca030f1)
@@ -4,6 +4,7 @@
*/
package org.jenkinsci.plugins;
+import com.vmware.vim25.mo.InventoryNavigator;
import hudson.model.Hudson;
import org.jenkinsci.plugins.vsphere.VSphereConnectionConfig;
import hudson.Extension;
@@ -318,5 +319,7 @@
throw new RuntimeException(e);
}
}
+
+
}
}
Index: src/main/java/org/jenkinsci/plugins/vsphere/builders/Clone.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/main/java/org/jenkinsci/plugins/vsphere/builders/Clone.java (revision 487bb7fb9ba573aeec5a5feb43d249164ce352d5)
+++ src/main/java/org/jenkinsci/plugins/vsphere/builders/Clone.java (revision 3ba76f8d0ebabaaafd5e498d0c3efc438ca030f1)
@@ -41,18 +41,30 @@
private final String resourcePool;
private final String cluster;
private final String datastore;
+ private final String customizationSpec;
+ private final String ipAddress;
@DataBoundConstructor
public Clone(String sourceName, String clone, boolean linkedClone,
- String resourcePool, String cluster, String datastore) throws VSphereException {
+ String resourcePool, String cluster, String datastore, String customizationSpec, String ipAddress) throws VSphereException {
this.sourceName = sourceName;
this.clone = clone;
this.linkedClone = linkedClone;
this.resourcePool=resourcePool;
this.cluster=cluster;
this.datastore=datastore;
+ this.customizationSpec = customizationSpec;
+ this.ipAddress = ipAddress;
}
+ public String getCustomizationSpec() {
+ return customizationSpec;
+ }
+
+ public String getIpAddress() {
+ return ipAddress;
+ }
+
public String getSourceName() {
return sourceName;
}
@@ -96,10 +108,10 @@
String expandedClone = env.expand(clone), expandedSource = env.expand(sourceName),
expandedCluster = env.expand(cluster), expandedDatastore = env.expand(datastore),
- expandedResourcePool = env.expand(resourcePool);
+ expandedResourcePool = env.expand(resourcePool), expandedCustomizationSpec=env.expand(customizationSpec), expandedIpAddress=env.expand(ipAddress);
vsphere.cloneVm(expandedClone, expandedSource, linkedClone, expandedResourcePool, expandedCluster,
- expandedDatastore, jLogger);
+ expandedDatastore, expandedCustomizationSpec,expandedIpAddress,jLogger);
VSphereLogger.vsLogger(jLogger, "\""+expandedClone+"\" successfully cloned!");
return true;
@@ -145,16 +157,32 @@
return FormValidation.ok();
}
+ public FormValidation doCheckCustomizationSpec(@QueryParameter String value)
+ throws IOException, ServletException {
+ return FormValidation.ok();
+ }
+
+ public FormValidation doCheckIpAddress(@QueryParameter String value)
+ throws IOException, ServletException {
+ return FormValidation.ok();
+ }
+
+
public FormValidation doTestData(@QueryParameter String serverName,
@QueryParameter String sourceName, @QueryParameter String clone,
- @QueryParameter String resourcePool, @QueryParameter String cluster) {
+ @QueryParameter String resourcePool, @QueryParameter String cluster,
+ @QueryParameter String customizationSpec, @QueryParameter String ipAddress) {
try {
if (sourceName.length() == 0 || clone.length()==0 || serverName.length()==0
||resourcePool.length()==0 || cluster.length()==0 )
return FormValidation.error(Messages.validation_requiredValues());
-
+ if(ipAddress.length()>0 && customizationSpec.length()==0){
+ return FormValidation.error(Messages.validation_noSpecForIpAddress());
+ }
VSphere vsphere = getVSphereCloudByName(serverName).vSphereInstance();
-
+ if(customizationSpec.length()>0 && vsphere.getCustomizationSpecByName(customizationSpec) == null){
+ return FormValidation.error(Messages.validation_notFound("customizationSpec"));
+ }
//TODO what if clone name is variable?
VirtualMachine cloneVM = vsphere.getVmByName(clone);
if (cloneVM != null)
Index: src/main/java/org/jenkinsci/plugins/vsphere/builders/Deploy.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/main/java/org/jenkinsci/plugins/vsphere/builders/Deploy.java (revision 487bb7fb9ba573aeec5a5feb43d249164ce352d5)
+++ src/main/java/org/jenkinsci/plugins/vsphere/builders/Deploy.java (revision 3ba76f8d0ebabaaafd5e498d0c3efc438ca030f1)
@@ -44,18 +44,30 @@
private final String resourcePool;
private final String cluster;
private final String datastore;
+ private final String customizationSpec;
+ private final String ipAddress;
@DataBoundConstructor
public Deploy(String template, String clone, boolean linkedClone,
- String resourcePool, String cluster, String datastore) throws VSphereException {
+ String resourcePool, String cluster, String datastore, String customizationSpec, String ipAddress) throws VSphereException {
this.template = template;
this.clone = clone;
this.linkedClone = linkedClone;
this.resourcePool=resourcePool;
this.cluster=cluster;
this.datastore=datastore;
+ this.customizationSpec = customizationSpec;
+ this.ipAddress = ipAddress;
}
+ public String getCustomizationSpec() {
+ return customizationSpec;
+ }
+
+ public String getIpAddress() {
+ return ipAddress;
+ }
+
public String getTemplate() {
return template;
}
@@ -97,7 +109,8 @@
env.overrideAll(build.getBuildVariables()); // Add in matrix axes..
String expandedClone = env.expand(clone), expandedTemplate = env.expand(template),
- expandedCluster = env.expand(cluster), expandedDatastore = env.expand(datastore);
+ expandedCluster = env.expand(cluster), expandedDatastore = env.expand(datastore),
+ expandedCustomizationSpec=env.expand(customizationSpec), expandedIpAddress=env.expand(ipAddress);
String resourcePoolName;
if (resourcePool.length() == 0) {
@@ -108,7 +121,7 @@
resourcePoolName = env.expand(resourcePool);
}
- vsphere.deployVm(expandedClone, expandedTemplate, linkedClone, resourcePoolName, expandedCluster, expandedDatastore, jLogger);
+ vsphere.deployVm(expandedClone, expandedTemplate, linkedClone, resourcePoolName, expandedCluster, expandedDatastore, expandedCustomizationSpec,expandedIpAddress,jLogger);
VSphereLogger.vsLogger(jLogger, "\""+expandedClone+"\" successfully deployed!");
return true;
@@ -152,16 +165,33 @@
return FormValidation.ok();
}
+ public FormValidation doCheckCustomizationSpec(@QueryParameter String value)
+ throws IOException, ServletException {
+ return FormValidation.ok();
+ }
+
+ public FormValidation doCheckIpAddress(@QueryParameter String value)
+ throws IOException, ServletException {
+ return FormValidation.ok();
+ }
+
public FormValidation doTestData(@QueryParameter String serverName,
@QueryParameter String template, @QueryParameter String clone,
- @QueryParameter String resourcePool, @QueryParameter String cluster) {
+ @QueryParameter String resourcePool, @QueryParameter String cluster,
+ @QueryParameter String customizationSpec, @QueryParameter String ipAddress) {
try {
if (template.length() == 0 || clone.length()==0 || serverName.length()==0
|| cluster.length()==0 )
return FormValidation.error(Messages.validation_requiredValues());
+ if(ipAddress.length()>0 && customizationSpec.length()==0){
+ return FormValidation.error(Messages.validation_noSpecForIpAddress());
+ }
VSphere vsphere = getVSphereCloudByName(serverName).vSphereInstance();
+ if(customizationSpec.length()>0 && vsphere.getCustomizationSpecByName(customizationSpec) == null){
+ return FormValidation.error(Messages.validation_notFound("customizationSpec"));
+ }
//TODO what if clone name is variable?
VirtualMachine cloneVM = vsphere.getVmByName(clone);
if (cloneVM != null)
Index: src/main/java/org/jenkinsci/plugins/vsphere/tools/VSphere.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/main/java/org/jenkinsci/plugins/vsphere/tools/VSphere.java (revision 487bb7fb9ba573aeec5a5feb43d249164ce352d5)
+++ src/main/java/org/jenkinsci/plugins/vsphere/tools/VSphere.java (revision 3ba76f8d0ebabaaafd5e498d0c3efc438ca030f1)
@@ -14,35 +14,8 @@
*/
package org.jenkinsci.plugins.vsphere.tools;
-import com.vmware.vim25.FileFault;
-import com.vmware.vim25.GuestInfo;
-import com.vmware.vim25.InvalidName;
-import com.vmware.vim25.InvalidProperty;
-import com.vmware.vim25.InvalidState;
-import com.vmware.vim25.ManagedObjectReference;
-import com.vmware.vim25.RuntimeFault;
-import com.vmware.vim25.SnapshotFault;
-import com.vmware.vim25.TaskInProgress;
-import com.vmware.vim25.TaskInfoState;
-import com.vmware.vim25.VirtualMachineCloneSpec;
-import com.vmware.vim25.VirtualMachineConfigSpec;
-import com.vmware.vim25.VirtualMachinePowerState;
-import com.vmware.vim25.VirtualMachineQuestionInfo;
-import com.vmware.vim25.VirtualMachineRelocateSpec;
-import com.vmware.vim25.VirtualMachineSnapshotInfo;
-import com.vmware.vim25.VirtualMachineSnapshotTree;
-import com.vmware.vim25.VirtualMachineToolsStatus;
-import com.vmware.vim25.VmConfigFault;
-import com.vmware.vim25.mo.ClusterComputeResource;
-import com.vmware.vim25.mo.Datastore;
-import com.vmware.vim25.mo.Folder;
-import com.vmware.vim25.mo.InventoryNavigator;
-import com.vmware.vim25.mo.ManagedEntity;
-import com.vmware.vim25.mo.ResourcePool;
-import com.vmware.vim25.mo.ServiceInstance;
-import com.vmware.vim25.mo.Task;
-import com.vmware.vim25.mo.VirtualMachine;
-import com.vmware.vim25.mo.VirtualMachineSnapshot;
+import com.vmware.vim25.*;
+import com.vmware.vim25.mo.*;
import org.apache.commons.lang.StringUtils;
@@ -57,13 +30,16 @@
public class VSphere {
private final URL url;
private final String session;
+ private final ServerConnection connection;
private VSphere(@Nonnull String url, @Nonnull String user, @CheckForNull String pw) throws VSphereException{
try {
//TODO - change ignoreCert to be configurable
this.url = new URL(url);
- this.session = (new ServiceInstance(this.url, user, pw, true)).getServerConnection().getSessionStr();
+ this.connection = (new ServiceInstance(this.url, user, pw, true)).getServerConnection();
+ this.session = connection.getSessionStr();
+
} catch (Exception e) {
throw new VSphereException(e);
}
@@ -106,14 +82,20 @@
* @param resourcePoolName - resource pool to use
* @param cluster - ComputeClusterResource to use
* @param datastoreName - Datastore to use
- * @throws VSphereException
+ * @param expandedCustomizationSpec
+ *@param expandedIpAddress @throws VSphereException
*/
- public void deployVm(String cloneName, String sourceName, boolean linkedClone, String resourcePoolName, String cluster, String datastoreName, PrintStream jLogger) throws VSphereException {
+ public void deployVm(String cloneName, String sourceName, boolean linkedClone, String resourcePoolName, String cluster, String datastoreName, String expandedCustomizationSpec, String expandedIpAddress, PrintStream jLogger) throws VSphereException {
boolean DO_NOT_USE_SNAPSHOTS = false;
logMessage(jLogger, "Deploying new vm \""+ cloneName + "\" from template \""+sourceName+"\"");
- cloneOrDeployVm(cloneName, sourceName, linkedClone, resourcePoolName, cluster, datastoreName, DO_NOT_USE_SNAPSHOTS, jLogger);
+ cloneOrDeployVm(cloneName, sourceName, linkedClone, resourcePoolName, cluster, datastoreName, DO_NOT_USE_SNAPSHOTS, expandedCustomizationSpec,expandedIpAddress,jLogger);
}
+ public CustomizationSpecItem getCustomizationSpecByName(String name) throws RemoteException {
+ CustomizationSpecManager mgr = new CustomizationSpecManager(this.connection, connection.getServiceInstance().getServiceContent().customizationSpecManager);
+ return mgr.getCustomizationSpec(name);
+ }
+
/**
* Clones a new VM from a given vm or template with a given name.
*
@@ -123,15 +105,16 @@
* @param resourcePoolName - resource pool to use
* @param cluster - ComputeClusterResource to use
* @param datastoreName - Datastore to use
- * @throws VSphereException
+ * @param expandedCustomizationSpec
+ *@param expandedIpAddress @throws VSphereException
*/
- public void cloneVm(String cloneName, String sourceName, boolean linkedClone, String resourcePoolName, String cluster, String datastoreName, PrintStream jLogger) throws VSphereException {
+ public void cloneVm(String cloneName, String sourceName, boolean linkedClone, String resourcePoolName, String cluster, String datastoreName, String expandedCustomizationSpec, String expandedIpAddress, PrintStream jLogger) throws VSphereException {
boolean DO_USE_SNAPSHOTS = true;
logMessage(jLogger, "Creating a shallow clone of \""+ sourceName + "\" to \""+cloneName+"\"");
- cloneOrDeployVm(cloneName, sourceName, linkedClone, resourcePoolName, cluster, datastoreName, DO_USE_SNAPSHOTS, jLogger);
+ cloneOrDeployVm(cloneName, sourceName, linkedClone, resourcePoolName, cluster, datastoreName, DO_USE_SNAPSHOTS, expandedCustomizationSpec, expandedIpAddress, jLogger);
}
- private void cloneOrDeployVm(String cloneName, String sourceName, boolean linkedClone, String resourcePoolName, String cluster, String datastoreName, boolean useSnapshot, PrintStream jLogger) throws VSphereException {
+ private void cloneOrDeployVm(String cloneName, String sourceName, boolean linkedClone, String resourcePoolName, String cluster, String datastoreName, boolean useSnapshot, String expandedCustomizationSpec, String expandedIpAddress, PrintStream jLogger) throws VSphereException {
try{
VirtualMachine sourceVm = getVmByName(sourceName);
@@ -147,6 +130,21 @@
VirtualMachineCloneSpec cloneSpec = createCloneSpec(rel);
cloneSpec.setTemplate(false);
+ if(expandedCustomizationSpec != null && expandedCustomizationSpec.length()>0){
+ CustomizationSpecItem spec = getCustomizationSpecByName(expandedCustomizationSpec);
+ if(expandedIpAddress != null && expandedIpAddress.length()>0){
+ CustomizationAdapterMapping[] nic = spec.getSpec().getNicSettingMap();
+ for (int i = 0; i < nic.length; i++) {
+ CustomizationAdapterMapping customizationAdapterMapping = nic[i];
+ CustomizationIPSettings adapter = customizationAdapterMapping.getAdapter();
+ CustomizationFixedIp fixedIp = new CustomizationFixedIp();
+ fixedIp.setIpAddress(expandedIpAddress);
+ adapter.setIp(fixedIp);
+ }
+ }
+ cloneSpec.setCustomization(spec.getSpec());
+ }
+
if (useSnapshot) {
//TODO add config to allow state of VM or snapshot
Index: src/main/resources/org/jenkinsci/plugins/vsphere/builders/Clone/config.jelly
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/main/resources/org/jenkinsci/plugins/vsphere/builders/Clone/config.jelly (revision 487bb7fb9ba573aeec5a5feb43d249164ce352d5)
+++ src/main/resources/org/jenkinsci/plugins/vsphere/builders/Clone/config.jelly (revision 3ba76f8d0ebabaaafd5e498d0c3efc438ca030f1)
@@ -38,6 +38,14 @@