Class: Fog::Compute::DigitalOcean::Real
- Inherits:
-
Object
- Object
- Fog::Compute::DigitalOcean::Real
- Defined in:
- lib/fog/digitalocean/compute.rb,
lib/fog/digitalocean/requests/compute/get_ssh_key.rb,
lib/fog/digitalocean/requests/compute/list_images.rb,
lib/fog/digitalocean/requests/compute/list_flavors.rb,
lib/fog/digitalocean/requests/compute/list_regions.rb,
lib/fog/digitalocean/requests/compute/list_servers.rb,
lib/fog/digitalocean/requests/compute/create_server.rb,
lib/fog/digitalocean/requests/compute/list_ssh_keys.rb,
lib/fog/digitalocean/requests/compute/reboot_server.rb,
lib/fog/digitalocean/requests/compute/create_ssh_key.rb,
lib/fog/digitalocean/requests/compute/destroy_server.rb,
lib/fog/digitalocean/requests/compute/destroy_ssh_key.rb,
lib/fog/digitalocean/requests/compute/power_on_server.rb,
lib/fog/digitalocean/requests/compute/shutdown_server.rb,
lib/fog/digitalocean/requests/compute/power_off_server.rb,
lib/fog/digitalocean/requests/compute/get_server_details.rb,
lib/fog/digitalocean/requests/compute/power_cycle_server.rb
Instance Method Summary collapse
-
#create_server(name, size_id, image_id, region_id, options = {}) ⇒ Object
FIXME: missing ssh keys support.
- #create_ssh_key(name, pub_key) ⇒ Object
-
#destroy_server(id) ⇒ Object
FIXME: missing ssh keys support.
-
#destroy_ssh_key(id) ⇒ Object
Delete a SSH public key from your account.
- #get_server_details(server_id) ⇒ Object
-
#get_ssh_key(id) ⇒ Object
This method shows a specific public SSH key in your account that can be added to a droplet.
-
#initialize(options = {}) ⇒ Real
constructor
A new instance of Real.
- #list_flavors(options = {}) ⇒ Object
- #list_images(options = {}) ⇒ Object
- #list_regions(options = {}) ⇒ Object
- #list_servers(options = {}) ⇒ Object
- #list_ssh_keys(options = {}) ⇒ Object
- #power_cycle_server(id) ⇒ Object
- #power_off_server(id) ⇒ Object
- #power_on_server(id) ⇒ Object
- #reboot_server(id) ⇒ Object
- #reload ⇒ Object
- #request(params) ⇒ Object
- #shutdown_server(id) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Real
Returns a new instance of Real.
76 77 78 79 80 81 82 |
# File 'lib/fog/digitalocean/compute.rb', line 76 def initialize(={}) @digitalocean_api_key = [:digitalocean_api_key] @digitalocean_client_id = [:digitalocean_client_id] @digitalocean_api_url = [:digitalocean_api_url] || \ "https://api.digitalocean.com" @connection = Fog::Connection.new(@digitalocean_api_url) end |
Instance Method Details
#create_server(name, size_id, image_id, region_id, options = {}) ⇒ Object
FIXME: missing ssh keys support
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/fog/digitalocean/requests/compute/create_server.rb', line 9 def create_server( name, size_id, image_id, region_id, = {} ) query_hash = { :name => name, :size_id => size_id, :image_id => image_id, :region_id => region_id } if [:ssh_key_ids] query_hash[:ssh_key_ids] = [:ssh_key_ids] end request( :expects => [200], :method => 'GET', :path => 'droplets/new', :query => query_hash ) end |
#create_ssh_key(name, pub_key) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/fog/digitalocean/requests/compute/create_ssh_key.rb', line 6 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) ⇒ Object
FIXME: missing ssh keys support
9 10 11 12 13 14 15 |
# File 'lib/fog/digitalocean/requests/compute/destroy_server.rb', line 9 def destroy_server( id ) request( :expects => [200], :method => 'GET', :path => "droplets/#{id}/destroy" ) end |
#destroy_ssh_key(id) ⇒ Object
Delete a SSH public key from your account
11 12 13 14 15 16 17 |
# File 'lib/fog/digitalocean/requests/compute/destroy_ssh_key.rb', line 11 def destroy_ssh_key(id) request( :expects => [200], :method => 'GET', :path => "ssh_keys/#{id}/destroy" ) end |
#get_server_details(server_id) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/fog/digitalocean/requests/compute/get_server_details.rb', line 6 def get_server_details(server_id) request( :expects => [200], :method => 'GET', :path => "droplets/#{server_id}" ) end |
#get_ssh_key(id) ⇒ Object
This method shows a specific public SSH key in your account that can be added to a droplet.
12 13 14 15 16 17 18 |
# File 'lib/fog/digitalocean/requests/compute/get_ssh_key.rb', line 12 def get_ssh_key(id) request( :expects => [200], :method => 'GET', :path => "ssh_keys/#{id}" ) end |
#list_flavors(options = {}) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/fog/digitalocean/requests/compute/list_flavors.rb', line 6 def list_flavors( = {}) request( :expects => [200], :method => 'GET', :path => 'sizes' ) end |
#list_images(options = {}) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/fog/digitalocean/requests/compute/list_images.rb', line 6 def list_images( = {}) request( :expects => [200], :method => 'GET', :path => 'images' ) end |
#list_regions(options = {}) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/fog/digitalocean/requests/compute/list_regions.rb', line 6 def list_regions( = {}) request( :expects => [200], :method => 'GET', :path => 'regions' ) end |
#list_servers(options = {}) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/fog/digitalocean/requests/compute/list_servers.rb', line 6 def list_servers( = {}) request( :expects => [200], :method => 'GET', :path => 'droplets' ) end |
#list_ssh_keys(options = {}) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/fog/digitalocean/requests/compute/list_ssh_keys.rb', line 6 def list_ssh_keys( = {}) request( :expects => [200], :method => 'GET', :path => 'ssh_keys' ) end |
#power_cycle_server(id) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/fog/digitalocean/requests/compute/power_cycle_server.rb', line 6 def power_cycle_server( id ) request( :expects => [200], :method => 'GET', :path => "droplets/#{id}/power_cycle" ) end |
#power_off_server(id) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/fog/digitalocean/requests/compute/power_off_server.rb', line 6 def power_off_server( id ) request( :expects => [200], :method => 'GET', :path => "droplets/#{id}/power_off" ) end |
#power_on_server(id) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/fog/digitalocean/requests/compute/power_on_server.rb', line 6 def power_on_server( id ) request( :expects => [200], :method => 'GET', :path => "droplets/#{id}/power_on" ) end |
#reboot_server(id) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/fog/digitalocean/requests/compute/reboot_server.rb', line 6 def reboot_server( id ) request( :expects => [200], :method => 'GET', :path => "droplets/#{id}/reboot" ) end |
#reload ⇒ Object
84 85 86 |
# File 'lib/fog/digitalocean/compute.rb', line 84 def reload @connection.reset end |
#request(params) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/fog/digitalocean/compute.rb', line 88 def request(params) params[:query] ||= {} params[:query].merge!(:api_key => @digitalocean_api_key) params[:query].merge!(:client_id => @digitalocean_client_id) response = @connection.request(params) unless response.body.empty? response.body = Fog::JSON.decode(response.body) if response.body['status'] != 'OK' raise Fog::Errors::Error.new response.body.to_s end end response end |
#shutdown_server(id) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/fog/digitalocean/requests/compute/shutdown_server.rb', line 6 def shutdown_server( id ) request( :expects => [200], :method => 'GET', :path => "droplets/#{id}/shutdown" ) end |