Class: Util
- Inherits:
-
Object
- Object
- Util
- Defined in:
- lib/util.rb
Class Method Summary collapse
- .close_ssh_session(session) ⇒ Object
- .retryable(options = {}) ⇒ Object
- .run(session, cmd) ⇒ Object
- .start_ssh_session(config) ⇒ Object
Class Method Details
.close_ssh_session(session) ⇒ Object
21 22 23 |
# File 'lib/util.rb', line 21 def self.close_ssh_session session session.close end |
.retryable(options = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/util.rb', line 37 def self.retryable = {} opts = { :tries => 1, :on => Exception }.merge() retry_exception, retries = opts[:on], opts[:tries] begin return yield rescue retry_exception if (retries -= 1) > 0 sleep 2 retry else raise end end end |
.run(session, cmd) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/util.rb', line 25 def self.run session, cmd result = "NA" begin Timeout::timeout(30) do result = session.exec!(cmd) end rescue Exception => e raise e. end result end |
.start_ssh_session(config) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/util.rb', line 5 def self.start_ssh_session config session = nil host = config[:host] user = config[:user] params = { :password => config[:password], :port => config[:port] } retryable(:tries => config[:retries] || 10) do Timeout::timeout(config[:timeout] || 10 ) do session = Net::SSH.start(host, user, params) end end session end |