VI SDK API Usages

VI SDK API Usages

How do I retrieve all the hosts and virtual machines managed by VirtualCenter?

The mob page of a VirtualCenter Server helps you understand how to do this. Start from the ServiceInstance page (type <VC_server_host_name_or_IP>/mob in a browser) and click through the value link of the following property names: content > rootFolder > childEntity* > hostFolder > childEntity. For each childEntity, you see the host and all the virtual machines on that host.

To get all of the virtual machines, from the ServiceInstance page, traverse property content > rootFolder > childEntity > vmFolder > childEntity to get all the virtual machines. For each virtual machine, click through its property datastore > host to get the host for that virtual machine.

How can I get a HostSystem or VirtualMachine object more efficiently when I know its DNS name or IP address?

You can use the managed object SearchIndex to achieve this. For more information, please refer to this tech notes. VMware tools must installed in the virtual machine for this feature to work properly.

What does the AnswerVM method do?

The AnswerVM method answers a virtual machine question that is blocking a virtual machine. Virtual machine questions (abstracted by VirtualMachineQuestionInfo data object) are special conditions in the platform that must be answered before the virtual machine can resume. They are almost always issues that prevent a virtual machine from powering on or getting into the BIOS boot until they are answered.

For example, if the configured hard disk is marked being formatted on a virtual machine that used a BusLogic SCSI controller but the current virtual machine has an LSI Logic controller, the VMKernel wants to verify that it is OK to change the disk marking and continue booting.

Virtual machine questions are not intended for or available to guest software. They are a low-level intrusive solution for egregious but closed-ended problems, as an alternative to simply refusing to boot until the problem is fixed.

What are the Data Objects related to ISO images and VM? How should I use them?

The related data objects are VirtualMachineConfigInfo, VirtualHardware, VirtualDevice, VirtualDeviceBackingInfo, VirtualCdrom, VirtualCdromIsoBackingInfo.

The VirtualMachineConfigInfo data object provides virtual machine settings and virtual hardware configuration for the same.

The hardware property (VirtualHardware data object type) provides the set of virtual devices available. This list has the one device of type VirtualCdrom that inherits the VirtualDevice. Get the backing property of the VirtualCdrom. If the returned object VitualDeviceBackingInfo is an instance of VirtualCdromIsoBackingInfo, that object provides the ISO backing for the virtual CD-ROM.

The virtual machine configuration can be changed by using ReconfigVM_Task. This task takes in VirtualMachineConfigSpec.

Any changes to devices can be configured using VirtualDeviceConfigSpec. This data object contains a list of devices.

What are the measuring units for the objects HostFileSystemVolume and HostNicFailureCriteria?

HostFileSystemVolume is measured in bytes. HostNicFailureCriteria is measured in mBps (megabytes per second).

How can historical data and updates be retrieved?

By using TaskHistoryCollector. This object updates when server appends a new task by adding a new item in this collector. Use one of two methods to retrieve it:

  • latestPage property

  • readNextTasks and readPreviousTasks methods, which return the subsequent page in the corresponding direction

How can a list of users currently logged in to the system be retrieved?

By using the APIs. Use the SessionManager managed object for this purpose. Complete information is available by following these steps:

1. Retrieve the service content.

2. Use the service content to get a managed object reference of a session manager.

3. Use the sessionList property of SessionManager to fetch an array of UserSession.

The UserSession array contains the list of all the currently active sessions and their respective details, including the full name of the user, user name, login time, session ID, and so on.

What is the advantage of QueryPerf over QueryPerfComposite?

QueryPerfComposite uses the startTime and endTime properties in PerfQuery object. Setting the maxSample property of object PerfQuery to one with QueryPerfComposite provides the most recent sample available, not real-time statistics. Do not use this property with QueryPerfComposite.

Sometimes CreateVM() tasks show timeout errors. How can the timeout value for CreateVM() be changed?

The default timeout value for client-side HTTP is 90 seconds. This value can be set as per requirements of applications. After creating the object of the VimService, it can be changed by Timeout property in .Net.

Use timeouts of 5 minutes or more in Axis Java to avoid this problem.

Which functions are best suited to monitor the state change of a virtual machine?

GetContents() and GetUpdates(). If a client is making so many GetContents() calls the load on the server increases, resulting update delays, use GetUpdates().

Why is ComputeResourceSummary.totalMemory returned as a negative value?

This is known issue and is fixed in VMware VirtualCenter v2.5, VMware ESX 3.5 and VMware ESXi 3.5.

What is the use of summary.guest.ipAddress?

If multiple IP addresses are assigned to a virtual machine, guest.ipAddress or summary.guest.ipAddress return the primary IP address assigned to the guest operating system.

How can the listing of all IP address assigned to a virtual machine be retrieved?

guest.net returns array of GuestNicInfo, holding guest information about the network adapters. ipAddress property returns the IP addresses of the adapter.

How can events be notified as they occur?

Managed object EventHistoryCollector provides a mechanism for retrieving historical data and updates when the server appends new events. The latestPage property returns all the events on the latest page. This can be used unders certain the limitation of page size, you need to change the page size to a large number using method SetCollectorPageSize.

What is the reason for error HTTP: 503 Service Unavailable when using the RetrieveServiceContent API?

503 errors related to session limits on VMware ESX and VMware VirtualCenter and we have found SOAP session limit messages in our VMware ESX hostd.log files.

What is the return type of VirtualMachine.info.tools.toolsVersion?

Integer. The current SDK documentation for this incorrectly states Boolean. This will be updated in next documentation release.

How can the name of a virtual machine be retrieved?

APIs are available in the SDK for this task, as follows:

1. Using the RetrieveProperties API, find the datacenter reference object and the virtual machine folder for this datacenter.

2. Retrieve all the virtual machines in this folder.

3. Use the config.name property; find the name of a particular virtual machine.

4. (Optional) If a guest operating systemis installed on the virtual, call the FindByIp API.

This returns the ManagedObjectReference of the virtual machine. You can retrieve the name property from it.

Can a VM be created with multiple disks?

Yes, multiple disks can be created during the CreateVM_Taks.

How to enable the "Hide the Nx flag from the guest"?

By setting CpuFeatureMask property of VirtualMachineConfigInfo data object of Virtual Machine.

Are the DRS recommendations published through the VI API.

Yes, the DRS recommendations are published through the VI API. So you can track them using your custom application using the SDK.

For fetching the list you might want to use the Managed Object -"ClusterComputeResource" and then retrieve the property "drsRecommendation".

How BIOS related field can be read using API?

This feature is not available in current version and would be available in future versions.

How license level information can be retrieved with APIs?

Currently, No API is available to get this information.

How to get the “device Id” of an already existing virtual disk?

"key" property of VirtualDevice object is the device Id of that device. This property is a unique key that distinguishes this device from other devices in the same virtual machine.

Which API returns the list of Numa Nodes available on the host?

HostSystem->hardware->numaInfo->numaNode contains the information about each of the NUMA nodes on the host. The array is empty if the host is not NUMA-capable.

What parameters we need to provide when creating a Virtual Device and add it to VM in creation of VM process?

To create a new Virtual Device, we need to provide the parameters key, controllerKey, unitNumber and backing.

During “Update Network Config” operation, which changeOperation works?

The only mode that is implemented is incremental mode. Only add operations are supported for instances. Singleton configuration is not supported.

Does VirtualDeviceConfigSpecFileOperation.replace support on the disks?

No, this operation supports only for the floppy images.

How can an existing VMDK are replaced with a new unformatted one?

This can be done by using RecofigVM_Task API and performing "edit' file operation Device. Following are the steps to replace a vmdk.

1. First get the device on which the Virtual Disk to be replaced exist.

2. Then create a new backing info, with new file name

3. Set this new backinginfo in the Virtual device

4. To create a new backing file, use the "Create" fileOperation or To edit the existing device operation use the "Edit" fileoperation.“edit”.

Can a virtual machine be created with multiple disks?

Yes, during the CreateVM_Task.

Sample code for reference.

How can I enable Hide the Nx flag from the guest?

By setting the CpuFeatureMask property of VirtualMachineConfigInfo data object of the virtual machine.

sample code for reference.

Are DRS recommendations published through the VI API?

Yes. You can track them using your custom application using the SDK.

To retrieve list, use managed object ClusterComputeResource and retrieve the drsRecommendation property.

How can BIOS-related fields be read using APIs?

This feature is not available in the current version.

How can license-level information be retrieved using APIs?

This feature is not available in the current version.

Sample code for reference.

How can I get the device ID of an already exis(ting virtual disk?

The key property of the VirtualDevice object is the device ID. This property is a unique key that distinguishes this device from other devices in the same virtual machine.

How can the list of NUMA nodes available on the host can be retrieved?

How the list of NUMA nodes available on the host can be retrieved?

A: HostSystem > hardware > numaInfo > numaNode contains the information about each of the NUMA nodes on the host. The array is empty if the host is not NUMA capable.

What virtual device parameters are required at the creation of a virtual machine process?

To create a new virtual device, provide the parameters key, controllerKey, unitNumber, and backing.

During an Update Network Config operation, which changeOperation works?

The only mode that is implemented is incremental mode. Only add operations are supported for instances. Singleton configuration is not supported.

Does VirtualDeviceConfigSpecFileOperation.replace support disks?

No, this operation supports only floppy images.

How can I replace an existing VMDK with a new, unformatted one?

By using the RecofigVM_Task API and performing edit file operation device. Follow these steps to replace a VMDK:

1. Get the device on which the virtual disk to be replaced exists.

2. Create new backing info with a new filename.

3. Set the new backing info in the virtual device.

4. To create a new backing file, use the "Create" file operation or To edit the existing device operation use the "Edit" fileoperation.“edit”.

Why does the EventFilterSpec object behave differently on VMware VirtualCenter and VMware ESX?

Event filtering is done on VMware VirtualCenter, not on VMware ESX.

Can a virtual machine be created with static MAC provided?

Yes.

Sample code for reference.

Can basic datastore information be retrieved using an API?

Yes, using the datastores API.

Sample ode for reference.

Can CPU shares be changed during cloning process?

Yes.

Sample code for reference.

How can QueryEvent API be used with VMware ESX?

The QueryEvent API works with VirtualCenter only and is not supported by VMware ESX.

Sample code for reference.

Version history
Revision #:
1 of 1
Last update:
‎08-22-2008 12:53 PM
Updated by: