diff --git a/lib/fog/digitalocean/compute.rb b/lib/fog/digitalocean/compute.rb index 3fbdc5719..70c7f8ad8 100644 --- a/lib/fog/digitalocean/compute.rb +++ b/lib/fog/digitalocean/compute.rb @@ -29,6 +29,7 @@ module Fog request :create_server request :destroy_server request :reboot_server + request :power_cycle_server # request :digitalocean_resize diff --git a/lib/fog/digitalocean/models/compute/server.rb b/lib/fog/digitalocean/models/compute/server.rb index 8b7087a28..a85b92128 100644 --- a/lib/fog/digitalocean/models/compute/server.rb +++ b/lib/fog/digitalocean/models/compute/server.rb @@ -27,7 +27,7 @@ module Fog # # Powers the server off and then powers it on again. def power_cycle - raise NotImplementedError + service.power_cycle_server id end # Shutdown the server diff --git a/lib/fog/digitalocean/requests/compute/power_cycle_server.rb b/lib/fog/digitalocean/requests/compute/power_cycle_server.rb new file mode 100644 index 000000000..acfe5d961 --- /dev/null +++ b/lib/fog/digitalocean/requests/compute/power_cycle_server.rb @@ -0,0 +1,25 @@ +module Fog + module Compute + class DigitalOcean + class Real + + def power_cycle_server( id ) + request( + :expects => [200], + :method => 'GET', + :path => "droplets/#{id}/power_cycle" + ) + end + + end + + class Mock + + def power_cycle_server( id ) + Fog::Mock.not_implemented + end + + end + end + end +end diff --git a/tests/digitalocean/models/compute/server_tests.rb b/tests/digitalocean/models/compute/server_tests.rb index 44f49f47a..a00946cb3 100644 --- a/tests/digitalocean/models/compute/server_tests.rb +++ b/tests/digitalocean/models/compute/server_tests.rb @@ -9,6 +9,7 @@ Shindo.tests("Fog::Compute[:digitalocean] | server model", ['digitalocean', 'com %w{ shutdown reboot + power_cycle }.each do |action| test(action) { server.respond_to? action } end @@ -35,6 +36,12 @@ Shindo.tests("Fog::Compute[:digitalocean] | server model", ['digitalocean', 'com server.wait_for { server.status == 'off' } server.status == 'off' end + test('power_cycle the server') do + server.wait_for { server.ready? } + server.power_cycle + server.wait_for { server.status == 'off' } + server.status == 'off' + end end diff --git a/tests/digitalocean/requests/compute/destroy_server_tests.rb b/tests/digitalocean/requests/compute/destroy_server_tests.rb new file mode 100644 index 000000000..b796cdc64 --- /dev/null +++ b/tests/digitalocean/requests/compute/destroy_server_tests.rb @@ -0,0 +1,20 @@ +Shindo.tests('Fog::Compute[:digitalocean] | reboot_server request', ['digitalocean', 'compute']) do + + service = Fog::Compute[:digitalocean] + data = Fog::Compute[:digitalocean].create_server 'fog-test', + service.flavors.first.id, + service.images.first.id, + service.regions.first.id + + tests('success') do + + test('#reboot_server') do + sleep 120 + data.body['status'] == 'OK' and \ + (service.destroy_server(data.body['droplet']['id']).body['status'] == 'OK') + end + + end + + +end diff --git a/tests/digitalocean/requests/compute/power_cycle_server_tests.rb b/tests/digitalocean/requests/compute/power_cycle_server_tests.rb new file mode 100644 index 000000000..07cc6de31 --- /dev/null +++ b/tests/digitalocean/requests/compute/power_cycle_server_tests.rb @@ -0,0 +1,20 @@ +Shindo.tests('Fog::Compute[:digitalocean] | power_cycle_server request', ['digitalocean', 'compute']) do + + server = fog_test_server + + tests('success') do + + tests('#power_cycle_server') do + test('returns 200') do + service.power_cycle_server(server.id).status == 200 + end + test('state is off') do + server.wait_for { server.status == 'off' } + server.status == 'off' + end + end + + end + + +end