-
-
Notifications
You must be signed in to change notification settings - Fork 103
added possibility of creating clone without specifying resource pool. #33
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
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <projectDescription> | ||
| <name>vsphere-plugin-ichai5</name> | ||
| <comment></comment> | ||
| <projects> | ||
| </projects> | ||
| <buildSpec> | ||
| </buildSpec> | ||
| <natures> | ||
| </natures> | ||
| </projectDescription> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 { | ||
|
|
||
|
|
@@ -131,13 +134,6 @@ public FormValidation doCheckClone(@QueryParameter String value) | |
| return FormValidation.ok(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
@@ -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; | ||
|
|
@@ -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; | ||
|
|
@@ -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); | ||
|
|
@@ -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){ | ||
|
|
@@ -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; | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
|
|
@@ -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(); | ||
|
|
||
2 changes: 2 additions & 0 deletions
2
src/main/resources/org/jenkinsci/plugins/vsphere/builders/Clone/help-resourcePool.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.