Class: Toolshed::ServerAdministration::SSH
- Inherits:
-
Object
- Object
- Toolshed::ServerAdministration::SSH
- Includes:
- Password
- Defined in:
- lib/toolshed/server_administration/ssh.rb
Overview
SSH class that can ssh to a host and perform commands
Instance Attribute Summary collapse
-
#channel ⇒ Object
rubocop:disable LineLength.
-
#commands ⇒ Object
rubocop:disable LineLength.
-
#data ⇒ Object
rubocop:disable LineLength.
-
#host ⇒ Object
rubocop:disable LineLength.
-
#keys ⇒ Object
rubocop:disable LineLength.
-
#password ⇒ Object
rubocop:disable LineLength.
-
#silent ⇒ Object
readonly
Returns the value of attribute silent.
-
#ssh_options ⇒ Object
rubocop:disable LineLength.
-
#sudo_password ⇒ Object
rubocop:disable LineLength.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
-
#user ⇒ Object
rubocop:disable LineLength.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(options = nil) ⇒ SSH
constructor
rubocop:disable AbcSize, CyclomaticComplexity, PerceivedComplexity, LineLength.
Methods included from Password
Constructor Details
#initialize(options = nil) ⇒ SSH
rubocop:disable AbcSize, CyclomaticComplexity, PerceivedComplexity, LineLength
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/toolshed/server_administration/ssh.rb', line 16 def initialize( = nil) # rubocop:disable AbcSize, CyclomaticComplexity, PerceivedComplexity, LineLength ||= {} @password = [:password] || '' @sudo_password = [:sudo_password] || '' @keys = [:keys] || '' @host = [:host] || '' @user = [:user] || '' @ssh_options = [:ssh_options] || {} @commands = [:commands] || '' @password = [:password] || '' @data = [] @silent = [:silent] || false timeout_period = [:timeout_period].to_i || 30 @timeout = Toolshed::Timeout.new(timeout_period: timeout_period) end |
Instance Attribute Details
#channel ⇒ Object
rubocop:disable LineLength
13 14 15 |
# File 'lib/toolshed/server_administration/ssh.rb', line 13 def channel @channel end |
#commands ⇒ Object
rubocop:disable LineLength
13 14 15 |
# File 'lib/toolshed/server_administration/ssh.rb', line 13 def commands @commands end |
#data ⇒ Object
rubocop:disable LineLength
13 14 15 |
# File 'lib/toolshed/server_administration/ssh.rb', line 13 def data @data end |
#host ⇒ Object
rubocop:disable LineLength
13 14 15 |
# File 'lib/toolshed/server_administration/ssh.rb', line 13 def host @host end |
#keys ⇒ Object
rubocop:disable LineLength
13 14 15 |
# File 'lib/toolshed/server_administration/ssh.rb', line 13 def keys @keys end |
#password ⇒ Object
rubocop:disable LineLength
13 14 15 |
# File 'lib/toolshed/server_administration/ssh.rb', line 13 def password @password end |
#silent ⇒ Object (readonly)
Returns the value of attribute silent.
14 15 16 |
# File 'lib/toolshed/server_administration/ssh.rb', line 14 def silent @silent end |
#ssh_options ⇒ Object
rubocop:disable LineLength
13 14 15 |
# File 'lib/toolshed/server_administration/ssh.rb', line 13 def @ssh_options end |
#sudo_password ⇒ Object
rubocop:disable LineLength
13 14 15 |
# File 'lib/toolshed/server_administration/ssh.rb', line 13 def sudo_password @sudo_password end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
14 15 16 |
# File 'lib/toolshed/server_administration/ssh.rb', line 14 def timeout @timeout end |
#user ⇒ Object
rubocop:disable LineLength
13 14 15 |
# File 'lib/toolshed/server_administration/ssh.rb', line 13 def user @user end |
Instance Method Details
#execute ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/toolshed/server_administration/ssh.rb', line 34 def execute begin timeout.start do Net::SSH.start(host, user, ) do |ssh| ssh.open_channel do |channel| self.channel = channel request_pty run_commands end ssh.loop end end rescue Toolshed::Timeout::Error => e Toolshed.logger.fatal e. raise SSHResponseException, "Unable to handle response for #{data.last}" end data end |