[openstack-dev] [automaton] How to extend automaton?

Kwan, Louie Louie.Kwan at windriver.com
Tue Feb 13 19:55:11 UTC 2018


https://github.com/openstack/automaton

Friendly state machines for python.



A few questions about automaton.



1.       I would like to know can we addition parameters on on_enter or on_exit callbacks. Right now, it  seems it  only allows  state and triggered_event.

a.       I have many FSM running for different objects and it is much easier if I can pass on the some sort of ID back to the callbacks.

2.       Can we or how can we store extra attribute like last state change timestamp?

3.       Can we store additional identify info for the FSM object? Would like to add an UUID





Thanks.

Louie



def print_on_enter(new_state, triggered_event):

   print("Entered '%s' due to '%s'" % (new_state, triggered_event))





def print_on_exit(old_state, triggered_event):

   print("Exiting '%s' due to '%s'" % (old_state, triggered_event))



# This will contain all the states and transitions that our machine will

# allow, the format is relatively simple and designed to be easy to use.

state_space = [

    {

        'name': 'stopped',

        'next_states': {

            # On event 'play' transition to the 'playing' state.

            'play': 'playing',

            'open_close': 'opened',

            'stop': 'stopped',

        },

        'on_enter': print_on_enter,

        'on_exit': print_on_exit,

    },
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack-dev/attachments/20180213/c4440745/attachment.html>


More information about the OpenStack-dev mailing list