Class: CCSH::Host

Inherits:
Object
  • Object
show all
Defined in:
lib/ccsh/host.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHost

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

#groupsObject

Returns the value of attribute groups.



6
7
8
# File 'lib/ccsh/host.rb', line 6

def groups
  @groups
end

#hostnameObject

Returns the value of attribute hostname.



7
8
9
# File 'lib/ccsh/host.rb', line 7

def hostname
  @hostname
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/ccsh/host.rb', line 3

def name
  @name
end

#passwordObject

Returns the value of attribute password.



8
9
10
# File 'lib/ccsh/host.rb', line 8

def password
  @password
end

#portObject

Returns the value of attribute port.



4
5
6
# File 'lib/ccsh/host.rb', line 4

def port
  @port
end

#private_keyObject

Returns the value of attribute private_key.



9
10
11
# File 'lib/ccsh/host.rb', line 9

def private_key
  @private_key
end

#ssh_optionsObject

Returns the value of attribute ssh_options.



10
11
12
# File 'lib/ccsh/host.rb', line 10

def ssh_options
  @ssh_options
end

#sudo_enabledObject

Returns the value of attribute sudo_enabled.



12
13
14
# File 'lib/ccsh/host.rb', line 12

def sudo_enabled
  @sudo_enabled
end

#sudo_passwordObject

Returns the value of attribute sudo_password.



13
14
15
# File 'lib/ccsh/host.rb', line 13

def sudo_password
  @sudo_password
end

#timeoutObject

Returns the value of attribute timeout.



11
12
13
# File 'lib/ccsh/host.rb', line 11

def timeout
  @timeout
end

#userObject

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

Returns:

  • (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.options = @ssh_options
        ssh.password = @password
        ssh.private_key = @private_key
        ssh.options = @ssh_options
        ssh.enable_sudo = @sudo_enabled
        ssh.sudo_password = @sudo_password

        ssh.command = command
        ssh.hostname = @hostname || @name
    end

    return command
end