Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 11 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
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.

This file should not be in this commit.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You are right,
How can I remove from the pull request ?

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.

Make a commit to Ichai5:master that deletes the file. The PR will be automatically updated when the change is pushed to GitHub Ichai5:master.

<projectDescription>
<name>vsphere-plugin-ichai5</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>
22 changes: 9 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 @@ -14,24 +14,27 @@
*/
package org.jenkinsci.plugins.vsphere.builders;

import com.vmware.vim25.mo.VirtualMachine;
import com.vmware.vim25.mo.VirtualMachineSnapshot;
import hudson.EnvVars;
import hudson.Extension;
import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import hudson.model.AbstractBuild;
import hudson.util.FormValidation;

import java.io.IOException;
import java.io.PrintStream;

import javax.servlet.ServletException;

import org.jenkinsci.plugins.vsphere.VSphereBuildStep;
import org.jenkinsci.plugins.vsphere.tools.VSphere;
import org.jenkinsci.plugins.vsphere.tools.VSphereException;
import org.jenkinsci.plugins.vsphere.tools.VSphereLogger;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;

import javax.servlet.ServletException;
import java.io.IOException;
import java.io.PrintStream;
import com.vmware.vim25.mo.VirtualMachine;
import com.vmware.vim25.mo.VirtualMachineSnapshot;

public class Clone extends VSphereBuildStep {

Expand Down Expand Up @@ -131,13 +134,6 @@ public FormValidation doCheckClone(@QueryParameter String value)
return FormValidation.ok();
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.

Can't this be improved to check only if applicable?

}

public FormValidation doCheckResourcePool(@QueryParameter String value)
throws IOException, ServletException {
if (value.length() == 0)
return FormValidation.error(Messages.validation_required("the resource pool"));
return FormValidation.ok();
}

public FormValidation doCheckCluster(@QueryParameter String value)
throws IOException, ServletException {
if (value.length() == 0)
Expand Down
49 changes: 24 additions & 25 deletions src/main/java/org/jenkinsci/plugins/vsphere/tools/VSphere.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,20 @@
*/
package org.jenkinsci.plugins.vsphere.tools;

import com.vmware.vim25.FileFault;
import java.io.PrintStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

import org.apache.commons.lang.StringUtils;

import com.vmware.vim25.GuestInfo;
import com.vmware.vim25.InvalidName;
import com.vmware.vim25.InvalidProperty;
import com.vmware.vim25.InvalidState;
import com.vmware.vim25.ManagedObjectReference;
import com.vmware.vim25.RuntimeFault;
import com.vmware.vim25.SnapshotFault;
import com.vmware.vim25.TaskInProgress;
import com.vmware.vim25.TaskInfoState;
import com.vmware.vim25.VirtualMachineCloneSpec;
import com.vmware.vim25.VirtualMachineConfigSpec;
Expand All @@ -32,10 +37,10 @@
import com.vmware.vim25.VirtualMachineSnapshotInfo;
import com.vmware.vim25.VirtualMachineSnapshotTree;
import com.vmware.vim25.VirtualMachineToolsStatus;
import com.vmware.vim25.VmConfigFault;
import com.vmware.vim25.mo.ClusterComputeResource;
import com.vmware.vim25.mo.Datastore;
import com.vmware.vim25.mo.Folder;
import com.vmware.vim25.mo.HostSystem;
import com.vmware.vim25.mo.InventoryNavigator;
import com.vmware.vim25.mo.ManagedEntity;
import com.vmware.vim25.mo.ResourcePool;
Expand All @@ -44,16 +49,6 @@
import com.vmware.vim25.mo.VirtualMachine;
import com.vmware.vim25.mo.VirtualMachineSnapshot;

import org.apache.commons.lang.StringUtils;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

import java.io.PrintStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;

public class VSphere {
private final URL url;
private final String session;
Expand Down Expand Up @@ -143,7 +138,7 @@ private void cloneOrDeployVm(String cloneName, String sourceName, boolean linked
throw new VSphereException("VM \"" + cloneName + "\" already exists");
}

VirtualMachineRelocateSpec rel = createRelocateSpec(jLogger, linkedClone, resourcePoolName, cluster, datastoreName);
VirtualMachineRelocateSpec rel = createRelocateSpec(jLogger, linkedClone, resourcePoolName, cluster, datastoreName, sourceVm.getConfig().template);

VirtualMachineCloneSpec cloneSpec = createCloneSpec(rel);
cloneSpec.setTemplate(false);
Expand Down Expand Up @@ -181,7 +176,7 @@ private VirtualMachineCloneSpec createCloneSpec(VirtualMachineRelocateSpec rel)
}

private VirtualMachineRelocateSpec createRelocateSpec(PrintStream jLogger, boolean linkedClone, String resourcePoolName,
String cluster, String datastoreName) throws RemoteException, MalformedURLException, VSphereException {
String cluster, String datastoreName, boolean isResourcePoolRequired) throws RemoteException, MalformedURLException, VSphereException {
VirtualMachineRelocateSpec rel = new VirtualMachineRelocateSpec();

if(linkedClone){
Expand All @@ -197,22 +192,27 @@ private VirtualMachineRelocateSpec createRelocateSpec(PrintStream jLogger, boole
logMessage(jLogger, "Cluster resource " + cluster + " does not exist, root folder will be used for getting resource pool and datastore");
}

ResourcePool resourcePool = getResourcePoolByName(resourcePoolName, clusterResource);
if (resourcePoolName != null && !resourcePoolName.isEmpty()) {
ResourcePool resourcePool = getResourcePoolByName(resourcePoolName, clusterResource);

if (resourcePool == null) {
throw new VSphereException("Resource pool \"" + resourcePoolName + "\" not found");
if (resourcePool == null) {
throw new VSphereException("Resource pool \"" + resourcePoolName + "\" not found");
}

rel.setPool(resourcePool.getMOR());
} else if (isResourcePoolRequired) {
throw new VSphereException("You must specify a resource pool when using a template");
}

rel.setPool(resourcePool.getMOR());

if (datastoreName != null && !datastoreName.isEmpty()) {
Datastore datastore = getDatastoreByName(datastoreName, clusterResource);
if (datastore==null){
throw new VSphereException("Datastore \"" + datastoreName + "\" not found!");
}
rel.setDatastore(datastore.getMOR());
}
return rel;

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.

Unnecessary whitespace changes.

return rel;
}

public void reconfigureVm(String name, VirtualMachineConfigSpec spec) throws VSphereException {
Expand Down Expand Up @@ -491,7 +491,6 @@ public VirtualMachine getVmByName(String vmName) throws VSphereException {
}
}


private Datastore getDatastoreByName(final String datastoreName, ManagedEntity rootEntity) throws RemoteException, MalformedURLException {
if (rootEntity == null) {
rootEntity = getServiceInstance().getRootFolder();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<div>
The Resource Pool to be used by the VM.
Leave it blank to use the same resource pool as the source VM.
Must be specified if source VM is a template.
</div>