File: describe_reserved_instances_offerings.rb

package info (click to toggle)
ruby-fog-aws 3.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 8,092 kB
  • sloc: ruby: 72,795; javascript: 14; makefile: 9; sh: 4
file content (84 lines) | stat: -rw-r--r-- 4,286 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
module Fog
  module AWS
    class Compute
      class Real
        require 'fog/aws/parsers/compute/describe_reserved_instances_offerings'

        # Describe all or specified reserved instances offerings
        #
        # ==== Parameters
        # * filters<~Hash> - List of filters to limit results with
        #   * filters and/or the following
        #     * 'AvailabilityZone'<~String> - availability zone of offering
        #     * 'InstanceType'<~String> - instance type of offering
        #     * 'InstanceTenancy'<~String> - tenancy of offering in ['default', 'dedicated']
        #     * 'OfferingType'<~String> - type of offering, in ['Heavy Utilization', 'Medium Utilization', 'Light Utilization']
        #     * 'ProductDescription'<~String> - description of offering, in ['Linux/UNIX', 'Linux/UNIX (Amazon VPC)', 'Windows', 'Windows (Amazon VPC)']
        #     * 'MaxDuration'<~Integer> - maximum duration (in seconds) of offering
        #     * 'MinDuration'<~Integer> - minimum duration (in seconds) of offering
        #     * 'MaxResults'<~Integer> - The maximum number of results to return for the request in a single page
        #     * 'NextToken'<~String> - The token to retrieve the next page of results
        #
        # ==== Returns
        # * response<~Excon::Response>:
        #   * body<~Hash>:
        #     * 'requestId'<~String> - Id of request
        #     * 'reservedInstancesOfferingsSet'<~Array>:
        #       * 'availabilityZone'<~String> - availability zone of offering
        #       * 'duration'<~Integer> - duration, in seconds, of offering
        #       * 'fixedPrice'<~Float> - purchase price of offering
        #       * 'includeMarketplace'<~Boolean> - whether or not to include marketplace offerings
        #       * 'instanceType'<~String> - instance type of offering
        #       * 'offeringType'<~String> - type of offering, in ['Heavy Utilization', 'Medium Utilization', 'Light Utilization']
        #       * 'productDescription'<~String> - description of offering
        #       * 'reservedInstancesOfferingId'<~String> - id of offering
        #       * 'usagePrice'<~Float> - usage price of offering, per hour
        #     * 'NextToken'<~String> - The token to retrieve the next page of results
        #
        # {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeReservedInstancesOfferings.html]
        def describe_reserved_instances_offerings(filters = {})
          options = {}
          for key in %w(AvailabilityZone InstanceType InstanceTenancy OfferingType ProductDescription MaxDuration MinDuration MaxResults NextToken)
            if filters.is_a?(Hash) && filters.key?(key)
              options[key] = filters.delete(key)
            end
          end
          params = Fog::AWS.indexed_filters(filters).merge!(options)
          request({
            'Action'    => 'DescribeReservedInstancesOfferings',
            :idempotent => true,
            :parser     => Fog::Parsers::AWS::Compute::DescribeReservedInstancesOfferings.new
          }.merge!(params))
        end
      end

      class Mock
        def describe_reserved_instances_offerings(filters = {})
          response = Excon::Response.new
          response.status = 200

          self.data[:reserved_instances_offerings] ||= [{
            'reservedInstancesOfferingId' => Fog::AWS::Mock.reserved_instances_offering_id,
            'instanceType'                => 'm1.small',
            'availabilityZone'            => 'us-east-1d',
            'duration'                    => 31536000,
            'fixedPrice'                  => 350.0,
            'offeringType'                => 'Medium Utilization',
            'usagePrice'                  => 0.03,
            'productDescription'          => 'Linux/UNIX',
            'instanceTenancy'             => 'default',
            'currencyCode'                => 'USD'
          }]

          response.body = {
            'reservedInstancesOfferingsSet' => self.data[:reserved_instances_offerings],
            'requestId' => Fog::AWS::Mock.request_id,
            'nextToken' => (0...64).map { ('a'..'z').to_a[rand(26)] }.join
          }

          response
        end
      end
    end
  end
end