class Fog::Compute::AWS::Server

Public Instance Methods

setup(credentials = {}) click to toggle source
# File lib/core/mod/fog_aws_server.rb, line 6
def setup(credentials = {})
  requires :ssh_ip_address, :username
  
  commands = [
    %Q{mkdir .ssh},
    %Q{passwd -l #{username}},
    %Q{echo "#{Fog::JSON.encode(Fog::JSON.sanitize(attributes))}" >> ~/attributes.json}
  ]
  if public_key
    commands << %Q{echo "#{public_key}" >> ~/.ssh/authorized_keys}
  end

  tries      = 5
  sleep_secs = 5
  
  begin      
    Nucleon::Util::SSH.session(ssh_ip_address, username, ssh_port, private_key_path, true)
    results = Nucleon::Util::SSH.exec(ssh_ip_address, username, commands)
          
  rescue Net::SSH::HostKeyMismatch => error
    error.remember_host!
    sleep 0.2
    reset = true
    retry
    
  rescue Net::SSH::ConnectionTimeout, Net::SSH::Disconnect => error     
    if tries > 1
      sleep(sleep_secs)
      
      tries -= 1
      reset  = true
      retry
    end
  end
end