Beispiel #1
0
        /// <summary>
        /// Retrieves a list of prices for the instance type received,
        /// respecting the history size parameter.
        /// </summary>
        /// <param name="instanceTypes">Type (T2.Medium, C4.XLarge...)</param>
        /// <param name="historySize">Number of prices</param>
        /// <returns>List of object containing Price, Timestamp and Description</returns>
        public List <EC2SpotPrice> GetSpotRequestPrices(String instanceType, String AZ, String productDescription = null, int historySize = 1)
        {
            // Building Requests
            var spotPriceRequest = new DescribeSpotPriceHistoryRequest();

            spotPriceRequest.MaxResults    = historySize;
            spotPriceRequest.InstanceTypes = new List <String>()
            {
                instanceType
            };
            spotPriceRequest.AvailabilityZone    = AZ;
            spotPriceRequest.ProductDescriptions = new List <String>()
            {
                productDescription
            };

            // Retrieving Spot Prices
            var response = EC2client.DescribeSpotPriceHistory(spotPriceRequest);

            //response.SpotPriceHistory.Select(t => t.ProductDescription.;
            return(response.SpotPriceHistory.Select(t => new EC2SpotPrice()
            {
                price = float.Parse(t.Price),
                productDescription = t.ProductDescription.Value.Replace(".", ","),
                timestamp = t.Timestamp
            }).ToList());
        }
Beispiel #2
0
        public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems)
        {
            AmazonEC2Config config = new AmazonEC2Config();

            config.RegionEndpoint = region;
            ConfigureClient(config);
            AmazonEC2Client client = new AmazonEC2Client(creds, config);

            DescribeSpotPriceHistoryResponse resp = new DescribeSpotPriceHistoryResponse();

            do
            {
                DescribeSpotPriceHistoryRequest req = new DescribeSpotPriceHistoryRequest
                {
                    NextToken = resp.NextToken
                    ,
                    MaxResults = maxItems
                };

                resp = client.DescribeSpotPriceHistory(req);
                CheckError(resp.HttpStatusCode, "200");

                foreach (var obj in resp.SpotPriceHistory)
                {
                    AddObject(obj);
                }
            }while (!string.IsNullOrEmpty(resp.NextToken));
        }
Beispiel #3
0
        /// <summary>
        /// Query the market for product spot pricing.
        /// </summary>
        protected override void AmazonExecute()
        {
            var request = new DescribeSpotPriceHistoryRequest
            {
                InstanceType = new List <string> {
                    this.InstanceType.Get(this.ActivityContext)
                },
                ProductDescription = new List <string> {
                    this.ProductDescription.Get(this.ActivityContext)
                },
                StartTime = DateTime.Now.ToAmazonDateTime(),
            };

            try
            {
                var response = EC2Client.DescribeSpotPriceHistory(request);

                // Get the first price in the price history array
                decimal price = decimal.Parse(response.DescribeSpotPriceHistoryResult.SpotPriceHistory[0].SpotPrice);
                this.CurrentSpotPrice.Set(this.ActivityContext, price);
            }
            catch (EndpointNotFoundException ex)
            {
                LogBuildMessage(ex.Message);
            }
        }
Beispiel #4
0
 public decimal load_spot_price(string instance_type, string az)
 {
     try
     {
         var client    = get_client();
         var query_req = new DescribeSpotPriceHistoryRequest();
         query_req.InstanceTypes.Add(instance_type);
         query_req.AvailabilityZone = region + az;
         query_req.ProductDescriptions.Add("Linux/UNIX");
         query_req.StartTime  = DateTime.Now;
         query_req.MaxResults = 1;
         var query_res = client.DescribeSpotPriceHistory(query_req);
         if (query_res.SpotPriceHistory.Count == 0)
         {
             write_log(region + az + " にはスポットインスタンスがありません。");
             return(10000);
         }
         write_log(region + az + " のスポットインスタンスの現在の値段 " + query_res.SpotPriceHistory[0].Price);
         return(Convert.ToDecimal(query_res.SpotPriceHistory[0].Price));
     }
     catch (Exception ex)
     {
         write_log("ERROR: " + ex.ToString());
         return(10000);
     }
 }
Beispiel #5
0
        /// <summary>
        /// Query EC2 for the spot pricing history for a specified instance type.
        /// </summary>
        protected override void AmazonExecute()
        {
            var request = new DescribeSpotPriceHistoryRequest
            {
                InstanceType = new List <string> {
                    this.InstanceType.Get(this.ActivityContext)
                },
                StartTime = this.StartTime.Get(this.ActivityContext).ToAmazonDateTime(),
                EndTime   = this.EndTime.Get(this.ActivityContext).ToAmazonDateTime()
            };

            try
            {
                var response = EC2Client.DescribeSpotPriceHistory(request);
                this.PriceHistory.Set(this.ActivityContext, response.DescribeSpotPriceHistoryResult.SpotPriceHistory);
            }
            catch (EndpointNotFoundException ex)
            {
                this.LogBuildMessage(ex.Message);
            }
        }