Class: CCSH::Host
- Inherits:
-
Object
- Object
- CCSH::Host
- Defined in:
- lib/ccsh/host.rb
Instance Attribute Summary collapse
-
#groups ⇒ Object
Returns the value of attribute groups.
-
#hostname ⇒ Object
Returns the value of attribute hostname.
-
#name ⇒ Object
Returns the value of attribute name.
-
#password ⇒ Object
Returns the value of attribute password.
-
#port ⇒ Object
Returns the value of attribute port.
-
#private_key ⇒ Object
Returns the value of attribute private_key.
-
#ssh_options ⇒ Object
Returns the value of attribute ssh_options.
-
#sudo_enabled ⇒ Object
Returns the value of attribute sudo_enabled.
-
#sudo_password ⇒ Object
Returns the value of attribute sudo_password.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #contain?(target) ⇒ Boolean
-
#initialize ⇒ Host
constructor
A new instance of Host.
- #run(command) ⇒ Object
Constructor Details
#initialize ⇒ Host
Returns a new instance of Host.
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/ccsh/host.rb', line 15 def initialize @name = '' @port = 22 @user = 'root' @groups = '' @hostname = '127.0.0.1' @password = nil @private_key = nil @ssh_options = [] @sudo_enabled = false @sudo_password = @password end |
Instance Attribute Details
#groups ⇒ Object
Returns the value of attribute groups.
6 7 8 |
# File 'lib/ccsh/host.rb', line 6 def groups @groups end |
#hostname ⇒ Object
Returns the value of attribute hostname.
7 8 9 |
# File 'lib/ccsh/host.rb', line 7 def hostname @hostname end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/ccsh/host.rb', line 3 def name @name end |
#password ⇒ Object
Returns the value of attribute password.
8 9 10 |
# File 'lib/ccsh/host.rb', line 8 def password @password end |
#port ⇒ Object
Returns the value of attribute port.
4 5 6 |
# File 'lib/ccsh/host.rb', line 4 def port @port end |
#private_key ⇒ Object
Returns the value of attribute private_key.
9 10 11 |
# File 'lib/ccsh/host.rb', line 9 def private_key @private_key end |
#ssh_options ⇒ Object
Returns the value of attribute ssh_options.
10 11 12 |
# File 'lib/ccsh/host.rb', line 10 def @ssh_options end |
#sudo_enabled ⇒ Object
Returns the value of attribute sudo_enabled.
12 13 14 |
# File 'lib/ccsh/host.rb', line 12 def sudo_enabled @sudo_enabled end |
#sudo_password ⇒ Object
Returns the value of attribute sudo_password.
13 14 15 |
# File 'lib/ccsh/host.rb', line 13 def sudo_password @sudo_password end |
#timeout ⇒ Object
Returns the value of attribute timeout.
11 12 13 |
# File 'lib/ccsh/host.rb', line 11 def timeout @timeout end |
#user ⇒ Object
Returns the value of attribute user.
5 6 7 |
# File 'lib/ccsh/host.rb', line 5 def user @user end |
Instance Method Details
#contain?(target) ⇒ Boolean
48 49 50 |
# File 'lib/ccsh/host.rb', line 48 def contain?(target) return @groups.include? target end |
#run(command) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ccsh/host.rb', line 28 def run(command) CCSH::Utils.debug("Running command '#{command}' on #{@hostname}") command = CCSH::SSH.start do |ssh| ssh.user = @user ssh.port = @port ssh. = @ssh_options ssh.password = @password ssh.private_key = @private_key ssh. = @ssh_options ssh.enable_sudo = @sudo_enabled ssh.sudo_password = @sudo_password ssh.command = command ssh.hostname = @hostname || @name end return command end |