From c1e518c3b50b2ddaf6ae9fcc61b6444471a1cbc5 Mon Sep 17 00:00:00 2001 From: Sergio Rubio Date: Tue, 26 Feb 2013 20:42:08 +0100 Subject: [PATCH] [digitalocean|compute] implemented missing Server actions - shutdown - stop - start Added required tests --- lib/fog/digitalocean/models/compute/server.rb | 31 ++++++++++++------- .../models/compute/server_tests.rb | 30 ++++++++++++++++-- 2 files changed, 48 insertions(+), 13 deletions(-) diff --git a/lib/fog/digitalocean/models/compute/server.rb b/lib/fog/digitalocean/models/compute/server.rb index a85b92128..1575ae89a 100644 --- a/lib/fog/digitalocean/models/compute/server.rb +++ b/lib/fog/digitalocean/models/compute/server.rb @@ -14,20 +14,25 @@ module Fog attribute :image_id attribute :region_id attribute :flavor_id, :aliases => :size_id + # Not documented in their API, but + # available nevertheless + attribute :ip_address attribute :backups_active # Reboot the server (soft reboot). # # The preferred method of rebooting a server. def reboot - service.reboot_server id + requires :id + service.reboot_server self.id end # Reboot the server (hard reboot). # # Powers the server off and then powers it on again. def power_cycle - service.power_cycle_server id + requires :id + service.power_cycle_server self.id end # Shutdown the server @@ -38,7 +43,8 @@ module Fog # # @see https://www.digitalocean.com/community/questions/am-i-charged-while-my-droplet-is-in-a-powered-off-state def shutdown - raise NotImplementedError + requires :id + service.shutdown_server self.id end # Power off the server @@ -47,13 +53,11 @@ module Fog # The server consumes resources while powered off # so you are still charged. # - # Server.power_off is an alias to Server.stop - # # @see https://www.digitalocean.com/community/questions/am-i-charged-while-my-droplet-is-in-a-powered-off-state def stop - raise NotImplementedError + requires :id + service.power_off_server self.id end - alias power_off stop # Power on the server. # @@ -63,12 +67,10 @@ module Fog # Each time a server is spun up, even if for a few seconds, # it is charged for an hour. # - # Server.power_off is an alias to Server.stop - # def start - raise NotImplementedError + requires :id + service.power_on_server self.id end - alias power_on start # Creates the server (not to be called directly). # @@ -118,6 +120,7 @@ module Fog # # Double check the server has been destroyed! def destroy + requires :id service.destroy_server id end @@ -132,6 +135,12 @@ module Fog status == 'active' end + # DigitalOcean API does not support updating server state + def update + msg = 'DigitalOcean servers do not support updates' + raise NotImplementedError.new(msg) + end + end end diff --git a/tests/digitalocean/models/compute/server_tests.rb b/tests/digitalocean/models/compute/server_tests.rb index 3c1414d7e..b23b0300c 100644 --- a/tests/digitalocean/models/compute/server_tests.rb +++ b/tests/digitalocean/models/compute/server_tests.rb @@ -10,6 +10,8 @@ Shindo.tests("Fog::Compute[:digitalocean] | server model", ['digitalocean', 'com shutdown reboot power_cycle + stop + start }.each do |action| test(action) { server.respond_to? action } end @@ -32,19 +34,43 @@ Shindo.tests("Fog::Compute[:digitalocean] | server model", ['digitalocean', 'com end end end - test('reboot the server') do + test('#reboot') do server.reboot server.wait_for { server.status == 'off' } server.status == 'off' end - test('power_cycle the server') do + test('#power_cycle') do server.wait_for { server.ready? } server.power_cycle server.wait_for { server.status == 'off' } server.status == 'off' end + test('#stop') do + server.stop + server.wait_for { server.status == 'off' } + server.status == 'off' + end + test('#start') do + server.start + server.wait_for { ready? } + server.ready? + end + # DigitalOcean shutdown is unreliable + #test('#shutdown') do + # server.start + # server.wait_for { server.ready? } + # server.shutdown + # server.wait_for { server.status == 'off' } + # server.status == 'off' + #end + raises(NotImplementedError, '#update') do + server.update + end end + # restore server state + server.start + end