Class: Kanrisuru::Remote::Host
- Inherits:
-
Object
- Object
- Kanrisuru::Remote::Host
- Extended by:
- OsPackage::Include
- Defined in:
- lib/kanrisuru/core.rb,
lib/kanrisuru/remote/host.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#keys ⇒ Object
readonly
Returns the value of attribute keys.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #cd(path = '~') ⇒ Object
- #chdir(path = '~') ⇒ Object
- #cpu ⇒ Object
- #disconnect ⇒ Object
- #env ⇒ Object
- #execute(command) ⇒ Object
- #execute_shell(command) ⇒ Object
- #file(path) ⇒ Object
- #fstab(file = '/etc/fstab') ⇒ Object
- #hostname ⇒ Object
-
#initialize(opts = {}) ⇒ Host
constructor
A new instance of Host.
- #memory ⇒ Object
- #os ⇒ Object
- #ping? ⇒ Boolean
- #proxy ⇒ Object
- #remote_user ⇒ Object
- #ssh ⇒ Object
- #su(user) ⇒ Object
- #template(path, args = {}) ⇒ Object
Methods included from OsPackage::Include
Constructor Details
#initialize(opts = {}) ⇒ Host
Returns a new instance of Host.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/kanrisuru/remote/host.rb', line 15 def initialize(opts = {}) @opts = opts @host = opts[:host] @username = opts[:username] @login_user = @username @port = opts[:port] || 22 @password = opts[:password] if opts[:password] @keys = opts[:keys] if opts[:keys] @shell = opts[:shell] || '/bin/bash' @current_dir = '' end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
13 14 15 |
# File 'lib/kanrisuru/remote/host.rb', line 13 def host @host end |
#keys ⇒ Object (readonly)
Returns the value of attribute keys.
13 14 15 |
# File 'lib/kanrisuru/remote/host.rb', line 13 def keys @keys end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
13 14 15 |
# File 'lib/kanrisuru/remote/host.rb', line 13 def password @password end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
13 14 15 |
# File 'lib/kanrisuru/remote/host.rb', line 13 def port @port end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
13 14 15 |
# File 'lib/kanrisuru/remote/host.rb', line 13 def username @username end |
Instance Method Details
#cd(path = '~') ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/kanrisuru/remote/host.rb', line 58 def cd(path = '~') @current_dir = pwd.path if Kanrisuru::Util.blank?(@current_dir) @current_dir = if path == '~' realpath('~').path elsif path[0] == '.' || path[0] != '/' ## Use strip to preserve symlink directories realpath("#{@current_dir}/#{path}", strip: true).path else ## Use strip to preserve symlink directories realpath(path, strip: true).path end end |
#chdir(path = '~') ⇒ Object
54 55 56 |
# File 'lib/kanrisuru/remote/host.rb', line 54 def chdir(path = '~') cd(path) end |
#cpu ⇒ Object
73 74 75 |
# File 'lib/kanrisuru/remote/host.rb', line 73 def cpu @cpu ||= init_cpu end |
#disconnect ⇒ Object
118 119 120 121 |
# File 'lib/kanrisuru/remote/host.rb', line 118 def disconnect ssh.close proxy&.close(ssh.transport.port) end |
#env ⇒ Object
42 43 44 |
# File 'lib/kanrisuru/remote/host.rb', line 42 def env @env ||= init_env end |
#execute(command) ⇒ Object
113 114 115 116 |
# File 'lib/kanrisuru/remote/host.rb', line 113 def execute(command) command = Kanrisuru::Command.new(command) if command.instance_of?(String) execute_with_retries(command) end |
#execute_shell(command) ⇒ Object
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/kanrisuru/remote/host.rb', line 102 def execute_shell(command) command = Kanrisuru::Command.new(command) if command.instance_of?(String) command.remote_user = remote_user command.remote_shell = @shell command.remote_path = @current_dir command.remote_env = env.to_s execute_with_retries(command) end |
#file(path) ⇒ Object
85 86 87 |
# File 'lib/kanrisuru/remote/host.rb', line 85 def file(path) Kanrisuru::Remote::File.new(path, self) end |
#fstab(file = '/etc/fstab') ⇒ Object
50 51 52 |
# File 'lib/kanrisuru/remote/host.rb', line 50 def fstab(file = '/etc/fstab') @fstab ||= init_fstab(file) end |
#hostname ⇒ Object
34 35 36 |
# File 'lib/kanrisuru/remote/host.rb', line 34 def hostname @hostname ||= init_hostname end |
#memory ⇒ Object
77 78 79 |
# File 'lib/kanrisuru/remote/host.rb', line 77 def memory @memory ||= init_memory end |
#os ⇒ Object
38 39 40 |
# File 'lib/kanrisuru/remote/host.rb', line 38 def os @os ||= init_os end |
#ping? ⇒ Boolean
97 98 99 100 |
# File 'lib/kanrisuru/remote/host.rb', line 97 def ping? check = Net::Ping::External.new(@host) check.ping? end |
#proxy ⇒ Object
93 94 95 |
# File 'lib/kanrisuru/remote/host.rb', line 93 def proxy @proxy ||= init_proxy end |
#remote_user ⇒ Object
30 31 32 |
# File 'lib/kanrisuru/remote/host.rb', line 30 def remote_user @remote_user ||= @username end |
#ssh ⇒ Object
89 90 91 |
# File 'lib/kanrisuru/remote/host.rb', line 89 def ssh @ssh ||= init_ssh end |
#su(user) ⇒ Object
81 82 83 |
# File 'lib/kanrisuru/remote/host.rb', line 81 def su(user) @remote_user = user end |