Class: Yun::Ssh
- Inherits:
-
Object
- Object
- Yun::Ssh
- Defined in:
- lib/yun/model/ssh.rb
Instance Attribute Summary collapse
-
#executor ⇒ Object
Returns the value of attribute executor.
Instance Method Summary collapse
- #chef(role) ⇒ Object
- #connect ⇒ Object
-
#initialize(host, ssh_config) ⇒ Ssh
constructor
A new instance of Ssh.
- #is_ssh_ready? ⇒ Boolean
Constructor Details
#initialize(host, ssh_config) ⇒ Ssh
Returns a new instance of Ssh.
9 10 11 12 13 |
# File 'lib/yun/model/ssh.rb', line 9 def initialize host, ssh_config @host = host @ssh_config = ssh_config self.executor = Yun::CommandExecutor.new end |
Instance Attribute Details
#executor ⇒ Object
Returns the value of attribute executor.
7 8 9 |
# File 'lib/yun/model/ssh.rb', line 7 def executor @executor end |
Instance Method Details
#chef(role) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/yun/model/ssh.rb', line 30 def chef role Net::SSH.start(@host, user, :keys => [key_file]) do |ssh| puts "packaging chef repo" tmp_chef_repo_tar = make_chef_repo_tar Config.chef_repo puts "uploading chef repo" ssh.scp.upload! tmp_chef_repo_tar, tmp_chef_repo_tar ssh.scp.upload! install_chef_file, "/tmp/install_chef_file.sh" ssh.scp.upload! chef_config_file, "/tmp/chef-solo.rb" puts "installing chef" remote_command ssh, "bash /tmp/install_chef_file.sh" remote_command ssh, "echo {\\\"run_list\\\":\\\"role[#{role}]\\\"} > /tmp/node.json" puts "executing chef" remote_command ssh, "sudo chef-solo -c /tmp/chef-solo.rb -j /tmp/node.json -r /tmp/chef-solo.tar.gz" puts "**********" puts "DONE" end end |
#connect ⇒ Object
15 16 17 18 19 |
# File 'lib/yun/model/ssh.rb', line 15 def connect ssh_command = "ssh -i #{key_file} #{user}@#{@host}" puts ssh_command executor.sys_exec ssh_command end |
#is_ssh_ready? ⇒ Boolean
21 22 23 24 25 26 27 28 |
# File 'lib/yun/model/ssh.rb', line 21 def is_ssh_ready? tcp_socket = TCPSocket.new(@host, 22) IO.select([tcp_socket], nil, nil, 10) rescue Exception false ensure tcp_socket && tcp_socket.close end |