public class VimUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
COMPUTERESOURCE
Managed entity of type ComputeResource
|
static java.lang.String |
DATACENTER
Managed entity of type Datacenter
|
static java.lang.String |
DATASTORE
Managed entity of type Datastore
|
static java.lang.String |
FOLDER
Managed entity of type Folder
|
static java.lang.String |
HOSTSYSTEM
Managed entity of type HostSystem
|
static java.lang.String[] |
MANAGEDENTITIES |
static java.lang.String |
NETWORK
Managed entity of type Network
|
static java.lang.String |
RESOURCEPOOL
Managed entity of type ResourcePool
|
static java.lang.String |
VIRTUALAPP
Managed entity of type VirtualApp
|
static java.lang.String |
VIRTUALMACHINE
Managed entity of type VirtualMachine
|
Constructor and Description |
---|
VimUtil() |
Modifier and Type | Method and Description |
---|---|
void |
connect(java.lang.String urlstr,
java.lang.String name,
java.lang.String pwd) |
void |
createVM(java.lang.String hostName)
Method to create a new Virtual Machine on a specific host.
|
void |
deleteVM(java.lang.String vmName)
Method to delete a VM
|
void |
disconnect()
Method to disconnect connection to the connected vCenter Server or Esi host
|
void |
enableLog(boolean flag)
Enable or disable log messages
|
void |
exportVM(java.lang.String vmName,
java.lang.String localpath)
Method to export a VM to a ovf file.
|
com.vmware.vim25.ManagedObjectReference[] |
getAllEntities()
Method to retrieve all available managed entities in a given vCenter/Esxi host environment
|
com.vmware.vim25.ManagedObjectReference[] |
getAllManagedEntities() |
com.vmware.vim25.ManagedObjectReference[] |
getArray(java.util.List<com.vmware.vim25.ManagedObjectReference> list) |
java.lang.String |
getCapacity(com.vmware.vim25.ManagedObjectReference entity) |
java.util.List<com.vmware.vim25.ManagedObjectReference> |
getChildEntities(com.vmware.vim25.ManagedObjectReference mor) |
java.util.List<java.lang.String> |
getList(java.lang.String entityType)
Get list of available managed entities from vCenter Server or Esxi host
|
com.vmware.vim25.ManagedObjectReference[] |
getManagedEntities(java.lang.String entityType) |
com.vmware.vim25.ManagedObjectReference |
getManagedEntity(java.lang.String entityType,
com.vmware.vim25.ManagedObjectReference dsRef)
Method to retrieve MOR of a given managed entity type.
|
com.vmware.vim25.ManagedObjectReference |
getMORFromEntityName(java.lang.String entityType,
java.lang.String entityName)
Method to get the MOR for a given entity type and entity name
|
java.lang.String |
getOvfDesc(java.lang.String ovfDescFile)
Method to get Ovf descriptor
|
com.vmware.vim25.ManagedObjectReference |
getParentMOR(com.vmware.vim25.ManagedObjectReference mor)
Method to retrieve parent MOR of a given MOR
|
java.lang.String |
getParentName(com.vmware.vim25.ManagedObjectReference mor)
Method to retrieve parent name of a given MOR
|
java.lang.String |
getParentName(java.lang.String entityType,
java.lang.String entityName)
Method to retrieve parent name of a given entity name
|
java.util.Map<java.lang.String,java.lang.Object> |
getProperties(com.vmware.vim25.ManagedObjectReference ref,
java.lang.String[] props)
Method to retrieve all or specific properties of a given managed entity //kannan
|
java.util.Map<java.lang.String,java.lang.Object> |
getProperties(java.lang.String entityType,
java.lang.String entityName,
java.lang.String[] props)
Method to retrieve all or specific properties of a given entity
|
java.lang.Object |
getProperty(com.vmware.vim25.ManagedObjectReference ref,
java.lang.String prop)
Method to retrieve a specific property of a given entity
|
java.lang.String |
getResourceInfo(com.vmware.vim25.ResourceConfigSpec rSpec) |
com.vmware.vim25.ManagedObjectReference |
getResourcePool(com.vmware.vim25.ManagedObjectReference hostRef)
Method to retrieve ResourcePool for a given host MOR
|
java.util.Map<java.lang.String,java.lang.Object> |
getRPtoVMMap()
Method to get a map of ResourcePool to VM mapping
|
java.lang.String |
getServiceInstanceName()
Method to retrieve service instance name
|
java.util.List<?> |
getVMListFromHost(java.lang.String hostName,
boolean retName)
Method for getting list of all VMs on a given hostname
|
com.vmware.vim25.ManagedObjectReference |
getVMMORFromHostName(java.lang.String hostName,
java.lang.String vmName)
Method to retrieve VM MOR from a given host name and vm name
|
com.vmware.vim25.ManagedObjectReference |
getVMMORFromHostSystem(com.vmware.vim25.ManagedObjectReference hostRef,
java.lang.String vmName) |
java.lang.Object |
getVMProperty(java.lang.String vmName,
java.lang.String property)
Method to retrieve a specific property of a virtual machine
|
void |
help()
Method to print out all the available command line arguments and its parameters
|
void |
importVM(java.lang.String ovfFilePath,
java.lang.String hostName,
java.lang.String newVmName)
Method to import a ovf file into a requested host
|
void |
installVMWareTools(com.vmware.vim25.ManagedObjectReference vmRef)
Method to install vmware tools on a specific vm(MOR)
|
void |
installVMWareTools(java.lang.String vmName)
Method to install vmware tools on a specific vm
|
boolean |
isConnected()
Method to determine if conection to vCenter Server or Esxi host is still active
|
boolean |
isVCenterServer()
Method to determine if the connection is made to a vCenter Server or an Esxi host
|
ManagedObject |
loadInventory()
Method to load all the ManagedEntities with basic properties into memory.
|
ManagedObject |
loadInventory(com.vmware.vim25.ManagedObjectReference entity)
Method to load all the ManagedEntities associated with a given ManagedEntity alongwith their respective basic properties into memory.
|
protected void |
logOutput(java.lang.String str)
Method to log any comments to std out prefixed with the caller method's name
|
static void |
main(java.lang.String[] args) |
void |
populateDataObject(DataObject rootData)
Method to populate a DataObject with all the ManagedEntities in vCenter/Esxi host inventory
|
void |
populateDataObject(DataObject rootData,
java.lang.String hostName)
Method to populate a DataObject with the objects/resources associated with a given host in vCenter/Esxi host inventory
|
boolean |
powerOffVM(java.lang.String vmName,
java.lang.String hostName)
Method to power OFF a given VM name on a specific host name.
|
boolean |
powerOnVM(java.lang.String vmName,
java.lang.String hostName)
Method to power ON a given VM name on a specific host name.
|
void |
setConnection(com.vmware.vim25.VimService service,
com.vmware.vim25.VimPortType port,
com.vmware.vim25.ServiceContent content,
com.vmware.vim25.UserSession session)
Use this method to use up your own connection and make use of this utility class as required
|
public static final java.lang.String HOSTSYSTEM
public static final java.lang.String VIRTUALMACHINE
public static final java.lang.String DATACENTER
public static final java.lang.String DATASTORE
public static final java.lang.String RESOURCEPOOL
public static final java.lang.String COMPUTERESOURCE
public static final java.lang.String FOLDER
public static final java.lang.String NETWORK
public static final java.lang.String VIRTUALAPP
public static final java.lang.String[] MANAGEDENTITIES
public java.lang.String getServiceInstanceName()
public void setConnection(com.vmware.vim25.VimService service, com.vmware.vim25.VimPortType port, com.vmware.vim25.ServiceContent content, com.vmware.vim25.UserSession session)
service
- port
- content
- session
- public void connect(java.lang.String urlstr, java.lang.String name, java.lang.String pwd) throws java.lang.Exception
java.lang.Exception
public boolean isVCenterServer()
public boolean isConnected()
public void disconnect() throws java.lang.Exception
java.lang.Exception
public void enableLog(boolean flag)
flag
- to enable logging or notpublic void help()
public static void main(java.lang.String[] args) throws java.lang.Exception
java.lang.Exception
public java.util.List<?> getVMListFromHost(java.lang.String hostName, boolean retName)
hostName
- name of the host systemretName
- set it to true if list of all VM names are to be returned. set to false to return list of all VM MORspublic java.util.Map<java.lang.String,java.lang.Object> getRPtoVMMap()
public java.lang.Object getVMProperty(java.lang.String vmName, java.lang.String property)
vmName
- Name of the virtual machineproperty
- specific property of the VM to be retrieved.public java.lang.Object getProperty(com.vmware.vim25.ManagedObjectReference ref, java.lang.String prop)
ref
- MOR of the entity whose property need to be retrievedprop
- specific property of the managed entity to be retrieved.public java.util.Map<java.lang.String,java.lang.Object> getProperties(java.lang.String entityType, java.lang.String entityName, java.lang.String[] props)
entityType
- type of the managed entityentityName
- name of the managed entityprops
- specific list of properties to be retrieved. If passed null, the method will retrieve all propertiespublic java.util.Map<java.lang.String,java.lang.Object> getProperties(com.vmware.vim25.ManagedObjectReference ref, java.lang.String[] props)
ref
- MOR of the entity whose properties need to be retrievedprops
- specific list of properties to be retrieved. If passed null, the method will retrieve all propertiespublic java.lang.String getParentName(java.lang.String entityType, java.lang.String entityName)
entityType
- managed entity typeentityName
- managed entity namepublic java.lang.String getParentName(com.vmware.vim25.ManagedObjectReference mor)
mor
- MOR of the requested entitypublic com.vmware.vim25.ManagedObjectReference getParentMOR(com.vmware.vim25.ManagedObjectReference mor)
mor
- MOR of the requested entitypublic java.util.List<java.lang.String> getList(java.lang.String entityType)
entityType
- managed entity typepublic com.vmware.vim25.ManagedObjectReference getMORFromEntityName(java.lang.String entityType, java.lang.String entityName)
entityType
- managed entity typeentityName
- managed entity namepublic com.vmware.vim25.ManagedObjectReference getVMMORFromHostName(java.lang.String hostName, java.lang.String vmName)
hostName
- name of the hostsystemvmName
- name of the virtual machinepublic com.vmware.vim25.ManagedObjectReference getVMMORFromHostSystem(com.vmware.vim25.ManagedObjectReference hostRef, java.lang.String vmName)
public com.vmware.vim25.ManagedObjectReference[] getAllEntities()
public java.util.List<com.vmware.vim25.ManagedObjectReference> getChildEntities(com.vmware.vim25.ManagedObjectReference mor)
public boolean powerOnVM(java.lang.String vmName, java.lang.String hostName)
vmName
- name of the virtual machine that needs to be powered onhostName
- name of the host where the requested vmName resides. This parameter is optional.public boolean powerOffVM(java.lang.String vmName, java.lang.String hostName)
vmName
- name of the virtual machine that needs to be powered offhostName
- name of the host where the requested vmName resides. This parameter is optional.public void importVM(java.lang.String ovfFilePath, java.lang.String hostName, java.lang.String newVmName)
ovfFilePath
- path to ovf file that needs to be importedhostName
- host system where the ovf file needs to be imported tonewVmName
- name of the virtual machine that needs to be given on deploying the ovfpublic com.vmware.vim25.ManagedObjectReference getResourcePool(com.vmware.vim25.ManagedObjectReference hostRef)
hostRef
- MOR of the host systempublic com.vmware.vim25.ManagedObjectReference getManagedEntity(java.lang.String entityType, com.vmware.vim25.ManagedObjectReference dsRef)
entityType
- public com.vmware.vim25.ManagedObjectReference[] getManagedEntities(java.lang.String entityType)
public com.vmware.vim25.ManagedObjectReference[] getArray(java.util.List<com.vmware.vim25.ManagedObjectReference> list)
public com.vmware.vim25.ManagedObjectReference[] getAllManagedEntities()
public java.lang.String getOvfDesc(java.lang.String ovfDescFile)
ovfDescFile
- path to the ovf filepublic void exportVM(java.lang.String vmName, java.lang.String localpath)
vmName
- name of the virtual machine to be exported tolocalpath
- path to the directory where the ovf needs to be createdpublic void installVMWareTools(java.lang.String vmName)
vmName
- name of the virtual machine where vmware tools need to be installedpublic void installVMWareTools(com.vmware.vim25.ManagedObjectReference vmRef)
vmRef
- MOR of the virtual machine here vmware tools need to be installedpublic void createVM(java.lang.String hostName)
hostName
- Esxi host where the virtual machine needs to be createdpublic void deleteVM(java.lang.String vmName)
vmName
- name of the virtual machine that needs to be deleted from the inventorypublic ManagedObject loadInventory()
public java.lang.String getCapacity(com.vmware.vim25.ManagedObjectReference entity)
public java.lang.String getResourceInfo(com.vmware.vim25.ResourceConfigSpec rSpec)
public ManagedObject loadInventory(com.vmware.vim25.ManagedObjectReference entity)
entity
- reference to the ManagedEntitypublic void populateDataObject(DataObject rootData, java.lang.String hostName)
rootData
- reference to DataObject that needs to be populatedhostName
- name of the hostpublic void populateDataObject(DataObject rootData)
rootData
- reference to DataObject that needs to be populatedprotected void logOutput(java.lang.String str)