How to maintain stateful data through state retries?


#1

I’m implementing a control policy that reacts to “VM settings change” events. It tracks changes of the VM ‘annotation’ (it corresponds to the “description” field in RHEV-M), parses it, then tags the VM accordingly. The problem I’m faced with is that reading the ‘annotation’ in response to the event, I get an out-to-date value. In fact the new value is available only after a while. From measurement I made, the delay varies from about 30 s to 5 minutes.

To circumvent the problem, I delay the reading of the annotation by managing a retry in my automaton, with a 6 minutes delay. I would like to improve the automaton by looping on shorter retries (say with e.g. 30 s delays) until I detect the change. This requires to retain the value of ‘annotation’ from a retry to the next, so that to compare them and detect the change. But I’m a newbie with ManageIQ, and I don’t know how to do it.


#2

See Persistent state data through retries here http://www.johnmark.org/blog/

  • state_var_exist?(var_name)
  • set_state_var(var_name, value)
  • get_state_var(var_name)

Example:

if $evm.state_var_exist?("test_data")
    test_data = $evm.get_state_var("test_data")
    # TODO: Something interesting
else
    # First time through, initialize data
    $evm.set_state_var("test_data", 1)
end

#3

Thanks, exactly what I need. I can now detect the change earlyer and more safely.

Is there somewhere some documentation on $evm?

I have read the “CloudForms Management Engine 5.3 Methods Available for Automation” document, but it does not say anything about it.