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

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/linode/compute.rb,
lib/fog/linode/requests/compute/image_list.rb,
lib/fog/linode/requests/compute/linode_boot.rb,
lib/fog/linode/requests/compute/linode_list.rb,
lib/fog/linode/requests/compute/image_delete.rb,
lib/fog/linode/requests/compute/avail_kernels.rb,
lib/fog/linode/requests/compute/linode_create.rb,
lib/fog/linode/requests/compute/linode_delete.rb,
lib/fog/linode/requests/compute/linode_reboot.rb,
lib/fog/linode/requests/compute/linode_update.rb,
lib/fog/linode/requests/compute/linode_ip_list.rb,
lib/fog/linode/requests/compute/linode_shutdown.rb,
lib/fog/linode/requests/compute/linode_disk_list.rb,
lib/fog/linode/requests/compute/stackscript_list.rb,
lib/fog/linode/requests/compute/avail_datacenters.rb,
lib/fog/linode/requests/compute/avail_linodeplans.rb,
lib/fog/linode/requests/compute/avail_stackscripts.rb,
lib/fog/linode/requests/compute/linode_config_list.rb,
lib/fog/linode/requests/compute/linode_disk_create.rb,
lib/fog/linode/requests/compute/linode_disk_delete.rb,
lib/fog/linode/requests/compute/linode_disk_resize.rb,
lib/fog/linode/requests/compute/linode_disk_update.rb,
lib/fog/linode/requests/compute/avail_distributions.rb,
lib/fog/linode/requests/compute/linode_disk_imagize.rb,
lib/fog/linode/requests/compute/linode_config_create.rb,
lib/fog/linode/requests/compute/linode_config_delete.rb,
lib/fog/linode/requests/compute/linode_config_update.rb,
lib/fog/linode/requests/compute/linode_ip_addprivate.rb,
lib/fog/linode/requests/compute/linode_disk_duplicate.rb,
lib/fog/linode/requests/compute/linode_disk_createfromimage.rb,
lib/fog/linode/requests/compute/linode_disk_createfromstackscript.rb,
lib/fog/linode/requests/compute/linode_disk_createfromdistribution.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



86
87
88
89
90
91
92
# File 'lib/fog/linode/compute.rb', line 86

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::XML::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/compute/avail_datacenters.rb', line 11

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



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

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



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

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



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

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

#avail_stackscripts(options = {}) ⇒ Object



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

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

#image_delete(image_id) ⇒ Object



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

def image_delete(image_id)
  request(
    :expects  => 200,
    :method   => 'GET',
    :query    => {
      :api_action => 'image.delete',
      :imageId => image_id
    }
  )
end

#image_list(pending = nil, image_id = nil) ⇒ Object



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

def image_list(pending=nil, image_id=nil)
  options = {}
  if pending
    options.merge!(:pending => pending)
  end
  if image_id
    options.merge!(:imageId => image_id)
  end
  request(
    :expects  => 200,
    :method   => 'GET',
    :query    => { :api_action => 'image.list' }.merge!(options)
  )
end

#linode_boot(linode_id, config_id) ⇒ Object



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

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



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

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_delete(linode_id, config_id) ⇒ Object



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

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

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



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

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_config_update(linode_id, config_id, options = {}) ⇒ Object

api docs say LinodeID is optional, turns out its required



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

def linode_config_update(linode_id, config_id, options={})
  request(
    :expects  => 200,
    :method   => 'GET',
    :query    => { 
      :api_action => 'linode.config.update', 
      :configId => config_id,
      :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



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

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



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

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



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

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



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

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_createfromimage(linode_id, image_id, label, size, password, sshkey) ⇒ Object



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

def linode_disk_createfromimage(linode_id, image_id, label, size, password, sshkey)
  request(
    :expects  => 200,
    :method   => 'GET',
    :query    => {
      :api_action => 'linode.disk.createfromimage',
      :linodeId => linode_id,
      :imageId => image_id,
      :label => label,
      :size => size,
      :rootPass => password,
      :rootSSHKey => sshkey
    }
  )
end

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



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

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 => Fog::JSON.encode(options)
    }
  )
end

#linode_disk_delete(linode_id, disk_id) ⇒ Object



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

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_duplicate(linode_id, disk_id) ⇒ Object



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

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

#linode_disk_imagize(linode_id, disk_id, description, label) ⇒ Object



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

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

#linode_disk_list(linode_id, disk_id = nil) ⇒ Object



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

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_disk_resize(linode_id, disk_id, size) ⇒ Object



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

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

#linode_disk_update(linode_id, disk_id, label, isreadonly) ⇒ Object



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

def linode_disk_update(linode_id, disk_id, label, isreadonly)
  request(
    :expects  => 200,
    :method   => 'GET',
    :query    => {
      :api_action => 'linode.disk.update',
      :linodeId => linode_id,
      :diskId => disk_id,
      :label => label,
      :isReadOnly => isreadonly
    }
  )
end

#linode_ip_addprivate(linode_id) ⇒ Object



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

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



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

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



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

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



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

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



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

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



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

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

#reloadObject



94
95
96
# File 'lib/fog/linode/compute.rb', line 94

def reload
  @connection.reset
end

#request(params) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/fog/linode/compute.rb', line 98

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

  response = @connection.request(params)

  unless response.body.empty?
    response.body = Fog::JSON.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



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

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