mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[digitalocean|compute] implemented missing Server actions
- shutdown - stop - start Added required tests
This commit is contained in:
parent
f83b4885e9
commit
c1e518c3b5
2 changed files with 48 additions and 13 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue