Class: Gusteau::Server
- Inherits:
-
Object
- Object
- Gusteau::Server
- Defined in:
- lib/gusteau/server.rb
Instance Attribute Summary collapse
-
#chef ⇒ Object
readonly
Returns the value of attribute chef.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
-
#initialize(config) ⇒ Server
constructor
A new instance of Server.
- #run(*cmds) ⇒ Object
- #ssh ⇒ Object
- #to_s ⇒ Object
- #upload(files_and_dirs, dest_dir, opts = {}) ⇒ Object
Methods included from SSH
#conn, #send_command, #send_files
Methods included from Log
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
#chef ⇒ Object (readonly)
Returns the value of attribute chef.
10 11 12 |
# File 'lib/gusteau/server.rb', line 10 def chef @chef end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
10 11 12 |
# File 'lib/gusteau/server.rb', line 10 def host @host end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
10 11 12 |
# File 'lib/gusteau/server.rb', line 10 def password @password end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
10 11 12 |
# File 'lib/gusteau/server.rb', line 10 def port @port end |
#user ⇒ Object (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 |
#ssh ⇒ Object
46 47 48 49 |
# File 'lib/gusteau/server.rb', line 46 def ssh ssh_expect = File.("../../../bin/gusteau_ssh_expect", __FILE__) Kernel.system "#{ssh_expect} #{@user}@#{@host} #{@port} #{@password}" end |
#to_s ⇒ Object
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 |