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
- #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.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/kanrisuru/remote/host.rb', line 14 def initialize(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.
12 13 14 |
# File 'lib/kanrisuru/remote/host.rb', line 12 def host @host end |
#keys ⇒ Object (readonly)
Returns the value of attribute keys.
12 13 14 |
# File 'lib/kanrisuru/remote/host.rb', line 12 def keys @keys end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
12 13 14 |
# File 'lib/kanrisuru/remote/host.rb', line 12 def password @password end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
12 13 14 |
# File 'lib/kanrisuru/remote/host.rb', line 12 def port @port end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
12 13 14 |
# File 'lib/kanrisuru/remote/host.rb', line 12 def username @username end |
Instance Method Details
#cd(path = '~') ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/kanrisuru/remote/host.rb', line 55 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
51 52 53 |
# File 'lib/kanrisuru/remote/host.rb', line 51 def chdir(path = '~') cd(path) end |
#cpu ⇒ Object
70 71 72 |
# File 'lib/kanrisuru/remote/host.rb', line 70 def cpu @cpu ||= init_cpu end |
#disconnect ⇒ Object
111 112 113 |
# File 'lib/kanrisuru/remote/host.rb', line 111 def disconnect ssh.close end |
#env ⇒ Object
39 40 41 |
# File 'lib/kanrisuru/remote/host.rb', line 39 def env @env ||= init_env end |
#execute(command) ⇒ Object
106 107 108 109 |
# File 'lib/kanrisuru/remote/host.rb', line 106 def execute(command) command = Kanrisuru::Command.new(command) if command.instance_of?(String) execute_with_retries(command) end |
#execute_shell(command) ⇒ Object
95 96 97 98 99 100 101 102 103 104 |
# File 'lib/kanrisuru/remote/host.rb', line 95 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
82 83 84 |
# File 'lib/kanrisuru/remote/host.rb', line 82 def file(path) Kanrisuru::Remote::File.new(path, self) end |
#fstab(file = '/etc/fstab') ⇒ Object
47 48 49 |
# File 'lib/kanrisuru/remote/host.rb', line 47 def fstab(file = '/etc/fstab') @fstab ||= init_fstab(file) end |
#hostname ⇒ Object
31 32 33 |
# File 'lib/kanrisuru/remote/host.rb', line 31 def hostname @hostname ||= init_hostname end |
#memory ⇒ Object
74 75 76 |
# File 'lib/kanrisuru/remote/host.rb', line 74 def memory @memory ||= init_memory end |
#os ⇒ Object
35 36 37 |
# File 'lib/kanrisuru/remote/host.rb', line 35 def os @os ||= init_os end |
#ping? ⇒ Boolean
90 91 92 93 |
# File 'lib/kanrisuru/remote/host.rb', line 90 def ping? check = Net::Ping::External.new(@host) check.ping? end |
#remote_user ⇒ Object
27 28 29 |
# File 'lib/kanrisuru/remote/host.rb', line 27 def remote_user @remote_user ||= @username end |
#ssh ⇒ Object
86 87 88 |
# File 'lib/kanrisuru/remote/host.rb', line 86 def ssh @ssh ||= Net::SSH.start(@host, @username, keys: @keys, password: @password, port: @port) end |
#su(user) ⇒ Object
78 79 80 |
# File 'lib/kanrisuru/remote/host.rb', line 78 def su(user) @remote_user = user end |