Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions src/main/java/org/jenkinsci/plugins/vsphere/builders/Clone.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

public class Clone extends VSphereBuildStep {

private final int TIMEOUT_DEFAULT = 60;
private static final int TIMEOUT_DEFAULT = 60;

private final String sourceName;
private final String clone;
Expand All @@ -52,7 +52,8 @@ public class Clone extends VSphereBuildStep {
private final String folder;
private final String customizationSpec;
private final boolean powerOn;
private final int timeoutInSeconds;
/** null means use default, zero or negative means don't even try at all. */
private final Integer timeoutInSeconds;
private String IP;

@DataBoundConstructor
Expand All @@ -68,12 +69,7 @@ public Clone(String sourceName, String clone, boolean linkedClone,
this.folder=folder;
this.customizationSpec=customizationSpec;
this.powerOn=powerOn;
if (timeoutInSeconds != null) {
this.timeoutInSeconds = timeoutInSeconds;
}
else {
this.timeoutInSeconds = TIMEOUT_DEFAULT;
}
this.timeoutInSeconds = timeoutInSeconds;
}

public String getSourceName() {
Expand Down Expand Up @@ -111,9 +107,12 @@ public String getCustomizationSpec() {
public boolean isPowerOn() {
return powerOn;
}

public int getTimeoutInSeconds() {
return timeoutInSeconds;
if (timeoutInSeconds==null) {
return TIMEOUT_DEFAULT;
}
return timeoutInSeconds.intValue();
}

@Override
Expand Down Expand Up @@ -179,9 +178,10 @@ private boolean cloneFromSource(final Run<?, ?> run, final Launcher launcher, fi
}
vsphere.cloneVm(expandedClone, expandedSource, linkedClone, expandedResourcePool, expandedCluster,
expandedDatastore, expandedFolder, powerOn, expandedCustomizationSpec, jLogger);
if (powerOn) {
VSphereLogger.vsLogger(jLogger, "Powering on VM \""+expandedClone+"\" for the next "+timeoutInSeconds+" seconds.");
IP = vsphere.getIp(vsphere.getVmByName(expandedClone), timeoutInSeconds);
final int timeoutInSecondsForGetIp = getTimeoutInSeconds();
if (powerOn && timeoutInSecondsForGetIp>0) {
VSphereLogger.vsLogger(jLogger, "Powering on VM \""+expandedClone+"\". Waiting for its IP for the next "+timeoutInSecondsForGetIp+" seconds.");
IP = vsphere.getIp(vsphere.getVmByName(expandedClone), timeoutInSecondsForGetIp);
}
VSphereLogger.vsLogger(jLogger, "\""+expandedClone+"\" successfully cloned " + (powerOn ? "and powered on" : "") + "!");

Expand All @@ -200,6 +200,10 @@ public String getDisplayName() {
return Messages.vm_title_Clone();
}

public static int getDefaultTimeoutInSeconds() {
return TIMEOUT_DEFAULT;
}

public FormValidation doCheckSource(@QueryParameter String value)
throws IOException, ServletException {
if (value.length() == 0)
Expand Down Expand Up @@ -249,6 +253,11 @@ public FormValidation doCheckCustomizationSpec(@QueryParameter String value)
return FormValidation.ok();
}

public FormValidation doCheckTimeoutInSeconds(@QueryParameter String value)
throws IOException, ServletException {
return FormValidation.validateNonNegativeInteger(value);
}

public FormValidation doTestData(@QueryParameter String serverName,
@QueryParameter String sourceName, @QueryParameter String clone,
@QueryParameter String resourcePool, @QueryParameter String cluster,
Expand Down
42 changes: 27 additions & 15 deletions src/main/java/org/jenkinsci/plugins/vsphere/builders/Deploy.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

public class Deploy extends VSphereBuildStep implements SimpleBuildStep {

private final int TIMEOUT_DEFAULT = 60;
private static final int TIMEOUT_DEFAULT = 60;

private final String template;
private final String clone;
Expand All @@ -51,12 +51,14 @@ public class Deploy extends VSphereBuildStep implements SimpleBuildStep {
private final String folder;
private final String customizationSpec;
private final boolean powerOn;
private final int timeoutInSeconds;
/** null means use default, zero or negative means don't even try at all. */
private final Integer timeoutInSeconds;
private String IP;

@DataBoundConstructor
public Deploy(String template, String clone, boolean linkedClone,
String resourcePool, String cluster, String datastore, String folder, String customizationSpec, Integer timeoutInSeconds, boolean powerOn) throws VSphereException {
String resourcePool, String cluster, String datastore, String folder,
String customizationSpec, Integer timeoutInSeconds, boolean powerOn) throws VSphereException {
this.template = template;
this.clone = clone;
this.linkedClone = linkedClone;
Expand All @@ -66,12 +68,7 @@ public Deploy(String template, String clone, boolean linkedClone,
this.folder=folder;
this.customizationSpec=customizationSpec;
this.powerOn=powerOn;
if (timeoutInSeconds != null) {
this.timeoutInSeconds = timeoutInSeconds;
}
else {
this.timeoutInSeconds = TIMEOUT_DEFAULT;
}
this.timeoutInSeconds = timeoutInSeconds;
}

public String getTemplate() {
Expand Down Expand Up @@ -111,7 +108,10 @@ public boolean isPowerOn() {
}

public int getTimeoutInSeconds() {
return timeoutInSeconds;
if (timeoutInSeconds==null) {
return TIMEOUT_DEFAULT;
}
return timeoutInSeconds.intValue();
}

@Override
Expand Down Expand Up @@ -199,10 +199,14 @@ private boolean deployFromTemplate(final Run<?, ?> run, final Launcher launcher,
if (!powerOn) {
return true; // don't try to obtain IP if VM isn't being turned on.
}
VSphereLogger.vsLogger(jLogger, "Trying to get the IP address of \""+expandedClone+"\" for the next "+timeoutInSeconds+" seconds.");
IP = vsphere.getIp(vsphere.getVmByName(expandedClone), timeoutInSeconds);
final int timeoutInSecondsForGetIp = getTimeoutInSeconds();
if (timeoutInSecondsForGetIp<=0) {
return true; // don't try to obtain IP if disabled
}
VSphereLogger.vsLogger(jLogger, "Trying to get the IP address of \""+expandedClone+"\" for the next "+timeoutInSecondsForGetIp+" seconds.");
IP = vsphere.getIp(vsphere.getVmByName(expandedClone), timeoutInSecondsForGetIp);

if(IP!=null) {
if (IP!=null) {
VSphereLogger.vsLogger(jLogger, "Successfully retrieved IP for \"" + expandedClone + "\" : " + IP);
VSphereLogger.vsLogger(jLogger, "Exposing " + IP + " as environment variable VSPHERE_IP");

Expand All @@ -211,10 +215,9 @@ private boolean deployFromTemplate(final Run<?, ?> run, final Launcher launcher,
envAction.add("VSPHERE_IP", IP);
run.addAction(envAction);
}

return true;
} else {
VSphereLogger.vsLogger(jLogger, "Error: Timed out after waiting 60 seconds to get IP for \""+expandedClone+"\" ");
VSphereLogger.vsLogger(jLogger, "Error: Timed out after waiting "+timeoutInSecondsForGetIp+" seconds to get IP for \""+expandedClone+"\" ");
return false;
}
}
Expand All @@ -231,6 +234,10 @@ public String getDisplayName() {
return Messages.vm_title_Deploy();
}

public static int getDefaultTimeoutInSeconds() {
return TIMEOUT_DEFAULT;
}

public FormValidation doCheckTemplate(@QueryParameter String value)
throws IOException, ServletException {
if (value.length() == 0)
Expand All @@ -257,6 +264,11 @@ public FormValidation doCheckCluster(@QueryParameter String value)
return FormValidation.ok();
}

public FormValidation doCheckTimeoutInSeconds(@QueryParameter String value)
throws IOException, ServletException {
return FormValidation.validateNonNegativeInteger(value);
}

public FormValidation doTestData(@QueryParameter String serverName,
@QueryParameter String template, @QueryParameter String clone,
@QueryParameter String resourcePool, @QueryParameter String cluster) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ limitations under the License.
<f:textbox />
</f:entry>

<f:entry title="${%Power on?}" field="powerOn">
<f:checkbox />
</f:entry>

<f:entry title="${%Customization Specification}" field="customizationSpec">
<f:textbox/>
</f:entry>

<f:optionalBlock title="${%Power on?}" field="powerOn" inline="true">
<f:entry title="${%Max time to wait for IP}" field="timeoutInSeconds">
<f:number clazz="required non-negative-number" default="${descriptor.defaultTimeoutInSeconds}" />
</f:entry>
</f:optionalBlock>

<f:validateButton title="${%Check Data}" progress="${%Testing...}" method="testData" with="serverName,sourceName,clone,resourcePool,cluster"/>
</j:jelly>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div>
The length of time, in seconds, to wait for the new VirtualMachine to be assigned an IP address after it has been powered on.
If this value is zero, no attempt will be made to determine the IP address.
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ limitations under the License.
<f:textbox />
</f:entry>

<f:entry title="${%Power on?}" field="powerOn">
<f:checkbox />
</f:entry>

<f:optionalBlock title="${%Power on?}" field="powerOn" inline="true">
<f:entry title="${%Max time to wait for IP}" field="timeoutInSeconds">
<f:number clazz="required non-negative-number" default="${descriptor.defaultTimeoutInSeconds}" />
</f:entry>
</f:optionalBlock>

<f:validateButton title="${%Check Data}" progress="${%Testing...}" method="testData" with="serverName,template,clone,resourcePool,cluster"/>
</j:jelly>
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<div>
Specifies whether or not the new VirtualMachine should be powered on after creation.
If set, the power-on operation will be done using default settings and an attempt will be made at determining the IP address.
If you require more control over this process, use a separate step to turn on the VirtualMachine.
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div>
The length of time, in seconds, to wait for the new VirtualMachine to be assigned an IP address after it has been powered on.
If this value is zero, no attempt will be made to determine the IP address.
</div>