in ec2-spot-duration/get_spot_duration.py [0:0]
def get_last_spot_price_exceeding_the_bid(profile, hours, inst_type, region, product, bid):
now = datetime.datetime.utcfromtimestamp(time.time())
start_time = now - datetime.timedelta(hours=hours)
start_time_unix = calendar.timegm(start_time.utctimetuple())
#: :type: list of SpotPriceHistory
res = make_call(["ec2", "--region", region,
"describe-spot-price-history",
"--start-time", start_time.isoformat(),
"--end-time", now.isoformat(),
"--instance-types", inst_type,
"--product-descriptions", product], profile)
last_times = {}
for p in res['SpotPriceHistory']:
cur_ts = iso_to_unix_time(p['Timestamp'])
cur_az = p['AvailabilityZone']
old_ts = last_times.get((inst_type, cur_az), None)
if old_ts is None:
last_times[(inst_type, cur_az)] = old_ts = start_time_unix
if float(p['SpotPrice']) > bid and cur_ts > old_ts:
last_times[(inst_type, cur_az)] = cur_ts
return last_times