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

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/compute/linode.rb,
lib/fog/compute/requests/linode/linode_boot.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/linode_update.rb,
lib/fog/compute/requests/linode/linode_ip_list.rb,
lib/fog/compute/requests/linode/linode_shutdown.rb,
lib/fog/compute/requests/linode/linode_disk_list.rb,
lib/fog/compute/requests/linode/stackscript_list.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/linode_config_list.rb,
lib/fog/compute/requests/linode/linode_disk_create.rb,
lib/fog/compute/requests/linode/linode_disk_delete.rb,
lib/fog/compute/requests/linode/avail_distributions.rb,
lib/fog/compute/requests/linode/linode_config_create.rb,
lib/fog/compute/requests/linode/linode_ip_addprivate.rb,
lib/fog/compute/requests/linode/linode_disk_createfromstackscript.rb,
lib/fog/compute/requests/linode/linode_disk_createfromdistribution.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



79
80
81
82
83
84
85
86
# File 'lib/fog/compute/linode.rb', line 79

def initialize(options={})
  require 'multi_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(kernel_id = nil) ⇒ Object

Get available kernels

Parameters

  • kernelId<~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_kernels.rb', line 15

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

#avail_linodeplans(linodeplan_id = nil) ⇒ Object

Get available plans

Parameters

  • linodeplanId<~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
26
27
28
29
# File 'lib/fog/compute/requests/linode/avail_linodeplans.rb', line 15

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)
  )
  
  #hack for plans not filtering by id like they should above, remove when they fix it.
  result.body["DATA"] = result.body["DATA"].select { |item| item['PLANID'] == linodeplan_id } if linodeplan_id
  result
end

#avail_stackscripts(options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/fog/compute/requests/linode/avail_stackscripts.rb', line 6

def avail_stackscripts(options={})
  result = request(
    :expects  => 200,
    :method   => 'GET',
    :query    => { :api_action => 'avail.stackscripts' }.merge!(options)
  )
  result.body['DATA'].each { |r| r['DISTRIBUTIONIDLIST'] = r['DISTRIBUTIONIDLIST'].to_s }
  result
end

#linode_boot(linode_id, config_id) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/fog/compute/requests/linode/linode_boot.rb', line 6

def linode_boot(linode_id, config_id)
  request(
    :expects => 200,
    :method => 'GET',
    :query => { :api_action => 'linode.boot', :linodeId => linode_id, :configId => config_id }
  )
end

#linode_config_create(linode_id, kernel_id, name, disk_list) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/fog/compute/requests/linode/linode_config_create.rb', line 6

def linode_config_create(linode_id, kernel_id, name, disk_list)
  request(
    :expects  => 200,
    :method   => 'GET',
    :query    => {
      :api_action => 'linode.config.create',
      :linodeId => linode_id,
      :kernelId => kernel_id,
      :label => name,
      :diskList => disk_list
    }
  )
end

#linode_config_list(linode_id, config_id = nil, options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/fog/compute/requests/linode/linode_config_list.rb', line 6

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

#linode_create(datacenter_id, plan_id, payment_term) ⇒ Object

Creates a linode and assigns you full privileges

Parameters

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

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

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

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, plan_id, payment_term)
  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_disk_create(linode_id, name, type, size) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/fog/compute/requests/linode/linode_disk_create.rb', line 6

def linode_disk_create(linode_id, name, type, size)
  request(
    :expects  => 200,
    :method   => 'GET',
    :query    => {
      :api_action => 'linode.disk.create',
      :linodeId => linode_id,
      :label => name,
      :type => type,
      :size => size
    }
  )
end

#linode_disk_createfromdistribution(linode_id, distro_id, name, size, password) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/fog/compute/requests/linode/linode_disk_createfromdistribution.rb', line 6

def linode_disk_createfromdistribution(linode_id, distro_id, name, size, password)
  request(
    :expects  => 200,
    :method   => 'GET',
    :query    => {
      :api_action => 'linode.disk.createfromdistribution',
      :linodeId => linode_id,
      :distributionId => distro_id,
      :label => name,
      :size => size,
      :rootPass => password
    }
  )
end

#linode_disk_createfromstackscript(linode_id, script_id, distro_id, name, size, password, options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/fog/compute/requests/linode/linode_disk_createfromstackscript.rb', line 6

def linode_disk_createfromstackscript(linode_id, script_id, distro_id, name, size, password, options={})
  request(
    :expects  => 200,
    :method   => 'GET',
    :query    => {
      :api_action => 'linode.disk.createfromstackscript',
      :linodeId => linode_id,
      :stackScriptID => script_id,
      :distributionId => distro_id,
      :label => name,
      :size => size,
      :rootPass => password,
      :stackScriptUDFResponses => MultiJson.encode(options)
    }
  )
end

#linode_disk_delete(linode_id, disk_id) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/fog/compute/requests/linode/linode_disk_delete.rb', line 6

def linode_disk_delete(linode_id, disk_id)
  request(
    :expects  => 200,
    :method   => 'GET',
    :query    => {
      :api_action => 'linode.disk.delete',
      :linodeId => linode_id,
      :diskId => disk_id
    }
  )
end

#linode_disk_list(linode_id, disk_id = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/fog/compute/requests/linode/linode_disk_list.rb', line 6

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

#linode_ip_addprivate(linode_id) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/fog/compute/requests/linode/linode_ip_addprivate.rb', line 6

def linode_ip_addprivate(linode_id)
  request(
    :expects  => 200,
    :method   => 'GET',
    :query    => { :api_action => 'linode.ip.addprivate', :linodeId => linode_id }
  )
end

#linode_ip_list(linode_id, ip_id = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/fog/compute/requests/linode/linode_ip_list.rb', line 6

def linode_ip_list(linode_id, ip_id=nil)
  options = {}
  if ip_id
    options.merge!(:ipaddressId => ip_id)
  end
  request(
    :expects  => 200,
    :method   => 'GET',
    :query    => { :api_action => 'linode.ip.list', :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

#linode_shutdown(linode_id) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/fog/compute/requests/linode/linode_shutdown.rb', line 6

def linode_shutdown(linode_id)
  request(
    :expects => 200,
    :method => 'GET',
    :query => { :api_action => 'linode.shutdown', :linodeId => linode_id }
  )
end

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



6
7
8
9
10
11
12
# File 'lib/fog/compute/requests/linode/linode_update.rb', line 6

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

#reloadObject



88
89
90
# File 'lib/fog/compute/linode.rb', line 88

def reload
  @connection.reset
end

#request(params) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/fog/compute/linode.rb', line 92

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 = MultiJson.decode(response.body)
    if data = response.body['ERRORARRAY'].first
      error = case data['ERRORCODE']
      when 5
        Fog::Compute::Linode::NotFound
      else
        Fog::Compute::Linode::Error
      end
      raise error.new(data['ERRORMESSAGE'])
    end
  end
  response
end

#stackscript_list(script_id = nil) ⇒ Object

Get available stack scripts

Parameters

  • scriptId<~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
26
27
# File 'lib/fog/compute/requests/linode/stackscript_list.rb', line 15

def stackscript_list(script_id=nil)
  options = {}
  if script_id
    options.merge!(:stackScriptID => script_id)
  end          
  result = request(
    :expects  => 200,
    :method   => 'GET',
    :query    => { :api_action => 'stackscript.list' }.merge!(options)
  )
  result.body['DATA'].each { |r| r['DISTRIBUTIONIDLIST'] = r['DISTRIBUTIONIDLIST'].to_s }
  result
end