2009-05-18 03:13:06 -04:00
|
|
|
require 'spec'
|
|
|
|
|
2009-07-15 14:53:32 -04:00
|
|
|
current_directory = File.dirname(__FILE__)
|
2009-08-10 11:30:28 -04:00
|
|
|
require "#{current_directory}/../lib/fog"
|
|
|
|
# Fog.mocking = true
|
2009-05-19 02:06:49 -04:00
|
|
|
|
2009-07-13 22:25:44 -04:00
|
|
|
def credentials
|
|
|
|
@credentials ||= begin
|
|
|
|
credentials_path = "#{File.dirname(__FILE__)}/credentials.yml"
|
|
|
|
credentials_data = File.open(credentials_path).read
|
|
|
|
YAML.load(credentials_data)
|
|
|
|
end
|
|
|
|
end
|
2009-05-19 02:06:49 -04:00
|
|
|
|
2009-08-12 00:40:59 -04:00
|
|
|
module Fog
|
|
|
|
module AWS
|
|
|
|
|
|
|
|
class EC2
|
|
|
|
def self.gen
|
|
|
|
new(
|
|
|
|
:aws_access_key_id => credentials['aws_access_key_id'],
|
|
|
|
:aws_secret_access_key => credentials['aws_secret_access_key']
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class S3
|
|
|
|
def self.gen(location = nil)
|
|
|
|
if location == :eu
|
|
|
|
host = 's3-external-3.amazonaws.com'
|
|
|
|
end
|
|
|
|
new(
|
|
|
|
:aws_access_key_id => credentials['aws_access_key_id'],
|
|
|
|
:aws_secret_access_key => credentials['aws_secret_access_key'],
|
|
|
|
:host => host
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class SimpleDB
|
|
|
|
def self.gen
|
|
|
|
new(
|
|
|
|
:aws_access_key_id => credentials['aws_access_key_id'],
|
|
|
|
:aws_secret_access_key => credentials['aws_secret_access_key']
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2009-07-22 22:28:53 -04:00
|
|
|
end
|
2009-05-19 02:06:49 -04:00
|
|
|
|
2009-07-25 21:05:49 -04:00
|
|
|
def eventually(max_delay = 16, &block)
|
|
|
|
delays = [0]
|
|
|
|
delay_step = 1
|
|
|
|
total = 0
|
|
|
|
while true
|
|
|
|
delay = 1
|
|
|
|
delay_step.times do
|
|
|
|
delay *= 2
|
|
|
|
end
|
|
|
|
delays << delay
|
|
|
|
delay_step += 1
|
|
|
|
break if delay >= max_delay
|
|
|
|
end
|
|
|
|
delays.each do |delay|
|
2009-07-16 02:37:22 -04:00
|
|
|
begin
|
|
|
|
sleep(delay)
|
|
|
|
yield
|
|
|
|
break
|
2009-07-19 19:06:33 -04:00
|
|
|
rescue => error
|
2009-07-25 21:05:49 -04:00
|
|
|
raise error if delay >= max_delay
|
2009-07-16 02:37:22 -04:00
|
|
|
end
|
2009-05-19 02:06:49 -04:00
|
|
|
end
|
2009-07-16 02:37:22 -04:00
|
|
|
end
|