def viewPoolPrices(request, poolid): pool = get_object_or_404(InstancePool, pk=poolid) config = pool.config.flatten() prices = { instance_type: get_spot_prices(config.ec2_allowed_regions, config.aws_access_key_id, config.aws_secret_access_key, instance_type) for instance_type in config.ec2_instance_types } zones = set() latest_price_by_zone = {} for instance_type in prices: for region in prices[instance_type]: for zone in prices[instance_type][region]: zones.add(zone) latest_price_by_zone[zone] = min( latest_price_by_zone.get(zone, 9999), prices[instance_type][region][zone][0]) prices = [] for zone in sorted(zones): prices.append((zone, latest_price_by_zone[zone])) return render(request, 'pools/prices.html', {'prices': prices})
def get_best_region_zone(self, config): prices = get_spot_prices(config.ec2_allowed_regions, config.aws_access_key_id, config.aws_secret_access_key, config.ec2_instance_type) # Calculate median values for all availability zones and best zone/price best_zone = None best_region = None best_median = None rejected_prices = {} for region in prices: for zone in prices[region]: # Do not consider a zone/region combination that has a current # price higher than the maximum price we are willing to pay, # even if the median would end up being lower than our maximum. if prices[region][zone][0] > config.ec2_max_price: rejected_prices[zone] = prices[region][zone][0] continue median = get_price_median(prices[region][zone]) if best_median == None or best_median > median: best_median = median best_zone = zone best_region = region return (best_region, best_zone, rejected_prices)
def viewPoolPrices(request, poolid): pool = get_object_or_404(InstancePool, pk=poolid) config = pool.config.flatten() prices = get_spot_prices(config.ec2_allowed_regions, config.aws_access_key_id, config.aws_secret_access_key, config.ec2_instance_type) zones = [] latest_price_by_zone = {} for region in prices: for zone in prices[region]: zones.append(zone) latest_price_by_zone[zone] = prices[region][zone][0] prices = [] for zone in sorted(zones): prices.append((zone, latest_price_by_zone[zone])) return render(request, 'pools/prices.html', { 'prices' : prices })