Worker State Machine

digraph rug {
  // rankdir=LR;

  node [shape = rectangle];
  START;

  // These nodes enter and exit the state machine.

  node [shape = doublecircle];
  EXIT;
  CALC_ACTION;

  node [shape = circle];

  START -> CALC_ACTION;

  CALC_ACTION -> ALIVE [ label = "ACT>[CRUP],vm:[UC]" ];
  CALC_ACTION -> CREATE_VM [ label = "ACT>[CRUP],vm:D" ];
  CALC_ACTION -> CHECK_BOOT [ label = "ACT>[CRUP],vm:B" ];
  CALC_ACTION -> REBUILD_VM [ label = "ACT:E" ];
  CALC_ACTION -> STOP_VM [ label = "ACT>D or vm:G" ];
  CALC_ACTION -> CLEAR_ERROR [ label = "vm:E" ];

  ALIVE -> CREATE_VM [ label = "vm>D" ];
  ALIVE -> CONFIG [ label = "ACT:[CU],vm:[UC]" ];
  ALIVE -> STATS [ label = "ACT:R,vm:C" ];
  ALIVE -> CALC_ACTION [ label = "ACT:P,vm>[UC]" ];
  ALIVE -> STOP_VM [ label = "vm:G" ];

  CREATE_VM -> CHECK_BOOT [ label = "ACT:[CRUDP],vm:[DBUCR]" ];
  CREATE_VM -> STOP_VM [ label = "vm:G" ];
  CREATE_VM -> CALC_ACTION [ label = "vm:E" ];
  CREATE_VM -> CREATE_VM [ label = "vm:D" ];

  CHECK_BOOT -> CONFIG [ label = "vm>U" ];
  CHECK_BOOT -> CALC_ACTION [ label = "vm:[BCR]" ];
  CHECK_BOOT -> STOP_VM [ label = "vm:[DG]" ];

  CONFIG -> STATS [ label = "ACT:R,vm>C" ];
  CONFIG -> CALC_ACTION [ label = "ACT>P,vm>C" ];
  CONFIG -> REPLUG_VM [ label = "vm>[H]" ];
  CONFIG -> STOP_VM [ label = "vm>[RDG]" ];

  REPLUG_VM -> CONFIG [ label = "vm>[H]" ];
  REPLUG_VM -> STOP_VM [ label = "vm>[R]" ];

  STATS -> CALC_ACTION [ label = "ACT>P" ];

  CLEAR_ERROR -> CALC_ACTION [ label = "no pause before next action" ];

  REBUILD_VM -> REBUILD_VM [ label = "vm!=[DG]" ];
  REBUILD_VM -> CREATE_VM [ label = "ACT:E,vm:D" ];

  STOP_VM -> CREATE_VM [ label = "ACT:E or vm>D" ];
  STOP_VM -> EXIT [ label = "ACT:D,vm>D or vm:G" ];

}

States

CALC_ACTION:Coalesces the pending actions from the queue inside the state machine.
ALIVE:Checks whether the instance is alive.
CLEAR_ERROR:Clear the error status before attempting any further operation.
STATS:Reads traffic data from the router.
CREATE_VM:Makes a new VM instance.
CHECKBOOT:Check if a new VM instance has been booted and initially configured.
CONFIG:Configures the VM and its services.
REPLUG_VM:Attempts to replug the VM with a new network (or remove an unplugged one).
STOP_VM:Terminates a running VM.
EXIT:Processing stops.

ACT(ion) Variable

Create:Create router was requested.
Read:Read router traffic stats.
Update:Update router configuration.
Delete:Delete router.
Poll:Poll router alive status.
rEbuild:Recreate a router from scratch.

vm Variable

Down:VM is known to be down.
Booting:VM is booting.
Up:VM is known to be up (pingable).
Configured:VM is known to be configured.
Restart Needed:VM needs to be rebooted.
Hotplug Needed:VM needs to be replugged.
Gone:The router definition has been removed from neutron.
Error:The router has been rebooted too many times, or has had some other error.