lib/rubber/cloud/digital_ocean.rb in rubber-2.16.0 vs lib/rubber/cloud/digital_ocean.rb in rubber-3.0.0

- old
+ new

@@ -56,10 +56,20 @@ # Check if the SSH key has been added to DigitalOcean yet. # TODO (nirvdrum 03/23/13): DigitalOcean has an API for getting a single SSH key, but it hasn't been added to fog yet. We should add it. ssh_key = compute_provider.list_ssh_keys.body['ssh_keys'].find { |key| key['name'] == env.key_name } if ssh_key.nil? if env.key_file - ssh_key = compute_provider.create_ssh_key(env.key_name, File.read("#{env.key_file}.pub")) + compute_provider.create_ssh_key(env.key_name, File.read("#{env.key_file}.pub")) + + # Although not documented, DigitalOcean is eventually consistent. Receiving a 200 response with the key + # body does not mean the key has propagated through their systems yet. Thus we need to query to see if + # the key is yet available. Otherwise our request will end up creating a droplet without an attached key. + + begin + sleep(0.5) + ssh_key = compute_provider.list_ssh_keys.body['ssh_keys'].find { |key| key['name'] == env.key_name } + end while ssh_key.nil? + else raise 'Missing key_file for DigitalOcean' end end