Sha256: f47e0b46f554e3f1590c5e83c632817f3e10a586fbb62aba234a6230e87c2d02

Contents?: true

Size: 1.96 KB

Versions: 14

Compression:

Stored size: 1.96 KB

Contents

module Fog
  module Linode
    class Compute < Fog::Service

      requires :linode_api_key

      model_path 'fog/linode/models/compute'

      request_path 'fog/linode/requests/compute'
      request :avail_datacenters
      request :avail_distributions
      request :avail_kernels
      request :avail_linodeplans
      request :avail_stackscripts
      request :linode_create
      request :linode_delete
      request :linode_list
      request :linode_reboot

      class Mock

        def self.data
          @data ||= Hash.new do |hash, key|
            hash[key] = {}
          end
        end

        def self.reset_data(keys=data.keys)
          for key in [*keys]
            data.delete(key)
          end
        end

        def initialize(options={})
          @linode_api_key = options[:linode_api_key]
          @data = self.class.data[@linode_api_key]
        end

      end

      class Real

        def initialize(options={})
          @linode_api_key = options[:linode_api_key]
          @host   = options[:host]    || "api.linode.com"
          @port   = options[:port]    || 443
          @scheme = options[:scheme]  || 'https'
          @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent])
        end

        def reload
          @connection.reset
        end

        def request(params)
          params[:query] ||= {}
          params[:query].merge!(:api_key => @linode_api_key)

          response = @connection.request(params.merge!({:host => @host}))

          unless response.body.empty?
            response.body = JSON.parse(response.body)
            if data = response.body['ERRORARRAY'].first
              error = case data['ERRORCODE']
              when 5
                Fog::Linode::Compute::NotFound
              else
                Fog::Linode::Compute::Error
              end
              raise error.new(data['ERRORMESSAGE'])
            end
          end
          response
        end

      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
fog-0.3.13 lib/fog/linode/compute.rb
fog-0.3.12 lib/fog/linode/compute.rb
fog-0.3.11 lib/fog/linode/compute.rb
fog-0.3.10 lib/fog/linode/compute.rb
fog-0.3.9 lib/fog/linode/compute.rb
fog-0.3.8 lib/fog/linode/compute.rb
fog-0.3.7 lib/fog/linode/compute.rb
fog-0.3.6 lib/fog/linode/compute.rb
fog-0.3.5 lib/fog/linode/compute.rb
fog-0.3.4 lib/fog/linode/compute.rb
fog-0.3.3 lib/fog/linode/compute.rb
fog-0.3.2 lib/fog/linode/compute.rb
fog-0.3.1 lib/fog/linode/compute.rb
fog-0.3.0 lib/fog/linode/compute.rb