private Machine.State waitForMachineState(
     final IComputeService computeService,
     final ProviderTarget target,
     final String machineId,
     final int seconds,
     final Machine.State... expectedStates)
     throws Exception {
   int tries = seconds;
   while (tries-- > 0) {
     Machine.State machineState = computeService.getMachineState(machineId, target);
     if (machineState == Machine.State.ERROR) {
       throw new Exception("Machine state ERROR");
     }
     for (Machine.State expectedFinalState : expectedStates) {
       if (machineState == expectedFinalState) {
         return machineState;
       }
     }
     Thread.sleep(1000);
   }
   throw new Exception("Timeout waiting for Machine state transition");
 }