Get vm id from IP

Hi there,

I’m doing some refactoring of the opennebula-metadata module, and would like to know what’s the quickest way to get the vmid, if having the IP address of a virtual machine.

Currently I’m doing as follows:

flags = OpenNebula::Pool::INFO_ALL || OpenNebula::VirtualMachinePool::INFO_NOT_DONE
vmpool =, flags)
vmpool.each do |vm|
   return if  vm["TEMPLATE/NIC/IP"] == ip

Transversing all the vmpool for every single attribute the metadata server returns is not something I consider a nice and efficient implementation.


I don’t think there is another way to do what you want. Pool info command does not allow you to filter by any column. You may make it faster filtering only VMs in ACTIVE state (3) as I suppose those are the only ones that will query the metadata server.

Instead of each loop you can also use xpath but I’m not sure it will be faster:[]-instance_method