Get Managed Object

Get Managed Object

We can easily gather all Managed Object information using vSphere SDK. We have seen in the earlier post about How to connect using SDK. Now, we will see how you can gather the Managed Object information using SDK.

Once, we connect to vCenter, we will have an object called VMware.Vim.VimClientImpl and after connection, this object will help us to gather any Managed Object information.

VimClientImpl object has the method FindEntityViews that can be used to get any Managed Object from the vCenter. This method requires the following parameters

  1. View Type
    1. "ClusterComputeResource"
    2. "ComputeResource"
    3. "Datacenter"
    4. "Datastore"
    5. "DistributedVirtualSwitch"
    6. "Folder"
    7. "HostSystem"
    8. "Network"
    9. "ResourcePool"
    10. "VirtualApp"
    11. "VirtualMachine"
  2. Begin Entity – This is Managed object reference input, that specifies the starting point for search in the inventory. This parameter helps you narrow the scope but it can be null.
  3. Filter – This is NameValueCollection input that uses hash of one or more name-value pairs, we can filter the search. The name represents the property value to test and the value represents a pattern that the property must match. If more than one pair is specified, all the patterns must match. It can be null but in that case all objects will be returned based on the specified View Type.
  4. Properties – This is string array input that contains View Type object property names. This can be null but if we specify the list of required properties then performance increases as View Type contains thousands of properties hence it is always recommended to specify properties that are required. You can refer VMware official documentation to understand the Managed Object properties. e.g. VirtualMachine Managed Object

Method FindEntityViews return List of VMware.Vim.EntityViewBase object that needs iteration of the list. In the iteration, we will have to cast the respective View Type that is used in FindEntityViews method.

In the following example, we are gathering VirtualMachine information.

After casting, we get the vm object that can be used to get respective VirtualMachine properties or perform any action on the VirtualMachine object.

VMware.Vim.VirtualMachine vm = (VMware.Vim.VirtualMachine)tmp;

vm object can be used to get properties such as Name, PowerState, vCPU, Memory many more.

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *