How to use a RUBY expression in a VM Filter?


#1

From the Infrastructure->Virtual machines,I want to define a custom filter to view all the VM that have at least one IP Adress.

So, I browse to Infrastructure->Virtual machines, then click on ‘VMs’ accordeon.

Then I specify a filter:

  • I select ‘Field’, then I choose the ‘Virtual Machine : IP Adresses’ field.
  • At that point, I have the choice for 4 operators: INCLUDE_ALL, INCLUDE_ANY, LIMITED_TO, RUBY. The former three seems not suitable, as they require to give a list of comma separated adresses. So I try RUBY.

I have tested three differents script:

  • script 1: The ruby code is: true
    The result is that I get all VMs, as expected.

  • script 2: The ruby code is: false.
    The result is that I get none VMs, as expected.

  • script 3: The ruby code will return true if the size of the IP Adresses is greater than 0.
    I tried the following code: (not ip_adresses.nil?) and ip_adresses.size > 0 But when applying the filter I get an exception that explain ip_adresses variable is undefined - I’m not really surprised.

What should my ruby script looks like to check whether the ‘IP Adresses’ field is empty or not ? I expect the “IP Adresses” to be an input parameter of my script, but how is it made known to the script I write ?