Class: Fog::Compute::Linode::Real
- Inherits:
-
Object
- Object
- Fog::Compute::Linode::Real
- 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
-
#avail_datacenters ⇒ Object
Get available data centers.
-
#avail_distributions(distribution_id = nil) ⇒ Object
Get available distributions.
-
#avail_kernels(kernel_id = nil) ⇒ Object
Get available kernels.
-
#avail_linodeplans(linodeplan_id = nil) ⇒ Object
Get available plans.
- #avail_stackscripts(options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Real
constructor
A new instance of Real.
- #linode_boot(linode_id, config_id) ⇒ Object
- #linode_config_create(linode_id, kernel_id, name, disk_list) ⇒ Object
- #linode_config_list(linode_id, config_id = nil, options = {}) ⇒ Object
-
#linode_create(datacenter_id, plan_id, payment_term) ⇒ Object
Creates a linode and assigns you full privileges.
-
#linode_delete(linode_id, options = {}) ⇒ Object
List all linodes user has access or delete to.
- #linode_disk_create(linode_id, name, type, size) ⇒ Object
- #linode_disk_createfromdistribution(linode_id, distro_id, name, size, password) ⇒ Object
- #linode_disk_createfromstackscript(linode_id, script_id, distro_id, name, size, password, options = {}) ⇒ Object
- #linode_disk_delete(linode_id, disk_id) ⇒ Object
- #linode_disk_list(linode_id, disk_id = nil) ⇒ Object
- #linode_ip_addprivate(linode_id) ⇒ Object
- #linode_ip_list(linode_id, ip_id = nil) ⇒ Object
-
#linode_list(linode_id = nil) ⇒ Object
List all linodes user has access or delete to.
-
#linode_reboot(linode_id, options = {}) ⇒ Object
Issues a shutdown, and then a boot job for a given linode.
- #linode_shutdown(linode_id) ⇒ Object
- #linode_update(linode_id, options = {}) ⇒ Object
- #reload ⇒ Object
- #request(params) ⇒ Object
-
#stackscript_list(script_id = nil) ⇒ Object
Get available stack scripts.
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(={}) require 'multi_json' @linode_api_key = [:linode_api_key] @host = [:host] || "api.linode.com" @port = [:port] || 443 @scheme = [:scheme] || 'https' @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", [:persistent]) end |
Instance Method Details
#avail_datacenters ⇒ Object
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) = {} if distribution_id .merge!(:distributionId => distribution_id) end request( :expects => 200, :method => 'GET', :query => { :api_action => 'avail.distributions' }.merge!() ) 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) = {} if kernel_id .merge!(:kernelId => kernel_id) end request( :expects => 200, :method => 'GET', :query => { :api_action => 'avail.kernels' }.merge!() ) 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) = {} if linodeplan_id .merge!(:planId => linodeplan_id) end result = request( :expects => 200, :method => 'GET', :query => { :api_action => 'avail.linodeplans' }.merge!() ) #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(={}) result = request( :expects => 200, :method => 'GET', :query => { :api_action => 'avail.stackscripts' }.merge!() ) 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, ={}) if config_id .merge!(:configid => config_id) end request( :expects => 200, :method => 'GET', :query => { :api_action => 'linode.config.list', :linodeId => linode_id }.merge!() ) 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, ={}) request( :expects => 200, :method => 'GET', :query => { :api_action => 'linode.delete', :linodeId => linode_id }.merge!() ) 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, ={}) 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() } ) 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) = {} if disk_id .merge!(:diskId => disk_id) end request( :expects => 200, :method => 'GET', :query => { :api_action => 'linode.disk.list', :linodeId => linode_id }.merge!() ) 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) = {} if ip_id .merge!(:ipaddressId => ip_id) end request( :expects => 200, :method => 'GET', :query => { :api_action => 'linode.ip.list', :linodeId => linode_id }.merge!() ) 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) = {} if linode_id .merge!(:linodeId => linode_id) end request( :expects => 200, :method => 'GET', :query => { :api_action => 'linode.list' }.merge!() ) 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, ={}) request( :expects => 200, :method => 'GET', :query => { :api_action => 'linode.reboot', :linodeId => linode_id }.merge!() ) 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, ={}) request( :expects => 200, :method => 'GET', :query => { :api_action => 'linode.update', :linodeId => linode_id }.merge!() ) end |
#reload ⇒ Object
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) = {} if script_id .merge!(:stackScriptID => script_id) end result = request( :expects => 200, :method => 'GET', :query => { :api_action => 'stackscript.list' }.merge!() ) result.body['DATA'].each { |r| r['DISTRIBUTIONIDLIST'] = r['DISTRIBUTIONIDLIST'].to_s } result end |