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
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,19 @@ public class PowerOff extends VSphereBuildStep implements SimpleBuildStep {
private final boolean evenIfSuspended;
private final boolean shutdownGracefully;


private final boolean ignoreIfNotExists;

@DataBoundConstructor
public PowerOff( final String vm, final boolean evenIfSuspended, final boolean shutdownGracefully) throws VSphereException {
public PowerOff( final String vm, final boolean evenIfSuspended, final boolean shutdownGracefully, final boolean ignoreIfNotExists) throws VSphereException {
this.vm = vm;
this.evenIfSuspended = evenIfSuspended;
this.shutdownGracefully = shutdownGracefully;
this.ignoreIfNotExists = ignoreIfNotExists;
}

public boolean isIgnoreIfNotExists() {
return ignoreIfNotExists;
}

public boolean isEvenIfSuspended() {
Expand Down Expand Up @@ -118,12 +126,17 @@ private boolean powerOff(final Run<?, ?> run, Launcher launcher, final TaskListe

VSphereLogger.vsLogger(jLogger, "Shutting Down VM " + expandedVm + "...");
VirtualMachine vsphereVm = vsphere.getVmByName(expandedVm);
if (vsphereVm == null) {
if (vsphereVm == null && !ignoreIfNotExists) {
throw new RuntimeException(Messages.validation_notFound("vm " + expandedVm));
}
vsphere.powerOffVm( vsphereVm, evenIfSuspended, shutdownGracefully);

VSphereLogger.vsLogger(jLogger, "Successfully shutdown \""+expandedVm+"\"");
if (vsphereVm != null) {
vsphere.powerOffVm(vsphereVm, evenIfSuspended, shutdownGracefully);

VSphereLogger.vsLogger(jLogger, "Successfully shutdown \"" + expandedVm + "\"");
} else {
VSphereLogger.vsLogger(jLogger, "Does not exists, BUT ignore it! \"" + expandedVm + "\"");
}

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ limitations under the License.
<f:entry title="${%Shutdown gracefully?}" field="shutdownGracefully">
<f:checkbox />
</f:entry>
<f:entry title="${%ignore If Not Exists?}" field="ignoreIfNotExists">
<f:checkbox />
</f:entry>

<f:validateButton title="${%Check Data}" progress="${%Testing...}" method="testData" with="serverName,vm"/>
</j:jelly>