2013-02-06 15:17:17 -05:00
|
|
|
|
|
|
|
# Shortcut for Fog::Compute[:digitalocean]
|
|
|
|
def service
|
|
|
|
Fog::Compute[:digitalocean]
|
|
|
|
end
|
|
|
|
|
2013-07-10 20:41:12 -04:00
|
|
|
def fog_test_server_attributes
|
|
|
|
image = service.images.find { |i| i.name == 'Ubuntu 12.04 x64' }
|
|
|
|
region = service.regions.find { |r| r.name == 'New York 1' }
|
|
|
|
flavor = service.flavors.find { |r| r.name == '512MB' }
|
|
|
|
|
|
|
|
{
|
|
|
|
:image_id => image.id,
|
|
|
|
:region_id => region.id,
|
|
|
|
:flavor_id => flavor.id
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def fog_server_name
|
|
|
|
"fog-server-test"
|
|
|
|
end
|
|
|
|
|
2013-02-06 15:17:17 -05:00
|
|
|
# Create a long lived server for the tests
|
|
|
|
def fog_test_server
|
2013-07-10 20:41:12 -04:00
|
|
|
server = service.servers.find { |s| s.name == fog_server_name }
|
2013-02-06 15:17:17 -05:00
|
|
|
unless server
|
2013-07-10 20:41:12 -04:00
|
|
|
server = service.servers.create({
|
|
|
|
:name => fog_server_name
|
|
|
|
}.merge(fog_test_server_attributes))
|
|
|
|
server.wait_for { ready? }
|
2013-02-06 15:17:17 -05:00
|
|
|
end
|
|
|
|
server
|
|
|
|
end
|
|
|
|
|
|
|
|
# Destroy the long lived server
|
|
|
|
def fog_test_server_destroy
|
2013-07-10 20:41:12 -04:00
|
|
|
server = service.servers.find { |s| s.name == fog_server_name }
|
2013-02-06 15:17:17 -05:00
|
|
|
server.destroy if server
|
|
|
|
end
|
2013-02-26 13:27:07 -05:00
|
|
|
|
|
|
|
at_exit do
|
2013-04-03 11:47:31 -04:00
|
|
|
unless Fog.mocking? || Fog.credentials[:digitalocean_api_key].nil?
|
2013-07-10 20:41:12 -04:00
|
|
|
server = service.servers.find { |s| s.name == fog_server_name }
|
2013-03-18 07:54:48 -04:00
|
|
|
if server
|
|
|
|
server.wait_for(120) do
|
|
|
|
reload rescue nil; ready?
|
|
|
|
end
|
2013-02-26 13:27:07 -05:00
|
|
|
end
|
2013-03-18 07:54:48 -04:00
|
|
|
fog_test_server_destroy
|
2013-02-26 13:27:07 -05:00
|
|
|
end
|
|
|
|
end
|