Sha256: e990facbe01bed947e72ce5a000c4f4f7f79a67f19f8541494e4b44e4b169d83

Contents?: true

Size: 1.84 KB

Versions: 16

Compression:

Stored size: 1.84 KB

Contents

module Fog
  module Compute
    class Linode
      class Real
        # Get available plans
        #
        # ==== Parameters
        # * linodeplanId<~Integer>: id to limit results to
        #
        # ==== Returns
        # * response<~Excon::Response>:
        #   * body<~Array>:
        # TODO: docs
        def avail_linodeplans(linodeplan_id = nil)
          options = {}
          if linodeplan_id
            options.merge!(:planId => linodeplan_id)
          end
          result = request(
            :expects  => 200,
            :method   => 'GET',
            :query    => { :api_action => 'avail.linodeplans' }.merge!(options)
          )

          result
        end
      end

      class Mock
        def avail_linodeplans(linodeplan_id = nil)
          response = Excon::Response.new
          response.status = 200
          body = {
            "ERRORARRAY" => [],
            "ACTION" => "avail.linodeplans"
          }
          if linodeplan_id
            mock_plan = create_mock_linodeplan(linodeplan_id)
            response.body = body.merge("DATA" => [mock_plan])
          else
            mock_plans = []
            10.times do
              plan_id = rand(1..99)
              mock_plans << create_mock_linodeplan(plan_id)
            end
            response.body = body.merge("DATA" => mock_plans)
          end
          response
        end

        private

        def create_mock_linodeplan(linodeplan_id)
          { "PRICE" => 19.95, "RAM" => 512, "XFER" => 200,
            "PLANID" => linodeplan_id, "LABEL" => "Linode #{linodeplan_id}",
            "DISK" => 20,
            "CORES" => 1,
            "AVAIL" => {
              "2" => 500, "3" => 500, "4" => 500, "6" => 500, "7" => 500,
              "8" => 500, "9" => 500, "10" => 500
            },
            "HOURLY" => 0.03
          }
        end
      end
    end
  end
end

Version data entries

16 entries across 14 versions & 3 rubygems

Version Path
fog-2.3.0 lib/fog/linode/requests/compute/avail_linodeplans.rb
fog-ifeel-2.2.0 lib/fog/linode/requests/compute/avail_linodeplans.rb
fog-2.2.0 lib/fog/linode/requests/compute/avail_linodeplans.rb
fog-2.1.0 lib/fog/linode/requests/compute/avail_linodeplans.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/fog-1.42.1/lib/fog/linode/requests/compute/avail_linodeplans.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/gems/fog-1.42.1/lib/fog/linode/requests/compute/avail_linodeplans.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/fog-1.42.1/lib/fog/linode/requests/compute/avail_linodeplans.rb
fog-1.42.1 lib/fog/linode/requests/compute/avail_linodeplans.rb
fog-2.0.0 lib/fog/linode/requests/compute/avail_linodeplans.rb
fog-1.42.0 lib/fog/linode/requests/compute/avail_linodeplans.rb
fog-1.41.0 lib/fog/linode/requests/compute/avail_linodeplans.rb
fog-1.40.0 lib/fog/linode/requests/compute/avail_linodeplans.rb
fog-1.39.0 lib/fog/linode/requests/compute/avail_linodeplans.rb
fog-1.38.0 lib/fog/linode/requests/compute/avail_linodeplans.rb
fog-1.37.0 lib/fog/linode/requests/compute/avail_linodeplans.rb
fog-1.36.0 lib/fog/linode/requests/compute/avail_linodeplans.rb