Exemplo n.º 1
0
retries = 0

# Run a dig in each Akamai ghost location and record the end IP address
# Only recording the first address as this is enough for region match
# Exponential backoff for bad repeated bad responses as API is rate limited
attempts = 0
#for num in range(0, location_count):
for num in range(0, 19):
    backoff = 2
    location = location_result['locations'][num]['id']
    while True:
        attempts += 1
        # sys.stdout.write("\r%d - %s               " % (num, location))
        # sys.stdout.flush()
        dig_result = httpCaller.getResultHeaders(
            "/diagnostic-tools/v2/ghost-locations/%s/dig-info" % location,
            apex_hostname)
        if dig_result['statuscode'] != 200:
            retries += 1
            backoff = backoff * 2
            sys.stdout.write(
                "\r%d - %s - Status Code: %s. Rate Limit Remaining: %s. Attempt: %s Retries: %s. Backoff %s"
                % (num, location, str(dig_result['statuscode']),
                   str(dig_result['ratelimit']), attempts, retries, backoff))
            sys.stdout.flush()
            time.sleep(backoff)
            continue
        elif dig_result['ratelimit'] is '0':
            retries += 1
            backoff = backoff * 2
            sys.stdout.write(