Move NodeRole on_<state> handling to the after_commit hook.

This lets the on_<state> hooks run after all the relavent node role
state graph changes have been saved and committed, which ensures that
they all see the graph in a state that is consistent with how they were
called.  It also allows the hooks to do things (like allocating IP
addresses) that need exclusive table access without risking a nested
transaction related deadlock.