Class: Fog::Linode::Compute::Real

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/compute/linode.rb,
lib/fog/compute/requests/linode/linode_list.rb,
lib/fog/compute/requests/linode/avail_kernels.rb,
lib/fog/compute/requests/linode/linode_create.rb,
lib/fog/compute/requests/linode/linode_delete.rb,
lib/fog/compute/requests/linode/linode_reboot.rb,
lib/fog/compute/requests/linode/avail_datacenters.rb,
lib/fog/compute/requests/linode/avail_linodeplans.rb,
lib/fog/compute/requests/linode/avail_stackscripts.rb,
lib/fog/compute/requests/linode/avail_distributions.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



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

def initialize(options={})
  unless options.delete(:provider)
    location = caller.first
    warning = "[yellow][WARN] Fog::Linode::Compute.new is deprecated, use Fog::Compute.new(:provider => 'Linode') instead[/]"
    warning << " [light_black](" << location << ")[/] "
    Formatador.display_line(warning)
  end

  require 'json'
  @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



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

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

#avail_distributions(distribution_id = nil) ⇒ Object

Get available distributions

Parameters

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

Returns

  • response<~Excon::Response>:

    • body<~Array>:

TODO: docs



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

def avail_distributions(distribution_id=nil)
  options = {}
  if distribution_id
    options.merge!(:distributionId => distribution_id)
  end
  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



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

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

#avail_linodeplans(linodeplan_id = nil) ⇒ Object

Get available plans

Returns

  • response<~Excon::Response>:

    • body<~Array>:

TODO: docs



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/fog/compute/requests/linode/avail_linodeplans.rb', line 12

def avail_linodeplans(linodeplan_id = nil)
  options = {}
  if linodeplan_id
    options.merge!(:planId => linodeplan_id)
  end
  request(
    :expects  => 200,
    :method   => 'GET',
    :query    => { :api_action => 'avail.linodeplans' }.merge!(options)
  )
end

#avail_stackscripts(options = {}) ⇒ Object

Get available stack scripts

Parameters

  • options<~Hash>:

    • distributionId<~Integer>: Limit the results to Stackscripts that can be applied to this distribution id

    • distributionVendor<~String>: Debian, Ubuntu, Fedora, etc.

    • keywords<~String>: Search terms

Returns

  • response<~Excon::Response>:

    • body<~Array>:

TODO: docs



18
19
20
21
22
23
24
# File 'lib/fog/compute/requests/linode/avail_stackscripts.rb', line 18

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

#linode_create(datacenter_id, payment_term, plan_id) ⇒ Object

Creates a linode and assigns you full privileges

Parameters

  • datacenter_id<~Integer>: id of datacenter to place new linode in

  • payment_term<~Integer>: Subscription term in months, in [1, 12, 24]

  • plan_id<~Integer>: id of plan to boot new linode with

Returns

  • response<~Excon::Response>:

    • body<~Array>:

TODO: docs



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fog/compute/requests/linode/linode_create.rb', line 17

def linode_create(datacenter_id, payment_term, plan_id)
  request(
    :expects  => 200,
    :method   => 'GET',
    :query    => {
      :api_action   => 'linode.create',
      :datacenterId => datacenter_id,
      :paymentTerm  => payment_term,
      :planId       => plan_id
    }
  )
end

#linode_delete(linode_id, options = {}) ⇒ Object

List all linodes user has access or delete to

Parameters

  • linode_id<~Integer>: id of linode to delete

  • options<~Hash>:

    • skipChecks<~Boolean>: skips safety checks and always deletes

Returns

  • response<~Excon::Response>:

    • body<~Array>:

TODO: docs



17
18
19
20
21
22
23
# File 'lib/fog/compute/requests/linode/linode_delete.rb', line 17

def linode_delete(linode_id, options={})
  request(
    :expects  => 200,
    :method   => 'GET',
    :query    => { :api_action => 'linode.delete', :linodeId => linode_id }.merge!(options)
  )
end

#linode_list(linode_id = nil) ⇒ Object

List all linodes user has access or delete to

Parameters

  • linodeId<~Integer>: Limit the list to the specified LinodeID

Returns

  • response<~Excon::Response>:

    • body<~Array>:

TODO: docs



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fog/compute/requests/linode/linode_list.rb', line 15

def linode_list(linode_id=nil)
  options = {}
  if linode_id
    options.merge!(:linodeId => linode_id)
  end
  request(
    :expects  => 200,
    :method   => 'GET',
    :query    => { :api_action => 'linode.list' }.merge!(options)
  )
end

#linode_reboot(linode_id, options = {}) ⇒ Object

Issues a shutdown, and then a boot job for a given linode

Parameters

  • linode_id<~Integer>: id of linode to reboot

  • options<~Hash>:

    • configId<~Boolean>: id of config to boot server with

Returns

  • response<~Excon::Response>:

    • body<~Array>:

TODO: docs



17
18
19
20
21
22
23
# File 'lib/fog/compute/requests/linode/linode_reboot.rb', line 17

def linode_reboot(linode_id, options={})
  request(
    :expects  => 200,
    :method   => 'GET',
    :query    => { :api_action => 'linode.reboot', :linodeId => linode_id }.merge!(options)
  )
end

#reloadObject



72
73
74
# File 'lib/fog/compute/linode.rb', line 72

def reload
  @connection.reset
end

#request(params) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/fog/compute/linode.rb', line 76

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