From cac4012b94fad3463b7b26b604582490ffa1c357 Mon Sep 17 00:00:00 2001 From: Peter Souter Date: Wed, 14 Jan 2015 11:24:05 -0800 Subject: [PATCH 1/6] Updates location to get API keys from Link has been moved now API 2.0 is available --- lib/fog/digitalocean/examples/getting_started.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/fog/digitalocean/examples/getting_started.md b/lib/fog/digitalocean/examples/getting_started.md index c8e62bb1f..b89d3a3dc 100644 --- a/lib/fog/digitalocean/examples/getting_started.md +++ b/lib/fog/digitalocean/examples/getting_started.md @@ -2,10 +2,7 @@ You'll need a DigitalOcean account and API key to use this provider. -Get one from http://www.digitalocean.com. - -To generate the API key, login to the DigitalOcean web panel and go to -'My Settings -> API Access -> Generate a new API key'. +Get one from https://cloud.digitalocean.com/api_access (fog currently uses the v1 API) Write down the Client Key and API Key, you'll need both to use the service. From cec93cfb3e5c6824e4fbfee5463644a8ab19e5de Mon Sep 17 00:00:00 2001 From: Peter Souter Date: Wed, 14 Jan 2015 11:24:21 -0800 Subject: [PATCH 2/6] Adds section about SSH key management --- .../digitalocean/examples/getting_started.md | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lib/fog/digitalocean/examples/getting_started.md b/lib/fog/digitalocean/examples/getting_started.md index b89d3a3dc..db995932c 100644 --- a/lib/fog/digitalocean/examples/getting_started.md +++ b/lib/fog/digitalocean/examples/getting_started.md @@ -26,6 +26,34 @@ docean = Fog::Compute.new({ }) ``` +## SSH Key Management + +Access to DigitalOcean servers can be managed with SSH keys. These can be assigned to servers at creation time so you can access them without having to use a password. + +Creating a key: + +```ruby +docean.ssh_keys.create( + :name => 'Default SSH Key', + :ssh_pub_key => File.read('~/.ssh/id_rsa.pub')) +) +``` + +Listing all keys: + +```ruby +docean.ssh_keys.each do | key | + key.name + key.ssh_pub_key +end +``` + +Destroying a key: + +```ruby +docean.ssh_keys.destroy(:id => '27100') +``` + ## Listing servers Listing servers and attributes: From 8ad2443947f9cc6f008a209554a9d5718fedcb67 Mon Sep 17 00:00:00 2001 From: Peter Souter Date: Wed, 14 Jan 2015 11:25:12 -0800 Subject: [PATCH 3/6] Adds notes about how to bootstrap a server Had to do a lot of googling and searching through gists to find an example of a DigitalOcean bootstrap, so hopefully this helps someone else! :smile: --- .../digitalocean/examples/getting_started.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/fog/digitalocean/examples/getting_started.md b/lib/fog/digitalocean/examples/getting_started.md index db995932c..5321b57eb 100644 --- a/lib/fog/digitalocean/examples/getting_started.md +++ b/lib/fog/digitalocean/examples/getting_started.md @@ -54,6 +54,23 @@ Destroying a key: docean.ssh_keys.destroy(:id => '27100') ``` +## Boostrapping a server + +Fog can be used to bootstrap a server, which will create an SSH key to be assigned to a server at boot. + +```ruby +server = connection.servers.bootstrap({ + :name => 'test', + :image_id => 1505447, + :size_id => 33, + :region_id => 4, + :flavor_id => 66, + :public_key_path => File.expand_path('~/.ssh/id_rsa.pub'), + :private_key_path => File.expand_path('~/.ssh/id_rsa'), +}) +server.wait_for { ready? } +``` + ## Listing servers Listing servers and attributes: From 778ba2a55bd900533cfedf6950aeafcc2e80eb3a Mon Sep 17 00:00:00 2001 From: Peter Souter Date: Wed, 14 Jan 2015 11:25:30 -0800 Subject: [PATCH 4/6] Fix typo It's DigitalOcean not AWS --- lib/fog/digitalocean/models/compute/server.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fog/digitalocean/models/compute/server.rb b/lib/fog/digitalocean/models/compute/server.rb index c33a6419b..e91cf48d5 100644 --- a/lib/fog/digitalocean/models/compute/server.rb +++ b/lib/fog/digitalocean/models/compute/server.rb @@ -94,7 +94,7 @@ module Fog commands << %{echo "#{public_key}" >> ~/.ssh/authorized_keys} end - # wait for aws to be ready + # wait for DigitalOcean to be ready wait_for { sshable?(credentials) } Fog::SSH.new(ssh_ip_address, username, credentials).run(commands) From 89717f0bfd9bf1338329e3c716bf2e79af523025 Mon Sep 17 00:00:00 2001 From: Peter Souter Date: Wed, 14 Jan 2015 11:26:05 -0800 Subject: [PATCH 5/6] Adds RDoc for #bootstrap, #get(id) and #all() --- .../digitalocean/models/compute/servers.rb | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lib/fog/digitalocean/models/compute/servers.rb b/lib/fog/digitalocean/models/compute/servers.rb index 1ddc22034..f4999bde7 100644 --- a/lib/fog/digitalocean/models/compute/servers.rb +++ b/lib/fog/digitalocean/models/compute/servers.rb @@ -7,11 +7,33 @@ module Fog class Servers < Fog::Collection model Fog::Compute::DigitalOcean::Server + # Returns list of servers + # @return [Fog::Compute::DigitalOcean::Servers] Retrieves a list of servers. + # @raise [Fog::Compute::DigitalOcean::NotFound] - HTTP 404 + # @raise [Fog::Compute::DigitalOcean::BadRequest] - HTTP 400 + # @raise [Fog::Compute::DigitalOcean::InternalServerError] - HTTP 500 + # @raise [Fog::Compute::DigitalOcean::ServiceError] + # @see https://developers.digitalocean.com/v1/droplets/ def all(filters = {}) data = service.list_servers.body['droplets'] load(data) end + # Creates a new server and populates ssh keys + # + # @return [Fog::Compute::DigitalOcean::Server] + # @raise [Fog::Compute::DigitalOcean::NotFound] - HTTP 404 + # @raise [Fog::Compute::DigitalOcean::BadRequest] - HTTP 400 + # @raise [Fog::Compute::DigitalOcean::InternalServerError] - HTTP 500 + # @raise [Fog::Compute::DigitalOcean::ServiceError] + # @note This creates an SSH public key object and assigns it to the server on creation + # @example + # service.servers.bootstrap :name => 'bootstrap-server', + # :flavor_ref => service.flavors.first.id, + # :image_ref => service.images.find {|img| img.name =~ /Ubuntu/}.id, + # :public_key_path => '~/.ssh/fog_rsa.pub', + # :private_key_path => '~/.ssh/fog_rsa' + # def bootstrap(new_attributes = {}) server = new(new_attributes) @@ -40,6 +62,14 @@ module Fog server end + # Retrieves server + # @param [String] id for server to be returned + # @return [Fog::Compute::DigitalOcean:Server] + # @raise [Fog::Compute::DigitalOcean::NotFound] - HTTP 404 + # @raise [Fog::Compute::DigitalOcean::BadRequest] - HTTP 400 + # @raise [Fog::Compute::DigitalOcean::InternalServerError] - HTTP 500 + # @raise [Fog::Compute::DigitalOcean::ServiceError] + # @see https://developers.digitalocean.com/v1/droplets/ def get(id) server = service.get_server_details(id).body['droplet'] new(server) if server From 9ff547c96764de06d3c4167751d0d27e7ebb7a66 Mon Sep 17 00:00:00 2001 From: Peter Souter Date: Wed, 14 Jan 2015 11:26:24 -0800 Subject: [PATCH 6/6] Removes not about not being documented This is now documented in the API --- lib/fog/digitalocean/models/compute/server.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/fog/digitalocean/models/compute/server.rb b/lib/fog/digitalocean/models/compute/server.rb index e91cf48d5..516c6c8f3 100644 --- a/lib/fog/digitalocean/models/compute/server.rb +++ b/lib/fog/digitalocean/models/compute/server.rb @@ -12,8 +12,6 @@ module Fog attribute :image_id attribute :region_id attribute :flavor_id, :aliases => 'size_id' - # Not documented in their API, but - # available nevertheless attribute :public_ip_address, :aliases => 'ip_address' attribute :private_ip_address attribute :private_networking