Class: Fog::Compute::AWS::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/core/mod/fog_aws_server.rb

Instance Method Summary collapse

Instance Method Details

#setup(credentials = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/core/mod/fog_aws_server.rb', line 6

def setup(credentials = {})
  requires :ssh_ip_address, :username
  
  commands = [
    %{mkdir .ssh},
    %{passwd -l #{username}},
    %{echo "#{Fog::JSON.encode(Fog::JSON.sanitize(attributes))}" >> ~/attributes.json}
  ]
  if public_key
    commands << %{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
    retry
    
  rescue Errno::ECONNREFUSED, Net::SSH::ConnectionTimeout, Net::SSH::Disconnect => error   
    if tries > 1
      sleep(sleep_secs)
      
      tries -= 1
      retry
    end
  end
end