2011-08-31 16:52:53 -04:00
|
|
|
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'linode'))
|
|
|
|
require 'fog/compute'
|
|
|
|
|
2010-09-08 13:56:38 -04:00
|
|
|
module Fog
|
2011-06-16 19:28:54 -04:00
|
|
|
module Compute
|
|
|
|
class Linode < Fog::Service
|
2010-09-08 13:56:38 -04:00
|
|
|
|
2010-12-16 18:31:24 -05:00
|
|
|
requires :linode_api_key
|
|
|
|
recognizes :port, :scheme, :persistent
|
2010-09-08 13:56:38 -04:00
|
|
|
|
2011-08-24 21:24:45 -04:00
|
|
|
model_path 'fog/linode/models/compute'
|
2011-02-28 16:25:38 -05:00
|
|
|
model :flavor
|
|
|
|
collection :flavors
|
|
|
|
model :image
|
|
|
|
collection :images
|
|
|
|
model :server
|
|
|
|
collection :servers
|
2011-03-01 11:34:29 -05:00
|
|
|
model :kernel
|
|
|
|
collection :kernels
|
2011-03-01 12:00:48 -05:00
|
|
|
model :data_center
|
|
|
|
collection :data_centers
|
2011-03-01 16:37:27 -05:00
|
|
|
model :stack_script
|
|
|
|
collection :stack_scripts
|
|
|
|
model :ip
|
|
|
|
collection :ips
|
2011-03-04 15:03:51 -05:00
|
|
|
model :disk
|
|
|
|
collection :disks
|
2010-09-08 13:56:38 -04:00
|
|
|
|
2011-08-24 21:24:45 -04:00
|
|
|
request_path 'fog/linode/requests/compute'
|
2010-09-08 13:56:38 -04:00
|
|
|
request :avail_datacenters
|
|
|
|
request :avail_distributions
|
|
|
|
request :avail_kernels
|
|
|
|
request :avail_linodeplans
|
|
|
|
request :avail_stackscripts
|
2011-03-04 15:03:51 -05:00
|
|
|
request :linode_disk_create
|
|
|
|
request :linode_disk_list
|
|
|
|
request :linode_disk_delete
|
|
|
|
request :linode_disk_createfromdistribution
|
2011-03-17 14:49:58 -04:00
|
|
|
request :linode_disk_createfromstackscript
|
2011-03-01 16:37:27 -05:00
|
|
|
request :linode_ip_list
|
|
|
|
request :linode_ip_addprivate
|
|
|
|
request :linode_config_list
|
2011-03-04 15:03:51 -05:00
|
|
|
request :linode_config_create
|
2010-09-08 13:56:38 -04:00
|
|
|
request :linode_create
|
|
|
|
request :linode_delete
|
|
|
|
request :linode_list
|
2011-03-17 14:49:58 -04:00
|
|
|
request :linode_boot
|
2010-09-08 13:56:38 -04:00
|
|
|
request :linode_reboot
|
2011-03-04 15:03:51 -05:00
|
|
|
request :linode_shutdown
|
2011-03-01 16:37:27 -05:00
|
|
|
request :linode_update
|
2011-03-17 14:49:58 -04:00
|
|
|
request :stackscript_list
|
2011-03-04 15:03:51 -05:00
|
|
|
# request :linode_resize
|
2010-09-08 13:56:38 -04:00
|
|
|
|
|
|
|
class Mock
|
|
|
|
|
|
|
|
def self.data
|
|
|
|
@data ||= Hash.new do |hash, key|
|
|
|
|
hash[key] = {}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-05-17 22:40:17 -04:00
|
|
|
def self.reset
|
|
|
|
@data = nil
|
|
|
|
end
|
|
|
|
|
2010-09-08 13:56:38 -04:00
|
|
|
def initialize(options={})
|
|
|
|
@linode_api_key = options[:linode_api_key]
|
2011-05-19 18:35:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def data
|
|
|
|
self.class.data[@linode_api_key]
|
2011-03-10 14:16:55 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def reset_data
|
|
|
|
self.class.data.delete(@linode_api_key)
|
2010-09-08 13:56:38 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
class Real
|
|
|
|
|
|
|
|
def initialize(options={})
|
2011-07-15 22:34:16 -04:00
|
|
|
require 'multi_json'
|
2010-09-08 13:56:38 -04:00
|
|
|
@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
|
|
|
|
|
|
|
|
def reload
|
|
|
|
@connection.reset
|
|
|
|
end
|
|
|
|
|
|
|
|
def request(params)
|
|
|
|
params[:query] ||= {}
|
|
|
|
params[:query].merge!(:api_key => @linode_api_key)
|
|
|
|
|
|
|
|
response = @connection.request(params.merge!({:host => @host}))
|
|
|
|
|
|
|
|
unless response.body.empty?
|
2011-07-20 12:08:11 -04:00
|
|
|
response.body = MultiJson.decode(response.body)
|
2010-09-08 13:56:38 -04:00
|
|
|
if data = response.body['ERRORARRAY'].first
|
|
|
|
error = case data['ERRORCODE']
|
|
|
|
when 5
|
2011-06-16 19:28:54 -04:00
|
|
|
Fog::Compute::Linode::NotFound
|
2010-09-08 13:56:38 -04:00
|
|
|
else
|
2011-06-16 19:28:54 -04:00
|
|
|
Fog::Compute::Linode::Error
|
2010-09-08 13:56:38 -04:00
|
|
|
end
|
|
|
|
raise error.new(data['ERRORMESSAGE'])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
response
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|