Class: Gusteau::Server

Inherits:
Object
  • Object
show all
Includes:
Log, SSH
Defined in:
lib/gusteau/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SSH

#conn, #send_command, #send_files

Methods included from Log

#info, #log, #log_error

Constructor Details

#initialize(config) ⇒ Server

Returns a new instance of Server.



12
13
14
15
16
17
18
# File 'lib/gusteau/server.rb', line 12

def initialize(config)
  @host     = config['host']
  @port     = config['port'] || 22
  @user     = config['user'] || 'root'
  @password = config['password']
  @chef     = Gusteau::Chef.new(self, config['platform'])
end

Instance Attribute Details

#chefObject (readonly)

Returns the value of attribute chef.



10
11
12
# File 'lib/gusteau/server.rb', line 10

def chef
  @chef
end

#hostObject (readonly)

Returns the value of attribute host.



10
11
12
# File 'lib/gusteau/server.rb', line 10

def host
  @host
end

#passwordObject (readonly)

Returns the value of attribute password.



10
11
12
# File 'lib/gusteau/server.rb', line 10

def password
  @password
end

#portObject (readonly)

Returns the value of attribute port.



10
11
12
# File 'lib/gusteau/server.rb', line 10

def port
  @port
end

#userObject (readonly)

Returns the value of attribute user.



10
11
12
# File 'lib/gusteau/server.rb', line 10

def user
  @user
end

Instance Method Details

#run(*cmds) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/gusteau/server.rb', line 34

def run(*cmds)
  cmds.each do |cmd|
    log("%{host}> #{prepared_cmd cmd}", :host => host) do
      unless send_command(cmd)
        log_error("%{host}> #{prepared_cmd cmd}", :host => host)
        raise
      end
    end
  end
  true
end

#sshObject



46
47
48
49
# File 'lib/gusteau/server.rb', line 46

def ssh
  ssh_expect = File.expand_path("../../../bin/gusteau_ssh_expect", __FILE__)
  Kernel.system "#{ssh_expect} #{@user}@#{@host} #{@port} #{@password}"
end

#to_sObject



20
21
22
# File 'lib/gusteau/server.rb', line 20

def to_s
  "#{user}@#{host}#{" -p #{port}" unless port == 22}"
end

#upload(files_and_dirs, dest_dir, opts = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/gusteau/server.rb', line 24

def upload(files_and_dirs, dest_dir, opts={})
  log "#uploading #{files_and_dirs.join(' ')} to #{@host}:#{dest_dir}" do
    files = []
    Find.find(*files_and_dirs) do |f|
      files << f unless(opts[:exclude] && f.include?(opts[:exclude]))
    end
    send_files(files, dest_dir, opts[:strip_c])
  end
end