Class: Fog::Linode::Real

Inherits:
Object
  • Object
show all
Includes:
Collections
Defined in:
lib/fog/linode.rb,
lib/fog/linode/requests/avail_kernels.rb,
lib/fog/linode/requests/avail_datacenters.rb,
lib/fog/linode/requests/avail_linodeplans.rb,
lib/fog/linode/requests/avail_distributions.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



40
41
42
43
44
45
46
# File 'lib/fog/linode.rb', line 40

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

Instance Method Details

#avail_datacentersObject

Get available data centers

Returns

  • response<~Excon::Response>:

    • body<~Array>:

TODO: docs



11
12
13
14
15
16
17
# File 'lib/fog/linode/requests/avail_datacenters.rb', line 11

def avail_datacenters
  request(
    :expects  => 200,
    :method   => 'GET',
    :query    => { :api_action => 'avail.datacenters' }
  )
end

#avail_distributions(options = {}) ⇒ Object

Get available distributions

Parameters

  • options<~Hash>:

    • distributionId<~Integer>: id to limit results to

Returns

  • response<~Excon::Response>:

    • body<~Array>:

TODO: docs



15
16
17
18
19
20
21
# File 'lib/fog/linode/requests/avail_distributions.rb', line 15

def avail_distributions(options={})
  request(
    :expects  => 200,
    :method   => 'GET',
    :query    => { :api_action => 'avail.distributions' }.merge!(options)
  )
end

#avail_kernels(options = {}) ⇒ Object

Get available kernels

Parameters

  • options<~Hash>:

    • kernelId<~Integer>: id to limit results to

    • isXen<~Integer>: if 1 limits results to only zen

Returns

  • response<~Excon::Response>:

    • body<~Array>:

TODO: docs



16
17
18
19
20
21
22
# File 'lib/fog/linode/requests/avail_kernels.rb', line 16

def avail_kernels(options={})
  request(
    :expects  => 200,
    :method   => 'GET',
    :query    => { :api_action => 'avail.kernels' }.merge!(options)
  )
end

#avail_linodeplansObject

Get available plans

Returns

  • response<~Excon::Response>:

    • body<~Array>:

TODO: docs



11
12
13
14
15
16
17
# File 'lib/fog/linode/requests/avail_linodeplans.rb', line 11

def avail_linodeplans
  request(
    :expects  => 200,
    :method   => 'GET',
    :query    => { :api_action => 'avail.linodeplans' }
  )
end

#reloadObject



48
49
50
# File 'lib/fog/linode.rb', line 48

def reload
  @connection.reset
end

#request(params) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/fog/linode.rb', line 52

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

  begin
    response = @connection.request(params.merge!({:host => @host}))
  rescue Excon::Errors::Error => error
    raise case error
    when Excon::Errors::NotFound
      Fog::Linode::NotFound.slurp(error)
    else
      error
    end
  end

  unless response.body.empty?
    response.body = JSON.parse(response.body)
  end
  response
end