visual2me
Enthusiast
Enthusiast

how to find a vm by its object id?

Jump to solution

is there any way to find a VM by its object id, just like the SearchIndex's findByInventoryPath? or how to implement it in an efficient way to find it by object id?

0 Kudos
1 Solution

Accepted Solutions
tmadam
Contributor
Contributor

You can use code as in http://communities.vmware.com/thread/130515 and just start by setting the ManagedObjectReference something like this:

ManagedObjectReference mor = new ManagedObjectReference("vm-114"); // the Value

mor.setType("VirtualMachine");

Tim.

View solution in original post

0 Kudos
6 Replies
admin
Immortal
Immortal

You can use SearchIndex's FindByUUID method. You can also restrict the query to a specific datacenter, by specifying the mor to the datacenter.

Each virtual machine is automatically assigned a universally unique identifier (UUID), which is stored in the SMBIOS system information descriptor. This UUID is generated when you power on or reset the virtual machine. As long as you do not move or copy the virtual machine to another location, the UUID remains constant.

0 Kudos
visual2me
Enthusiast
Enthusiast

thank you very much for your suggestion, but what i mean is how to find a vm by the object id of the managed object reference, just like "vm-114", rather than its UUID.

another thing that i want to make sure is whether this object id is unique among several data centers managed by one virtual center.

0 Kudos
tmadam
Contributor
Contributor

That ID, along with the type of VirtualMachine, makes up the ManagedObjectReference that is the handle to the object when talking to VC using the VI SDK. There is no need to look it up, you can access it directly. How you do that depends on which language binding of the SDK you are using.

Yes this ID will be unique on the VC. Note that unlike the UUID, this ID returned may be different depending on whether you are querying VC or ESX directly for that VM.

0 Kudos
visual2me
Enthusiast
Enthusiast

yeah, i have found that this id in fact is a column of the vm table used by VC or ESX to manage the VMs. This id does be different when the VM is managed by different hosts. But still I want to know how to get the managed ojbect and its properties by this id, for example, if i already hold this id in hand.

0 Kudos
tmadam
Contributor
Contributor

You can use code as in http://communities.vmware.com/thread/130515 and just start by setting the ManagedObjectReference something like this:

ManagedObjectReference mor = new ManagedObjectReference("vm-114"); // the Value

mor.setType("VirtualMachine");

Tim.

View solution in original post

0 Kudos
visual2me
Enthusiast
Enthusiast

thank you very much, i just didn't test this way:)

0 Kudos