Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
19 changes: 16 additions & 3 deletions src/main/java/org/jenkinsci/plugins/vsphere/builders/Clone.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@

public class Clone extends VSphereBuildStep {

private final int TIMEOUT_DEFAULT = 60;
Copy link
Copy Markdown
Member

@pjdarton pjdarton Jul 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation incorrect - use spaces, not tabs (tabs are evil - they never display the same as some people set them to 4, some 2, some 8 etc).

There's indentation issues lower down too - check your editor's settings and ensure that the file is free of tabs (and then check the indentation again) before re-uploading.


private final String sourceName;
private final String clone;
private final boolean linkedClone;
Expand All @@ -51,12 +53,13 @@ public class Clone extends VSphereBuildStep {
private final String folder;
private final String customizationSpec;
private final boolean powerOn;
private final int timeoutInSeconds;
private String IP;

@DataBoundConstructor
public Clone(String sourceName, String clone, boolean linkedClone,
String resourcePool, String cluster, String datastore, String folder,
boolean powerOn, String customizationSpec) throws VSphereException {
boolean powerOn, int timeoutInSeconds, String customizationSpec) throws VSphereException {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"int" should be "Integer" in order to cope with old configuration data where this parameter did not exist.

this.sourceName = sourceName;
this.clone = clone;
this.linkedClone = linkedClone;
Expand All @@ -66,6 +69,12 @@ public Clone(String sourceName, String clone, boolean linkedClone,
this.folder=folder;
this.customizationSpec=customizationSpec;
this.powerOn=powerOn;
if (timeoutInSeconds != null) {
this.timeoutInSeconds = timeoutInSeconds;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once the timeoutInSeconds is an Integer, you should use ... = timeoutInSeconds.intValue(); to explicitly un-box the value.

}
else {
this.timeoutInSeconds = TIMEOUT_DEFAULT;
}
}

public String getSourceName() {
Expand Down Expand Up @@ -103,6 +112,10 @@ public String getCustomizationSpec() {
public boolean isPowerOn() {
return powerOn;
}

public int getTimeoutInSeconds() {
return timeoutInSeconds;
}

@Override
public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath filePath, @Nonnull Launcher launcher, @Nonnull TaskListener listener) throws InterruptedException, IOException {
Expand Down Expand Up @@ -168,8 +181,8 @@ 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...");
IP = vsphere.getIp(vsphere.getVmByName(expandedClone), 60);
VSphereLogger.vsLogger(jLogger, "Powering on VM \""+expandedClone+"\" for the next "+timeoutInSeconds+" seconds.");
IP = vsphere.getIp(vsphere.getVmByName(expandedClone), timeoutInSeconds);
}
VSphereLogger.vsLogger(jLogger, "\""+expandedClone+"\" successfully cloned " + (powerOn ? "and powered on" : "") + "!");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@

public class Deploy extends VSphereBuildStep implements SimpleBuildStep {

private final int TIMEOUT_DEFAULT = 60;

private final String template;
private final String clone;
private final boolean linkedClone;
Expand All @@ -52,11 +54,12 @@ public class Deploy extends VSphereBuildStep implements SimpleBuildStep {
private final String folder;
private final String customizationSpec;
private final boolean powerOn;
private final int timeoutInSeconds;
private String IP;

@DataBoundConstructor
public Deploy(String template, String clone, boolean linkedClone,
String resourcePool, String cluster, String datastore, String folder, String customizationSpec, boolean powerOn) throws VSphereException {
String resourcePool, String cluster, String datastore, String folder, String customizationSpec, int timeoutInSeconds, boolean powerOn) throws VSphereException {
this.template = template;
this.clone = clone;
this.linkedClone = linkedClone;
Expand All @@ -66,6 +69,12 @@ 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;
}
}

public String getTemplate() {
Expand Down Expand Up @@ -101,8 +110,12 @@ public String getCustomizationSpec() {
}

public boolean isPowerOn() {
return powerOn;
return powerOn;
}

public int getTimeoutInSeconds() {
return timeoutInSeconds;
}

@Override
public String getIP() {
Expand Down Expand Up @@ -189,7 +202,8 @@ 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.
}
IP = vsphere.getIp(vsphere.getVmByName(expandedClone), 60);
VSphereLogger.vsLogger(jLogger, "Trying to get the IP address of \""+expandedClone+"\" for the next "+timeoutInSeconds+" seconds.");
IP = vsphere.getIp(vsphere.getVmByName(expandedClone), timeoutInSeconds);

if(IP!=null) {
VSphereLogger.vsLogger(jLogger, "Successfully retrieved IP for \"" + expandedClone + "\" : " + IP);
Expand Down