def main():

    parser = OptionParser(usage="Usage: %prog [options]")
    parser.add_option("-d",
                      "--days",
                      dest="no_of_days",
                      type="int",
                      help="[REQUIRED] Number of days to run this script")
    parser.add_option("-t",
                      "--threads",
                      dest="no_of_threads",
                      default=1,
                      type="int",
                      help="Number of thread count")
    parser.add_option("-e",
                      "--execution",
                      dest="no_of_execution",
                      default=1000,
                      type="int",
                      help="Number of execution count")
    (options, args) = parser.parse_args()

    if options.no_of_days is None:
        options.no_of_days = int(
            raw_input('Enter number of days to run this script:'))

    if options.no_of_threads is None:
        options.no_of_threads = int(
            raw_input('Enter number of of thread count:'))

    if options.no_of_execution is None:
        options.no_of_execution = int(
            raw_input('Enter number of execution count:'))

    current_time = datetime.datetime.now()
    end_time = current_time + datetime.timedelta(days=options.no_of_days)

    system_requests = SystemRequests('fill')
    machine_config = Config()

    while datetime.datetime.now() < end_time:

        thread_list = []
        for i in range(0, options.no_of_threads):
            t = threading.Thread(target=execute,
                                 args=(
                                     system_requests,
                                     machine_config,
                                     options.no_of_execution,
                                 ))
            thread_list.append(t)

        for thread in thread_list:
            thread.start()

        for thread in thread_list:
            thread.join()
def main():

    parser = OptionParser(usage="Usage: %prog [options]")
    parser.add_option("-d",
                      "--days",
                      dest="no_of_days",
                      type="int",
                      help="[REQUIRED] Number of days to run this script")
    parser.add_option("-t",
                      "--threads",
                      dest="no_of_threads",
                      default=1,
                      type="int",
                      help="Number of thread count")
    parser.add_option("-e",
                      "--execution",
                      dest="no_of_execution",
                      default=1000,
                      type="int",
                      help="Number of execution count")
    (options, args) = parser.parse_args()

    if options.no_of_days is None:
        options.no_of_days = int(
            raw_input('Enter number of days to run this script:'))

    if options.no_of_threads is None:
        options.no_of_threads = int(
            raw_input('Enter number of of thread count:'))

    if options.no_of_execution is None:
        options.no_of_execution = int(
            raw_input('Enter number of execution count:'))

    current_time = datetime.datetime.now()
    end_time = current_time + datetime.timedelta(days=options.no_of_days)

    system_requests = SystemRequests('knox')
    machine_config = Config()

    user_list = machine_config.get('knox', 'user_list', 'sam,tom,admin')
    user_list = user_list.split(",")

    knox_services = ['WEBHDFS', 'WEBHCAT']

    while datetime.datetime.now() < end_time:

        thread_list = []
        for i in range(0, options.no_of_threads):
            for j in range(0, len(user_list)):
                for service in range(0, len(knox_services)):
                    t = threading.Thread(target=execute,
                                         args=(
                                             system_requests,
                                             machine_config,
                                             user_list[j],
                                             knox_services[service],
                                             options.no_of_execution,
                                         ))
                    thread_list.append(t)

        for thread in thread_list:
            thread.start()

        for thread in thread_list:
            thread.join()