Class: DRbQS::Manage::SSHShell
- Inherits:
-
Object
- Object
- DRbQS::Manage::SSHShell
- Defined in:
- lib/drbqs/manage/ssh_shell.rb
Overview
Requirements:
- bash
Defined Under Namespace
Classes: RubyEnvironment
Constant Summary collapse
- DEFAULT_SHELL =
'bash'
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#keys ⇒ Object
readonly
Returns the value of attribute keys.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #directory ⇒ Object
- #exec(cmd, opts = {}) ⇒ Object
- #execute_all(commands, opts = {}) ⇒ Object
- #get_environment ⇒ Object
-
#initialize(dest, opts = {}) ⇒ SSHShell
constructor
A new instance of SSHShell.
- #start(&block) ⇒ Object
Constructor Details
#initialize(dest, opts = {}) ⇒ SSHShell
Returns a new instance of SSHShell.
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/drbqs/manage/ssh_shell.rb', line 70 def initialize(dest, opts = {}) @user, @host, @port = split_destination(dest) if !(@host && @user) raise ArgumentError, "Invalid ssh server: host=#{@host.inspect}, user=#{@user.inspect}." end @keys = opts.delete(:keys) @shell = opts.delete(:shell) || DEFAULT_SHELL @ruby_environment = DRbQS::Manage::SSHShell::RubyEnvironment.new(opts) @out = opts[:io] @ssh = nil end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
57 58 59 |
# File 'lib/drbqs/manage/ssh_shell.rb', line 57 def host @host end |
#keys ⇒ Object (readonly)
Returns the value of attribute keys.
57 58 59 |
# File 'lib/drbqs/manage/ssh_shell.rb', line 57 def keys @keys end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
57 58 59 |
# File 'lib/drbqs/manage/ssh_shell.rb', line 57 def port @port end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
57 58 59 |
# File 'lib/drbqs/manage/ssh_shell.rb', line 57 def user @user end |
Instance Method Details
#directory ⇒ Object
82 83 84 |
# File 'lib/drbqs/manage/ssh_shell.rb', line 82 def directory @ruby_environment.directory end |
#exec(cmd, opts = {}) ⇒ Object
146 147 148 149 150 151 152 153 154 155 |
# File 'lib/drbqs/manage/ssh_shell.rb', line 146 def exec(cmd, opts = {}) unless @ssh raise "Not connect." end if opts[:check] shell_exec_check(@ssh, cmd) else shell_exec(@ssh, cmd) end end |
#execute_all(commands, opts = {}) ⇒ Object
175 176 177 178 179 180 181 182 183 |
# File 'lib/drbqs/manage/ssh_shell.rb', line 175 def execute_all(commands, opts = {}) results = [] start do |ssh_shell| commands.each do |cmd| results << ssh_shell.exec(cmd, opts) end end results end |
#get_environment ⇒ Object
185 186 187 |
# File 'lib/drbqs/manage/ssh_shell.rb', line 185 def get_environment execute_all(@ruby_environment.get_environment_commands) end |
#start(&block) ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/drbqs/manage/ssh_shell.rb', line 157 def start(&block) Net::SSH.start(@host, @user, :port => @port, :keys => @keys) do |ssh| ssh.shell(@shell) do |sh| @ruby_environment.setup_commands.each do |cmd| shell_exec_check(sh, cmd) end @ssh = sh yield(self) shell_exec(sh, "exit") end end ensure @ssh = nil end |