class Fog::Compute::DigitalOcean::Real
Public Class Methods
new(options={})
click to toggle source
# File lib/fog/digitalocean/compute.rb, line 71 def initialize(options={}) @digitalocean_api_key = options[:digitalocean_api_key] @digitalocean_client_id = options[:digitalocean_client_id] @digitalocean_api_url = options[:digitalocean_api_url] || "https://api.digitalocean.com" @connection = Fog::XML::Connection.new(@digitalocean_api_url) end
Public Instance Methods
create_server( name, size_id, image_id, region_id, options = {} )
click to toggle source
FIXME: missing ssh keys support
# File lib/fog/digitalocean/requests/compute/create_server.rb, line 8 def create_server( name, size_id, image_id, region_id, options = {} ) query_hash = { :name => name, :size_id => size_id, :image_id => image_id, :region_id => region_id } if options[:ssh_key_ids] options[:ssh_key_ids] = options[:ssh_key_ids].join(",") if options[:ssh_key_ids].is_a? Array query_hash[:ssh_key_ids] = options[:ssh_key_ids] end query_hash[:private_networking] = !!options[:private_networking] request( :expects => [200], :method => 'GET', :path => 'droplets/new', :query => query_hash ) end
create_ssh_key( name, pub_key )
click to toggle source
# File lib/fog/digitalocean/requests/compute/create_ssh_key.rb, line 5 def create_ssh_key( name, pub_key ) request( :expects => [200], :method => 'GET', :path => 'ssh_keys/new', :query => { 'name' => name, 'ssh_pub_key' => pub_key } ) end
destroy_server( id )
click to toggle source
FIXME: missing ssh keys support
# File lib/fog/digitalocean/requests/compute/destroy_server.rb, line 8 def destroy_server( id ) request( :expects => [200], :method => 'GET', :path => "droplets/#{id}/destroy", # We scrub data so future users can't read our disks. :query => {:scrub_data => '1' } ) end
destroy_ssh_key(id)
click to toggle source
Delete a SSH public key from your account
@see developers.digitalocean.com/ssh-keys
# File lib/fog/digitalocean/requests/compute/destroy_ssh_key.rb, line 10 def destroy_ssh_key(id) request( :expects => [200], :method => 'GET', :path => "ssh_keys/#{id}/destroy" ) end
get_server_details(server_id)
click to toggle source
# File lib/fog/digitalocean/requests/compute/get_server_details.rb, line 5 def get_server_details(server_id) request( :expects => [200], :method => 'GET', :path => "droplets/#{server_id}" ) end
get_ssh_key(id)
click to toggle source
This method shows a specific public SSH key in your account that can be added to a droplet.
@see developers.digitalocean.com/ssh-keys
# File lib/fog/digitalocean/requests/compute/get_ssh_key.rb, line 11 def get_ssh_key(id) request( :expects => [200], :method => 'GET', :path => "ssh_keys/#{id}" ) end
list_flavors(options = {})
click to toggle source
# File lib/fog/digitalocean/requests/compute/list_flavors.rb, line 5 def list_flavors(options = {}) request( :expects => [200], :method => 'GET', :path => 'sizes' ) end
list_images(options = {})
click to toggle source
# File lib/fog/digitalocean/requests/compute/list_images.rb, line 5 def list_images(options = {}) request( :expects => [200], :method => 'GET', :path => 'images' ) end
list_regions(options = {})
click to toggle source
# File lib/fog/digitalocean/requests/compute/list_regions.rb, line 5 def list_regions(options = {}) request( :expects => [200], :method => 'GET', :path => 'regions' ) end
list_servers(options = {})
click to toggle source
# File lib/fog/digitalocean/requests/compute/list_servers.rb, line 5 def list_servers(options = {}) request( :expects => [200], :method => 'GET', :path => 'droplets' ) end
list_ssh_keys(options = {})
click to toggle source
# File lib/fog/digitalocean/requests/compute/list_ssh_keys.rb, line 5 def list_ssh_keys(options = {}) request( :expects => [200], :method => 'GET', :path => 'ssh_keys' ) end
power_cycle_server( id )
click to toggle source
# File lib/fog/digitalocean/requests/compute/power_cycle_server.rb, line 5 def power_cycle_server( id ) request( :expects => [200], :method => 'GET', :path => "droplets/#{id}/power_cycle" ) end
power_off_server( id )
click to toggle source
# File lib/fog/digitalocean/requests/compute/power_off_server.rb, line 5 def power_off_server( id ) request( :expects => [200], :method => 'GET', :path => "droplets/#{id}/power_off" ) end
power_on_server( id )
click to toggle source
# File lib/fog/digitalocean/requests/compute/power_on_server.rb, line 5 def power_on_server( id ) request( :expects => [200], :method => 'GET', :path => "droplets/#{id}/power_on" ) end
reboot_server( id )
click to toggle source
# File lib/fog/digitalocean/requests/compute/reboot_server.rb, line 5 def reboot_server( id ) request( :expects => [200], :method => 'GET', :path => "droplets/#{id}/reboot" ) end
reload()
click to toggle source
# File lib/fog/digitalocean/compute.rb, line 79 def reload @connection.reset end
request(params)
click to toggle source
# File lib/fog/digitalocean/compute.rb, line 83 def request(params) params[:query] ||= {} params[:query].merge!(:api_key => @digitalocean_api_key) params[:query].merge!(:client_id => @digitalocean_client_id) response = retry_event_lock { parse @connection.request(params) } unless response.body.empty? if response.body['status'] != 'OK' case response.body['error_message'] when /No Droplets Found/ raise Fog::Errors::NotFound.new else raise Fog::Errors::Error.new response.body.to_s end end end response end
shutdown_server( id )
click to toggle source
# File lib/fog/digitalocean/requests/compute/shutdown_server.rb, line 5 def shutdown_server( id ) request( :expects => [200], :method => 'GET', :path => "droplets/#{id}/shutdown" ) end
Private Instance Methods
parse(response)
click to toggle source
# File lib/fog/digitalocean/compute.rb, line 105 def parse(response) return response if response.body.empty? response.body = Fog::JSON.decode(response.body) response end
retry_event_lock() { || ... }
click to toggle source
# File lib/fog/digitalocean/compute.rb, line 111 def retry_event_lock count = 0 reponse = nil while count < 5 response = yield if response.body && response.body['error_message'] =~ /There is already a pending event for the droplet/ count += 1 sleep count ** 3 else break end end response end