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
|
2013-12-30 02:38:04 -05:00
|
|
|
# Hard coding numbers because requests from tests are sometimes failing.
|
|
|
|
# TODO: Mock properly instead
|
2013-12-27 11:03:22 -05:00
|
|
|
image = service.images.find { |i| i.name == 'Ubuntu 13.10 x64' }
|
2013-12-30 02:38:04 -05:00
|
|
|
image_id = image.nil? ? 1505447 : image.id
|
2013-07-10 20:41:12 -04:00
|
|
|
region = service.regions.find { |r| r.name == 'New York 1' }
|
2013-12-30 02:38:04 -05:00
|
|
|
region_id = region.nil? ? 4 : region.id
|
2013-07-10 20:41:12 -04:00
|
|
|
flavor = service.flavors.find { |r| r.name == '512MB' }
|
2013-12-30 02:38:04 -05:00
|
|
|
flavor_id = flavor.nil? ? 66 : flavor.id
|
2013-07-10 20:41:12 -04:00
|
|
|
|
|
|
|
{
|
2013-12-30 02:38:04 -05:00
|
|
|
:image_id => image_id,
|
|
|
|
:region_id => region_id,
|
|
|
|
:flavor_id => flavor_id
|
2013-07-10 20:41:12 -04:00
|
|
|
}
|
|
|
|
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
|