Revision 4fe43605 tools/move-instance

b/tools/move-instance
30 30
import time
31 31
import logging
32 32
import optparse
33
import random
33 34
import threading
34 35

  
35 36
from ganeti import cli
......
489 490
    # or failure
490 491
    creation_attempts.append(False)
491 492

  
493
    # Initiate the RNG for the variations
494
    random.seed()
495

  
492 496
    for is_attempt_opportunistic in creation_attempts:
493 497
      job_id = self._CreateInstance(dest_client, mrt.move.dest_instance_name,
494 498
                                    mrt.move.dest_pnode, mrt.move.dest_snode,
......
515 519
           err.args[1] != rapi.client.ECODE_TEMP_NORES:
516 520
          raise
517 521

  
518
      logging.info("Opportunistic attempt unsuccessful, waiting %d seconds"
522
      delay_to_use = MoveDestExecutor._VaryDelay(mrt)
523
      logging.info("Opportunistic attempt unsuccessful, waiting %.2f seconds"
519 524
                   " before another creation attempt is made",
520
                   mrt.move.opportunistic_delay)
521
      time.sleep(mrt.move.opportunistic_delay)
525
                   delay_to_use)
526
      time.sleep(delay_to_use)
527

  
528
  @staticmethod
529
  def _VaryDelay(mrt):
530
    """ Varies the opportunistic delay by a small amount.
531

  
532
    """
533
    MAX_VARIATION = 0.15
534
    variation_factor = (1.0 + random.uniform(-MAX_VARIATION, MAX_VARIATION))
535
    return mrt.move.opportunistic_delay * variation_factor
522 536

  
523 537
  @staticmethod
524 538
  def _SetImportInfo(mrt, impinfo):

Also available in: Unified diff