#!/usr/bin/env python3
#
# Determine the duration of the iperf

import datetime
import sys

import pscheduler

from iperf2_defaults import *
from iperf2_utils import *

json = pscheduler.json_load(exit_on_error=True)['spec']

# Setup:  How long it takes to connect and set up the test
setup = setup_time(json.get('link-rtt'))

duration = json.get('duration', None)
if duration:
    delta = pscheduler.iso8601_as_timedelta(duration)
    duration = int(pscheduler.timedelta_as_seconds(delta))
else:
    duration = DEFAULT_DURATION

pscheduler.succeed_json({
        "duration": 'PT%dS' % (setup + duration + DEFAULT_WAIT_SLEEP + DEFAULT_SERVER_SHUTDOWN)
})

pscheduler.succeed()
