Class VSphere
java.lang.Object
org.jenkinsci.plugins.vsphere.tools.VSphere
-
Method Summary
Modifier and TypeMethodDescriptionvoidcloneOrDeployVm(String cloneName, String sourceName, boolean linkedClone, String resourcePoolName, String cluster, String datastoreName, String folderName, boolean useCurrentSnapshot, String namedSnapshot, boolean powerOn, Map<String, String> extraConfigParameters, String customizationSpec, PrintStream jLogger) Creates a new VM by cloning an existing VM or Template.voidcloneVm(String cloneName, String sourceName, boolean linkedClone, String resourcePoolName, String cluster, String datastoreName, String folderName, boolean powerOn, String customizationSpec, PrintStream jLogger) Clones a new VM from an existing (named) VM.static VSphereDeprecated.static VSphereconnect(VSphereConnectionConfig connectionDetails) Initiates Connection to vSphere ServerintcountVms()intcountVmsByPrefix(String prefix) voiddeleteSnapshot(String vmName, String snapName, boolean consolidate, boolean failOnNoExist) voiddeployVm(String cloneName, String sourceName, boolean linkedClone, String resourcePoolName, String cluster, String datastoreName, String folderName, boolean powerOn, String customizationSpec, PrintStream jLogger) Deploys a new VM from an existing (named) Template.voidDestroys the VM in vSpherevoidDisconnect from vSphere server.folderExists(String folderPath) com.vmware.vim25.CustomizationSpecItemgetCustomizationSpecByName(String customizationSpecName) com.vmware.vim25.mo.ManagedEntity[]com.vmware.vim25.mo.DistributedVirtualPortgroupgetDistributedVirtualPortGroupByName(com.vmware.vim25.mo.VirtualMachine virtualMachine, String name) Find Distributed Virtual Port Group name in the same Datacenter as the VMcom.vmware.vim25.mo.DistributedVirtualSwitchgetDistributedVirtualSwitchByPortGroup(com.vmware.vim25.mo.DistributedVirtualPortgroup distributedVirtualPortgroup) Find Distributed Virtual Switch from the provided Distributed Virtual Portgroupcom.vmware.vim25.mo.FoldergetIp(com.vmware.vim25.mo.VirtualMachine vm, int timeout) Asks vSphere for the IP address used by a VM.com.vmware.vim25.mo.NetworkgetNetworkPortGroupByName(com.vmware.vim25.mo.VirtualMachine virtualMachine, String name) Find Distributed Virtual Port Group name in the same Datacenter as the VMcom.vmware.vim25.mo.VirtualMachineSnapshotgetSnapshotInTree(com.vmware.vim25.mo.VirtualMachine vm, String snapName) com.vmware.vim25.mo.VirtualMachinegetVmByName(String vmName) voidmarkAsTemplate(String vmName, String snapName, boolean force) voidvoidpowerOffVm(com.vmware.vim25.mo.VirtualMachine vm, boolean evenIfSuspended, boolean shutdownGracefully) Deprecated.This method has been superseded bypowerOffVm(VirtualMachine, boolean, int), which allows setting an arbitrary grace period.voidpowerOffVm(com.vmware.vim25.mo.VirtualMachine vm, boolean evenIfSuspended, int gracefulShutdownSeconds) Power off the given virtual machine, optionally waiting a while for its operating system to shut down.voidreconfigureVm(String name, com.vmware.vim25.VirtualMachineConfigSpec spec) voidRenames the VM vSpherevoidrenameVmSnapshot(String vmName, String oldName, String newName, String newDescription) Renames a VM SnapshotvoidrevertToSnapshot(String vmName, String snapName) voidsetExtraConfigParameters(String vmName, Map<String, String> parameters) Passes data to a VM's "extra config" object.voidvoidsuspendVm(com.vmware.vim25.mo.VirtualMachine vm) voidtakeSnapshot(String vmName, String snapshot, String description, boolean snapMemory) booleanvmToolIsEnabled(com.vmware.vim25.mo.VirtualMachine vm)
-
Method Details
-
connect
public static VSphere connect(@NonNull VSphereConnectionConfig connectionDetails) throws VSphereException Initiates Connection to vSphere Server- Parameters:
connectionDetails- Contains all the details we need to connect.- Returns:
- A connected instance.
- Throws:
VSphereException- If an error occurred.
-
connect
@Deprecated public static VSphere connect(@NonNull String server, boolean ignoreCert, @NonNull String user, @CheckForNull String pw) throws VSphereException Deprecated.Useconnect(VSphereConnectionConfig)instead.Initiates Connection to vSphere Server- Parameters:
server- Server URLignoreCert- If true then we disable certificate verification, allowing the use of untrusted certificates but risk man-in-the-middle attacks.user- Username.pw- Password.- Returns:
- A connected instance.
- Throws:
VSphereException- If an error occurred.
-
disconnect
public void disconnect()Disconnect from vSphere server.Note: This logs any
Exceptionit encounters - it does not pass them to get to the calling method. -
deployVm
public void deployVm(String cloneName, String sourceName, boolean linkedClone, String resourcePoolName, String cluster, String datastoreName, String folderName, boolean powerOn, String customizationSpec, PrintStream jLogger) throws VSphereException Deploys a new VM from an existing (named) Template.- Parameters:
cloneName- - name of VM to be createdsourceName- - name of VM or template to be clonedlinkedClone- - true if you want to re-use disk backingsresourcePoolName- - resource pool to usecluster- - ComputeClusterResource to usedatastoreName- - Datastore to usefolderName- - Folder name or path to usepowerOn- - If true the VM will be powered on.customizationSpec- - Customization spec to use for this VMjLogger- - Where to log to.- Throws:
VSphereException- If an error occurred.
-
cloneVm
public void cloneVm(String cloneName, String sourceName, boolean linkedClone, String resourcePoolName, String cluster, String datastoreName, String folderName, boolean powerOn, String customizationSpec, PrintStream jLogger) throws VSphereException Clones a new VM from an existing (named) VM.- Parameters:
cloneName- - name of VM to be createdsourceName- - name of VM or template to be clonedlinkedClone- - true if you want to re-use disk backingsresourcePoolName- - resource pool to usecluster- - ComputeClusterResource to usedatastoreName- - Datastore to usefolderName- - Folder name or path to usepowerOn- - If true the VM will be powered on.customizationSpec- - Customization spec to use for this VMjLogger- - Where to log to.- Throws:
VSphereException- If an error occurred.
-
cloneOrDeployVm
public void cloneOrDeployVm(String cloneName, String sourceName, boolean linkedClone, String resourcePoolName, String cluster, String datastoreName, String folderName, boolean useCurrentSnapshot, String namedSnapshot, boolean powerOn, Map<String, String> extraConfigParameters, String customizationSpec, PrintStream jLogger) throws VSphereExceptionCreates a new VM by cloning an existing VM or Template.- Parameters:
cloneName- The name for the new VM.sourceName- The name of the VM or Template that is to be cloned.linkedClone- If true then the clone will be defined as a delta from the original, rather than a "full fat" copy. If this is true then you will need to use a snapshot.resourcePoolName- (Optional) The name of the resource pool to use, or null.cluster- (Optional) The name of the cluster, or null.datastoreName- (Optional) The name of the data store, or null.folderName- (Optional) The name or path of the VSphere folder, or nulluseCurrentSnapshot- If true then the clone will be created from the source VM's "current" snapshot. This means that the VM must have at least one snapshot.namedSnapshot- If set then the clone will be created from the source VM's snapshot of this name. If this is set thenuseCurrentSnapshotmust not be set.powerOn- If true then the new VM will be switched on after it has been created.extraConfigParameters- (Optional) parameters to set in the VM's "extra config" object. This data can then be read back at a later stage.In the case of parameters whose name starts "guestinfo.", the parameter can be read by the VMware Tools on the client OS. e.g. a variable named "guestinfo.Foo" with value "Bar" could be read on the guest using the command-linevmtoolsd --cmd "info-get guestinfo.Foo".customizationSpec- (Optional) Customization spec to use for this VM, or nulljLogger- Where to log to.- Throws:
VSphereException- if anything goes wrong.
-
reconfigureVm
public void reconfigureVm(String name, com.vmware.vim25.VirtualMachineConfigSpec spec) throws VSphereException - Throws:
VSphereException
-
startVm
- Parameters:
name- - Name of VM to starttimeoutInSeconds- How long to wait for the VM to be running.- Throws:
VSphereException- If an error occurred.
-
getSnapshotInTree
public com.vmware.vim25.mo.VirtualMachineSnapshot getSnapshotInTree(com.vmware.vim25.mo.VirtualMachine vm, String snapName) -
revertToSnapshot
- Throws:
VSphereException
-
deleteSnapshot
public void deleteSnapshot(String vmName, String snapName, boolean consolidate, boolean failOnNoExist) throws VSphereException - Throws:
VSphereException
-
takeSnapshot
public void takeSnapshot(String vmName, String snapshot, String description, boolean snapMemory) throws VSphereException - Throws:
VSphereException
-
markAsTemplate
- Throws:
VSphereException
-
markAsVm
- Throws:
VSphereException
-
getIp
Asks vSphere for the IP address used by a VM.- Parameters:
vm- VirtualMachine name whose IP is to be returned.timeout- How long to wait (in seconds) for the IP address to known to vSphere.- Returns:
- String containing IP address.
- Throws:
VSphereException- If an error occurred.
-
getVmByName
- Parameters:
vmName- - name of VM object to retrieve- Returns:
- - VirtualMachine object
- Throws:
VSphereException- If an error occurred.
-
countVms
- Throws:
VSphereException
-
countVmsByPrefix
- Throws:
VSphereException
-
folderExists
- Throws:
VSphereException
-
getFolder
- Throws:
VSphereException
-
getCustomizationSpecByName
public com.vmware.vim25.CustomizationSpecItem getCustomizationSpecByName(String customizationSpecName) throws VSphereException - Throws:
VSphereException
-
getDatastores
- Returns:
- - ManagedEntity array of Datastore
- Throws:
VSphereException- If an error occurred.
-
destroyVm
Destroys the VM in vSphere- Parameters:
name- - VM object to destroyfailOnNoExist- If true and the VM does not exist then aVSphereNotFoundExceptionwill be thrown.- Throws:
VSphereException- If an error occurred.
-
renameVmSnapshot
public void renameVmSnapshot(String vmName, String oldName, String newName, String newDescription) throws VSphereException Renames a VM Snapshot- Parameters:
vmName- the name of the VM whose snapshot is being renamed.oldName- the current name of the VM's snapshot.newName- the new name of the VM's snapshot.newDescription- the new description of the VM's snapshot.- Throws:
VSphereException- If an error occurred.
-
renameVm
Renames the VM vSphere- Parameters:
oldName- the current name of the vmnewName- the new name of the vm- Throws:
VSphereException- If an error occurred.
-
vmToolIsEnabled
public boolean vmToolIsEnabled(com.vmware.vim25.mo.VirtualMachine vm) -
powerOffVm
@Deprecated public void powerOffVm(com.vmware.vim25.mo.VirtualMachine vm, boolean evenIfSuspended, boolean shutdownGracefully) throws VSphereException Deprecated.This method has been superseded bypowerOffVm(VirtualMachine, boolean, int), which allows setting an arbitrary grace period.Power off the given virtual machine, optionally waiting 180 seconds for its operating system to shut down.- Parameters:
vm- The virtual machine to power off.evenIfSuspended- If false, a suspended VM is left as it was. If true, a suspended VM gets fully powered off.shutdownGracefully- If false, the VM is powered off immediately. If true (and VMware tools is installed), the guest operating system is given a grace period of 180 seconds to shut down.- Throws:
VSphereException
-
powerOffVm
public void powerOffVm(com.vmware.vim25.mo.VirtualMachine vm, boolean evenIfSuspended, int gracefulShutdownSeconds) throws VSphereException Power off the given virtual machine, optionally waiting a while for its operating system to shut down.- Parameters:
vm- The virtual machine to power off.evenIfSuspended- If false, a suspended VM is left as it was. If true, a suspended VM gets fully powered off.gracefulShutdownSeconds- The number of seconds to wait for the guest operating system to shut down. If the passed value is zero or less (or if VMware tools is not installed on the VM), the VM is powered off immediately.- Throws:
VSphereException
-
suspendVm
- Throws:
VSphereException
-
getNetworkPortGroupByName
public com.vmware.vim25.mo.Network getNetworkPortGroupByName(com.vmware.vim25.mo.VirtualMachine virtualMachine, String name) throws VSphereException Find Distributed Virtual Port Group name in the same Datacenter as the VM- Parameters:
virtualMachine- - VM objectname- - the name of the Port Group- Returns:
- returns DistributedVirtualPortgroup object for the provided vDS PortGroup
- Throws:
VSphereException- If an error occurred.
-
getDistributedVirtualPortGroupByName
public com.vmware.vim25.mo.DistributedVirtualPortgroup getDistributedVirtualPortGroupByName(com.vmware.vim25.mo.VirtualMachine virtualMachine, String name) throws VSphereException Find Distributed Virtual Port Group name in the same Datacenter as the VM- Parameters:
virtualMachine- - VM objectname- - the name of the Port Group- Returns:
- returns DistributedVirtualPortgroup object for the provided vDS PortGroup
- Throws:
VSphereException- If an error occurred.
-
getDistributedVirtualSwitchByPortGroup
public com.vmware.vim25.mo.DistributedVirtualSwitch getDistributedVirtualSwitchByPortGroup(com.vmware.vim25.mo.DistributedVirtualPortgroup distributedVirtualPortgroup) throws VSphereException Find Distributed Virtual Switch from the provided Distributed Virtual Portgroup- Parameters:
distributedVirtualPortgroup- - DistributedVirtualPortgroup object for the provided vDS PortGroup- Returns:
- returns DistributedVirtualSwitch object that represents the vDS Switch
- Throws:
VSphereException- If an error occurred.
-
setExtraConfigParameters
public void setExtraConfigParameters(String vmName, Map<String, String> parameters) throws VSphereExceptionPasses data to a VM's "extra config" object. This data can then be read back at a later stage. In the case of parameters whose name starts "guestinfo.", the parameter can be read by the VMware Tools on the client OS.e.g. a variable named "guestinfo.Foo" with value "Bar" could be read on the guest using the command-line
vmtoolsd --cmd "info-get guestinfo.Foo".- Parameters:
vmName- The name of the VM.parameters- AMapof variable name to variable value.- Throws:
VSphereException- If an error occurred.
-
connect(VSphereConnectionConfig)instead.