class Fog::Compute::AWS::Server
Public Instance Methods
setup(credentials = {})
click to toggle source
# File lib/core/mod/fog_aws_server.rb 6 def setup(credentials = {}) 7 requires :ssh_ip_address, :username 8 9 commands = [ 10 %{mkdir .ssh}, 11 %{passwd -l #{username}}, 12 %{echo "#{Fog::JSON.encode(Fog::JSON.sanitize(attributes))}" >> ~/attributes.json} 13 ] 14 if public_key 15 commands << %{echo "#{public_key}" >> ~/.ssh/authorized_keys} 16 end 17 18 tries = 5 19 sleep_secs = 5 20 21 begin 22 Nucleon::Util::SSH.session(ssh_ip_address, username, ssh_port, private_key_path, true) 23 results = Nucleon::Util::SSH.exec(ssh_ip_address, username, commands) 24 25 rescue Net::SSH::HostKeyMismatch => error 26 error.remember_host! 27 sleep 0.2 28 retry 29 30 rescue Errno::ECONNREFUSED, Net::SSH::ConnectionTimeout, Net::SSH::Disconnect => error 31 if tries > 1 32 sleep(sleep_secs) 33 34 tries -= 1 35 retry 36 end 37 end 38 end