Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Jenkins 61702 #118

Merged
merged 4 commits into from
Sep 8, 2020
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 @@ -100,89 +100,19 @@ public void preLaunch(Computer c, TaskListener taskListener) throws IOException,
}

@Extension
public static class DescriptorVisibilityFilterImpl extends DescriptorVisibilityFilter {
@Override
public boolean filter(@CheckForNull Object context, @NonNull Descriptor descriptor) {
return !(descriptor instanceof DescriptorImpl);
}
}

@Extension
public static final class DescriptorImpl extends SlaveDescriptor {

public DescriptorImpl() {
load();
}

public static final class DescriptorImpl extends vSphereCloudSlave.DescriptorImpl {
@Override
public String getDisplayName() {
return "Slave created from a vSphere Cloud slave template";
return super.getDisplayName()+", auto-provisioned by Jenkins from cloud template";
}

@Override
public boolean isInstantiable() {
/*
* This type of agent can't be directly created by the user through the UI.
* The user defines a vSphere agent template and _that_ then creates these "on demand".
*/
return false;
Comment on lines 110 to 115
Copy link
Member

@jetersen jetersen Aug 18, 2020

Choose a reason for hiding this comment

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

I think we are fine as long as this is kept in. This is meant to prevent JCasC from removing dynamically provisioned nodes from vSphere.

}

public List<vSphereCloud> getvSphereClouds() {
List<vSphereCloud> result = new ArrayList<vSphereCloud>();
for (Cloud cloud : Jenkins.getInstance().clouds) {
if (cloud instanceof vSphereCloud) {
result.add((vSphereCloud) cloud);
}
}
return result;
}

public vSphereCloud getSpecificvSphereCloud(String vsDescription)
throws Exception {
for (vSphereCloud vs : getvSphereClouds()) {
if (vs.getVsDescription().equals(vsDescription)) {
return vs;
}
}
throw new Exception("The vSphere Cloud doesn't exist");
}

public List<String> getIdleOptions() {
List<String> options = new ArrayList<String>();
options.add("Shutdown");
options.add("Shutdown and Revert");
options.add("Revert and Restart");
options.add("Revert and Reset");
options.add("Suspend");
options.add("Reset");
options.add("Reconnect and Revert");
options.add("Nothing");
return options;
}

public FormValidation doCheckLaunchDelay(@QueryParameter String value) {
return FormValidation.validatePositiveInteger(value);
}

@RequirePOST
public FormValidation doTestConnection(@AncestorInPath ItemGroup<?> context,
@QueryParameter String vsDescription,
@QueryParameter String vmName,
@QueryParameter String snapName) {
throwUnlessUserHasPermissionToConfigureSlave(context);
try {
vSphereCloud vsC = getSpecificvSphereCloud(vsDescription);
VirtualMachine vm = vsC.vSphereInstance().getVmByName(vmName);
if (vm == null) {
return FormValidation.error("Virtual Machine was not found");
}
if (!snapName.isEmpty()) {
VirtualMachineSnapshot snap = vsC.vSphereInstance().getSnapshotInTree(vm, snapName);
if (snap == null) {
return FormValidation.error("Virtual Machine snapshot was not found");
}
}
return FormValidation.ok("Virtual Machine found successfully");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
}
22 changes: 2 additions & 20 deletions src/main/java/org/jenkinsci/plugins/vSphereCloudSlave.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@

import static org.jenkinsci.plugins.vsphere.tools.PermissionUtils.throwUnlessUserHasPermissionToConfigureSlave;

import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.AbortException;
import hudson.Extension;
import hudson.Util;
import hudson.model.DescriptorVisibilityFilter;
import hudson.model.Queue.BuildableItem;
import hudson.model.Result;
import hudson.model.TaskListener;
import hudson.model.Computer;
import hudson.model.Descriptor;
import hudson.model.Descriptor.FormException;
import hudson.model.Run;
import hudson.model.queue.CauseOfBlockage;
Expand Down Expand Up @@ -368,28 +364,14 @@ public void preLaunch(Computer c, TaskListener taskListener) throws IOException,
}

@Extension
public static class DescriptorVisibilityFilterImpl extends DescriptorVisibilityFilter {
@Override
public boolean filter(@CheckForNull Object context, @NonNull Descriptor descriptor) {
return !(descriptor instanceof DescriptorImpl);
}
}

@Extension
public static final class DescriptorImpl extends SlaveDescriptor {

public static class DescriptorImpl extends SlaveDescriptor {
public DescriptorImpl() {
load();
}

@Override
public String getDisplayName() {
return "Slave virtual computer running under vSphere Cloud";
}

@Override
public boolean isInstantiable() {
return true;
return "Agent running within a vSphere hypervisor";
}

public List<vSphereCloud> getvSphereClouds() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

<f:dropdownList name="slave.delegateLauncher" title="${%Secondary launch method}"
help="${descriptor.getHelpFile('launcher')}">
<j:forEach var="d" items="${descriptor.getComputerLauncherDescriptors()}" varStatus="loop">
<j:forEach var="d" items="${descriptor.computerLauncherDescriptors(it)}" varStatus="loop">
<f:dropdownListBlock value="${d.clazz.name}" name="${d.displayName}"
selected="${it.delegateLauncher.descriptor==d}"
title="${d.displayName}">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?jelly escape-by-default='true'?>
<div>
${%detail}
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
detail=\
Adds a permanent managed vSphere agent to Jenkins. \
This is called "managed" because Jenkins can perform vSphere-specific actions (e.g. to revert the agent back to a previous state) upon build completion etc. \
Use this if you have defined permanent virtual machines in your vSphere cloud and want Jenkins to handle them. \
If you want Jenkins to create, use and destroy machines "on demand" then you should use the Cloud functionality and define a Jenkins agent template instead.