Module: Remotus
- Defined in:
- lib/remotus.rb,
lib/remotus/auth.rb,
lib/remotus/pool.rb,
lib/remotus/logger.rb,
lib/remotus/result.rb,
lib/remotus/version.rb,
lib/remotus/host_pool.rb,
lib/remotus/auth/store.rb,
lib/remotus/ssh_connection.rb,
lib/remotus/auth/credential.rb,
lib/remotus/auth/hash_store.rb,
lib/remotus/core_ext/string.rb,
lib/remotus/winrm_connection.rb,
lib/remotus/core_ext/elevated.rb
Overview
Contains classes and methods for creating remote connections and running commands
Defined Under Namespace
Modules: Auth, CoreExt Classes: AuthenticationError, Error, HostPool, HostTypeDeterminationError, InvalidMetadataKey, Logger, MissingCredential, MissingOverride, MissingSudoPassword, Pool, PtyError, Result, ResultError, SshConnection, WinrmConnection
Constant Summary collapse
- VERSION =
Remotus gem version
"1.2.0"
Class Method Summary collapse
-
.clear ⇒ Integer
Removes all host pools from the pool in a thread-safe manner.
-
.connect(host, **options) ⇒ Remotus::HostPool
Creates/gets a host pool for the host that can be used to perform remote operations.
-
.count ⇒ Integer
Number of host pools in the connection pool.
-
.host_type(host, timeout: 1) ⇒ Symbol?
Determine remote host type by checking common ports.
-
.log_formatter ⇒ ::Logger::Formatter
Gets the remotus log formatter.
-
.log_formatter=(log_formatter) ⇒ Object
Sets the remotus log formatter.
-
.logger ⇒ Remotus::Logger
Gets the remotus logger.
-
.logger=(logger) ⇒ Object
Sets the remotus logger.
-
.port_open?(host, port, timeout: 1) ⇒ Boolean
Checks if a remote port is open.
Class Method Details
.clear ⇒ Integer
Removes all host pools from the pool in a thread-safe manner
45 46 47 |
# File 'lib/remotus.rb', line 45 def self.clear Remotus::Pool.clear end |
.connect(host, **options) ⇒ Remotus::HostPool
Creates/gets a host pool for the host that can be used to perform remote operations. After creation, the host pool will persist for future connections.
27 28 29 |
# File 'lib/remotus.rb', line 27 def self.connect(host, **) Remotus::Pool.connect(host, **) end |
.count ⇒ Integer
Number of host pools in the connection pool
36 37 38 |
# File 'lib/remotus.rb', line 36 def self.count Remotus::Pool.count end |
.host_type(host, timeout: 1) ⇒ Symbol?
Determine remote host type by checking common ports
74 75 76 77 78 79 80 |
# File 'lib/remotus.rb', line 74 def self.host_type(host, timeout: 1) return :ssh if port_open?(host, SshConnection::REMOTE_PORT, timeout: timeout) return :winrm if port_open?(host, WinrmConnection::REMOTE_PORT, timeout: timeout) nil end |
.log_formatter ⇒ ::Logger::Formatter
Gets the remotus log formatter
109 110 111 |
# File 'lib/remotus.rb', line 109 def self.log_formatter @log_formatter ||= logger.formatter end |
.log_formatter=(log_formatter) ⇒ Object
Sets the remotus log formatter
118 119 120 121 |
# File 'lib/remotus.rb', line 118 def self.log_formatter=(log_formatter) @log_formatter = log_formatter logger.formatter = log_formatter end |
.logger ⇒ Remotus::Logger
Gets the remotus logger
87 88 89 |
# File 'lib/remotus.rb', line 87 def self.logger @logger ||= Remotus::Logger.new($stdout, level: Logger::INFO) end |
.logger=(logger) ⇒ Object
Sets the remotus logger
96 97 98 99 100 101 102 |
# File 'lib/remotus.rb', line 96 def self.logger=(logger) if logger.nil? self.logger.level = Logger::FATAL return self.logger end @logger = logger end |
.port_open?(host, port, timeout: 1) ⇒ Boolean
Checks if a remote port is open
58 59 60 61 62 63 64 |
# File 'lib/remotus.rb', line 58 def self.port_open?(host, port, timeout: 1) logger.debug { "Checking if #{host}:#{port} is accessible" } Socket.tcp(host, port, connect_timeout: timeout) { true } rescue StandardError logger.debug { "#{host}:#{port} is inaccessible" } false end |