Class: Masterbaker::Remote

Inherits:
Object
  • Object
show all
Defined in:
lib/masterbaker/remote.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, host, key, options = {}) ⇒ Remote

Returns a new instance of Remote.



17
18
19
20
21
22
# File 'lib/masterbaker/remote.rb', line 17

def initialize(user, host, key, options = {})
  @user = user
  @host = host
  @key = File.expand_path(key)
  @timeout = options[:timeout] || 10000
end

Instance Attribute Details

#connection=(value) ⇒ Object

Sets the attribute connection

Parameters:

  • value

    the value to set the attribute connection to.



10
11
12
# File 'lib/masterbaker/remote.rb', line 10

def connection=(value)
  @connection = value
end

#exitstatusObject (readonly)

Returns the value of attribute exitstatus.



9
10
11
# File 'lib/masterbaker/remote.rb', line 9

def exitstatus
  @exitstatus
end

#hostObject (readonly)

Returns the value of attribute host.



9
10
11
# File 'lib/masterbaker/remote.rb', line 9

def host
  @host
end

#keyObject (readonly)

Returns the value of attribute key.



9
10
11
# File 'lib/masterbaker/remote.rb', line 9

def key
  @key
end

#stderrObject (readonly)

Returns the value of attribute stderr.



9
10
11
# File 'lib/masterbaker/remote.rb', line 9

def stderr
  @stderr
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



9
10
11
# File 'lib/masterbaker/remote.rb', line 9

def stdout
  @stdout
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



9
10
11
# File 'lib/masterbaker/remote.rb', line 9

def timeout
  @timeout
end

#userObject (readonly)

Returns the value of attribute user.



9
10
11
# File 'lib/masterbaker/remote.rb', line 9

def user
  @user
end

Class Method Details

.from_uri(uri, key = "~/.ssh/id_rsa") ⇒ Object



12
13
14
15
# File 'lib/masterbaker/remote.rb', line 12

def self.from_uri(uri, key = "~/.ssh/id_rsa")
  parsed = URI.parse("ssh://#{uri}")
  new(parsed.user || Etc.getlogin, parsed.host, key)
end

Instance Method Details

#backtick(command) ⇒ Object



24
25
26
27
28
29
# File 'lib/masterbaker/remote.rb', line 24

def backtick(command)
  @stdout = ""
  @stderr = ""
  exec(command)
  @stdout
end

#system(command) ⇒ Object



31
32
33
34
35
36
# File 'lib/masterbaker/remote.rb', line 31

def system(command)
  @stdout = STDOUT
  @stderr = STDERR
  exec(command)
  exitstatus
end

#system!(*command) ⇒ Object



38
39
40
41
42
# File 'lib/masterbaker/remote.rb', line 38

def system!(*command)
  system(*command).tap do |status|
    raise RemoteError.new("#{command.join(" ")} exited #{status}") unless status == 0
  end
end

#upload(from, to, opts = "--exclude .git") ⇒ Object



44
45
46
# File 'lib/masterbaker/remote.rb', line 44

def upload(from, to, opts = "--exclude .git")
  Kernel.system("rsync -e 'ssh -i #{key}' -avz --delete #{from} #{user}@#{host}:#{to} #{opts}")
end