Class: Toolshed::ServerAdministration::SSH

Inherits:
Object
  • Object
show all
Defined in:
lib/toolshed/server_administration/ssh.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ SSH

Returns a new instance of SSH.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/toolshed/server_administration/ssh.rb', line 8

def initialize(options={})
  self.password = options[:password] ||= ''
  self.sudo_password = options[:sudo_password] ||= ''
  self.keys = options[:keys] ||= ''
  self.host = options[:host] ||= ''
  self.user = options[:user] ||= ''
  self.ssh_options = options[:ssh_options] ||= {}
  self.commands = options[:commands] ||= ''
  self.password = Toolshed::Password.new(options)

  set_ssh_options
end

Instance Attribute Details

#channelObject

Returns the value of attribute channel.



6
7
8
# File 'lib/toolshed/server_administration/ssh.rb', line 6

def channel
  @channel
end

#commandsObject

Returns the value of attribute commands.



6
7
8
# File 'lib/toolshed/server_administration/ssh.rb', line 6

def commands
  @commands
end

#hostObject

Returns the value of attribute host.



6
7
8
# File 'lib/toolshed/server_administration/ssh.rb', line 6

def host
  @host
end

#keysObject

Returns the value of attribute keys.



6
7
8
# File 'lib/toolshed/server_administration/ssh.rb', line 6

def keys
  @keys
end

#passwordObject

Returns the value of attribute password.



6
7
8
# File 'lib/toolshed/server_administration/ssh.rb', line 6

def password
  @password
end

#ssh_optionsObject

Returns the value of attribute ssh_options.



6
7
8
# File 'lib/toolshed/server_administration/ssh.rb', line 6

def ssh_options
  @ssh_options
end

#sudo_passwordObject

Returns the value of attribute sudo_password.



6
7
8
# File 'lib/toolshed/server_administration/ssh.rb', line 6

def sudo_password
  @sudo_password
end

#userObject

Returns the value of attribute user.



6
7
8
# File 'lib/toolshed/server_administration/ssh.rb', line 6

def user
  @user
end

Instance Method Details

#executeObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/toolshed/server_administration/ssh.rb', line 21

def execute
  Net::SSH.start(self.host, self.user, self.ssh_options) do |ssh|
    ssh.open_channel do |channel|
      self.channel = channel
      request_pty
      run_commands
    end
    ssh.loop
  end
end