77"""
88import datetime
99import itertools
10+ import logging
11+ import random
1012import socket
1113import time
1214import warnings
1315
1416from SoftLayer import exceptions
1517from SoftLayer .managers import ordering
1618from SoftLayer import utils
19+
20+ LOGGER = logging .getLogger (__name__ )
1721# pylint: disable=no-self-use
1822
1923
@@ -392,23 +396,20 @@ def _generate_create_dict(
392396
393397 return data
394398
395- def wait_for_transaction (self , instance_id , limit , delay = 1 ):
399+ def wait_for_transaction (self , instance_id , limit , delay = 10 ):
396400 """Waits on a VS transaction for the specified amount of time.
397401
398402 This is really just a wrapper for wait_for_ready(pending=True).
399403 Provided for backwards compatibility.
400404
401-
402405 :param int instance_id: The instance ID with the pending transaction
403406 :param int limit: The maximum amount of time to wait.
404- :param int delay: The number of seconds to sleep before checks.
405- Defaults to 1.
407+ :param int delay: The number of seconds to sleep before checks. Defaults to 10.
406408 """
407409
408- return self .wait_for_ready (instance_id , limit , delay = delay ,
409- pending = True )
410+ return self .wait_for_ready (instance_id , limit , delay = delay , pending = True )
410411
411- def wait_for_ready (self , instance_id , limit , delay = 1 , pending = False ):
412+ def wait_for_ready (self , instance_id , limit , delay = 10 , pending = False ):
412413 """Determine if a VS is ready and available.
413414
414415 In some cases though, that can mean that no transactions are running.
@@ -420,8 +421,7 @@ def wait_for_ready(self, instance_id, limit, delay=1, pending=False):
420421
421422 :param int instance_id: The instance ID with the pending transaction
422423 :param int limit: The maximum amount of time to wait.
423- :param int delay: The number of seconds to sleep before checks.
424- Defaults to 1.
424+ :param int delay: The number of seconds to sleep before checks. Defaults to 10.
425425 :param bool pending: Wait for pending transactions not related to
426426 provisioning or reloads such as monitoring.
427427
@@ -435,36 +435,37 @@ def wait_for_ready(self, instance_id, limit, delay=1, pending=False):
435435 mask = """id,
436436 lastOperatingSystemReload.id,
437437 activeTransaction.id,provisionDate"""
438- instance = self .get_instance (new_instance , mask = mask )
439- last_reload = utils .lookup (instance ,
440- 'lastOperatingSystemReload' ,
441- 'id' )
442- active_transaction = utils .lookup (instance ,
443- 'activeTransaction' ,
444- 'id' )
445-
446- reloading = all ((
447- active_transaction ,
448- last_reload ,
449- last_reload == active_transaction ,
450- ))
451-
452- # only check for outstanding transactions if requested
453- outstanding = False
454- if pending :
455- outstanding = active_transaction
456-
457- # return True if the instance has finished provisioning
458- # and isn't currently reloading the OS.
459- if all ([instance .get ('provisionDate' ),
460- not reloading ,
461- not outstanding ]):
462- return True
438+ try :
439+ instance = self .get_instance (new_instance , mask = mask )
440+ last_reload = utils .lookup (instance , 'lastOperatingSystemReload' , 'id' )
441+ active_transaction = utils .lookup (instance , 'activeTransaction' , 'id' )
442+
443+ reloading = all ((
444+ active_transaction ,
445+ last_reload ,
446+ last_reload == active_transaction ,
447+ ))
448+
449+ # only check for outstanding transactions if requested
450+ outstanding = False
451+ if pending :
452+ outstanding = active_transaction
453+
454+ # return True if the instance has finished provisioning
455+ # and isn't currently reloading the OS.
456+ if all ([instance .get ('provisionDate' ),
457+ not reloading ,
458+ not outstanding ]):
459+ return True
460+ LOGGER .info ("%s not ready." , str (instance_id ))
461+ except exceptions .SoftLayerAPIError as exception :
462+ delay = (delay * 2 ) + random .randint (0 , 9 )
463+ LOGGER .info ('Exception: %s' , str (exception ))
463464
464465 now = time .time ()
465466 if now >= until :
466467 return False
467-
468+ LOGGER . info ( 'Auto retry in %s seconds' , str ( min ( delay , until - now )))
468469 time .sleep (min (delay , until - now ))
469470
470471 def verify_create_instance (self , ** kwargs ):
0 commit comments