Commit 0218b908 authored by Yingjie Xu's avatar Yingjie Xu

Delay a randomized period of time when initialize.

parent 5533c318
...@@ -57,6 +57,8 @@ import tempfile ...@@ -57,6 +57,8 @@ import tempfile
from time import strftime from time import strftime
import StringIO import StringIO
from lxml import etree from lxml import etree
from time import sleep
from random import random
MANDATORY_PARAMETER_LIST = [ MANDATORY_PARAMETER_LIST = [
...@@ -114,6 +116,8 @@ def parseArgumentTupleAndReturnSlapgridObject(*argument_tuple): ...@@ -114,6 +116,8 @@ def parseArgumentTupleAndReturnSlapgridObject(*argument_tuple):
help="Promise timeout in seconds.") help="Promise timeout in seconds.")
parser.add_argument("configuration_file", nargs=1, type=argparse.FileType(), parser.add_argument("configuration_file", nargs=1, type=argparse.FileType(),
help="SlapOS configuration file.") help="SlapOS configuration file.")
parser.add_argument("--maximal_delay", help="The maximal delay value in seconds. " \
"A negative value leads start immediately.")
# Parses arguments # Parses arguments
if argument_tuple == (): if argument_tuple == ():
...@@ -215,6 +219,13 @@ def parseArgumentTupleAndReturnSlapgridObject(*argument_tuple): ...@@ -215,6 +219,13 @@ def parseArgumentTupleAndReturnSlapgridObject(*argument_tuple):
else: else:
signature_certificate_list = None signature_certificate_list = None
maximal_delay = float(option_dict.get("maximal_delay", "300"))
if maximal_delay > 0:
duration = maximal_delay * random()
logging.info("Sleeping for %s seconds. To disable this feature, " \
"check maximal_delay parameter in manual." % duration)
time.sleep(duration)
# Returning new Slapgrid instance and options # Returning new Slapgrid instance and options
return ([Slapgrid(software_root=option_dict['software_root'], return ([Slapgrid(software_root=option_dict['software_root'],
instance_root=option_dict['instance_root'], instance_root=option_dict['instance_root'],
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment