Class: SSHKit::Backend::Netssh

Inherits:
Printer show all
Includes:
CommandHelper
Defined in:
lib/sshkit/backends/netssh.rb

Defined Under Namespace

Classes: Configuration

Instance Attribute Summary

Attributes inherited from Abstract

#host

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CommandHelper

#make, #rake

Methods inherited from Abstract

#as, #debug, #error, #fatal, #info, #initialize, #log, #make, #rake, #trace, #warn, #with, #within

Constructor Details

This class inherits a constructor from SSHKit::Backend::Abstract

Class Method Details

.configObject



89
90
91
# File 'lib/sshkit/backends/netssh.rb', line 89

def config
  @config ||= Configuration.new
end

.configure {|config| ... } ⇒ Object

Yields:



85
86
87
# File 'lib/sshkit/backends/netssh.rb', line 85

def configure
  yield config
end

Instance Method Details

#background(*args) ⇒ Object



52
53
54
55
# File 'lib/sshkit/backends/netssh.rb', line 52

def background(*args)
  options = args.extract_options!.merge(run_in_background: true)
  _execute(*[*args, options]).success?
end

#capture(*args) ⇒ Object



57
58
59
60
# File 'lib/sshkit/backends/netssh.rb', line 57

def capture(*args)
  options = args.extract_options!.merge(verbosity: Logger::DEBUG)
  _execute(*[*args, options]).full_stdout.strip
end

#download!(remote, local = nil, options = {}) ⇒ Object



73
74
75
76
77
78
79
80
81
82
# File 'lib/sshkit/backends/netssh.rb', line 73

def download!(remote, local=nil, options = {})
  ssh.scp.download!(remote, local, options) do |ch, name, received, total|
    percentage = (received.to_f * 100 / total.to_f).to_i
    if percentage > 0 && percentage % 10 == 0
      info "Downloading #{name} #{percentage}%"
    else
      debug "Downloading #{name} #{percentage}%"
    end
  end
end

#execute(*args) ⇒ Object



48
49
50
# File 'lib/sshkit/backends/netssh.rb', line 48

def execute(*args)
  _execute(*args).success?
end

#runObject



36
37
38
# File 'lib/sshkit/backends/netssh.rb', line 36

def run
  instance_exec(host, &@block)
end

#test(*args) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/sshkit/backends/netssh.rb', line 40

def test(*args)
  options = args.extract_options!.merge(
    raise_on_non_zero_exit: false,
    verbosity: Logger::DEBUG
  )
  _execute(*[*args, options]).success?
end

#upload!(local, remote, options = {}) ⇒ Object



62
63
64
65
66
67
68
69
70
71
# File 'lib/sshkit/backends/netssh.rb', line 62

def upload!(local, remote, options = {})
  ssh.scp.upload!(local, remote, options) do |ch, name, sent, total|
    percentage = (sent.to_f * 100 / total.to_f).to_i
    if percentage > 0 && percentage % 10 == 0
      info "Uploading #{name} #{percentage}%"
    else
      debug "Uploading #{name} #{percentage}%"
    end
  end
end