Skip to content
Closed
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
20 changes: 16 additions & 4 deletions src/main/java/org/jenkinsci/plugins/vsphere/builders/Clone.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@

public class Clone extends VSphereBuildStep {

private final int TIMEOUT_DEFAULT = 60;

private final String sourceName;
private final String clone;
private final boolean linkedClone;
Expand All @@ -48,21 +50,26 @@ public class Clone extends VSphereBuildStep {
private final String folder;
private final String customizationSpec;
private final boolean powerOn;
private Integer timeoutInSeconds = new Integer(TIMEOUT_DEFAULT);
Copy link
Copy Markdown
Contributor

@elordahl elordahl Jul 4, 2017

Choose a reason for hiding this comment

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

• Why don't you declare this as final and set it in the constructor if null?
• Why are you using an Integer over a primitive int? Are you giving the user a field to provide an override?

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, Integer timeoutInSeconds, String customizationSpec) throws VSphereException {
this.sourceName = sourceName;
this.clone = clone;
this.linkedClone = linkedClone;
this.resourcePool=resourcePool;
this.cluster=cluster;
this.datastore=datastore;
this.folder=folder;
this.customizationSpec=customizationSpec;
this.customizationSpec=customizationSpec;
this.powerOn=powerOn;
if(timeoutInSeconds != null){
this.timeoutInSeconds=timeoutInSeconds;
}

}

public String getSourceName() {
Expand All @@ -88,7 +95,7 @@ public String getResourcePool() {
public String getDatastore() {
return datastore;
}

public String getFolder() {
return folder;
}
Expand All @@ -101,6 +108,10 @@ public boolean isPowerOn() {
return powerOn;
}

public Integer getTimeoutInSeconds() {
return timeoutInSeconds;
}

@Override
public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath filePath, @Nonnull Launcher launcher, @Nonnull TaskListener listener) throws InterruptedException, IOException {
try {
Expand Down Expand Up @@ -156,7 +167,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) {
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);
}
VSphereLogger.vsLogger(jLogger, "\""+expandedClone+"\" successfully cloned!");

Expand Down
33 changes: 22 additions & 11 deletions src/main/java/org/jenkinsci/plugins/vsphere/builders/Deploy.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,35 @@

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;
private final String resourcePool;
private final String cluster;
private final String datastore;
private final String folder;
private final String customizationSpec;
private final boolean powerOn;
private final String datastore;
private final String folder;
private final String customizationSpec;
private final boolean powerOn;
private Integer timeoutInSeconds = new Integer(TIMEOUT_DEFAULT);
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, Integer timeoutInSeconds, boolean powerOn) throws VSphereException {
this.template = template;
this.clone = clone;
this.linkedClone = linkedClone;
this.resourcePool= (resourcePool != null) ? resourcePool : "";
this.cluster=cluster;
this.datastore=datastore;
this.folder=folder;
this.customizationSpec=customizationSpec;
this.datastore=datastore;
this.folder=folder;
this.customizationSpec=customizationSpec;
this.powerOn=powerOn;
if(timeoutInSeconds != null){
this.timeoutInSeconds=timeoutInSeconds;
}
}

public String getTemplate() {
Expand All @@ -91,7 +97,7 @@ public String getResourcePool() {
public String getDatastore() {
return datastore;
}

public String getFolder() {
return folder;
}
Expand All @@ -101,7 +107,11 @@ public String getCustomizationSpec() {
}

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

public Integer getTimeoutInSeconds() {
return timeoutInSeconds;
}

@Override
Expand Down Expand Up @@ -189,7 +199,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
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ protected String run() throws Exception {
step.getBuildStep().getClass().toString().contains("Clone") ||
step.getBuildStep().getClass().toString().contains("ExposeGuestInfo")) {
IP = step.getBuildStep().getIP();
envVars.put("VSPHERE_IP", IP);
if(IP != null){
envVars.put("VSPHERE_IP", IP);
}

if (step.getBuildStep().getClass().toString().contains("ExposeGuestInfo")) {
Map<String, String> envVars = ((ExposeGuestInfo)step.getBuildStep()).getVars();
Expand All @@ -136,4 +138,4 @@ protected String run() throws Exception {
return IP;
}
}
}
}