Class: Ridley::HostCommander
- Inherits:
-
Object
- Object
- Ridley::HostCommander
- Includes:
- Celluloid, Logging
- Defined in:
- lib/ridley-connectors/host_commander.rb
Constant Summary collapse
- PORT_CHECK_TIMEOUT =
3
- RETRY_COUNT =
3
- DEFAULT_WINDOWS_CONNECTOR =
"winrm"
- DEFAULT_LINUX_CONNECTOR =
"ssh"
- VALID_CONNECTORS =
[ DEFAULT_WINDOWS_CONNECTOR, DEFAULT_LINUX_CONNECTOR ]
- CONNECTOR_PORT_ERRORS =
[ Errno::ETIMEDOUT, Timeout::Error, SocketError, Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::EADDRNOTAVAIL, Resolv::ResolvError ]
Instance Method Summary collapse
-
#bootstrap(host, options = {}) ⇒ HostConnector::Response
Bootstrap a node.
-
#chef_client(host, options = {}) ⇒ HostConnector::Response
Perform a chef client run on a node.
-
#connector_for(host, options = {}) ⇒ HostConnector::SSH, ...
Finds and returns the best HostConnector for a given host.
-
#initialize(connector_pool_size = nil) ⇒ HostCommander
constructor
A new instance of HostCommander.
-
#put_secret(host, secret, options = {}) ⇒ HostConnector::Response
Write your encrypted data bag secret on a node.
-
#ruby_script(host, command_lines, options = {}) ⇒ HostConnector::Response
Execute line(s) of Ruby code on a node using Chef’s embedded Ruby.
-
#run(host, command, options = {}) ⇒ HostConnector::Response
Execute a shell command on a node.
-
#uninstall_chef(host, options = {}) ⇒ HostConnector::Response
Uninstall Chef from a node.
Constructor Details
#initialize(connector_pool_size = nil) ⇒ HostCommander
Returns a new instance of HostCommander.
46 47 48 49 50 |
# File 'lib/ridley-connectors/host_commander.rb', line 46 def initialize(connector_pool_size=nil) connector_pool_size ||= 1 @connector_registry = Celluloid::Registry.new @connector_supervisor = ConnectorSupervisor.new_link(@connector_registry, connector_pool_size) end |
Instance Method Details
#bootstrap(host, options = {}) ⇒ HostConnector::Response
Bootstrap a node
93 94 95 |
# File 'lib/ridley-connectors/host_commander.rb', line 93 def bootstrap(host, = {}) execute(__method__, host, ) end |
#chef_client(host, options = {}) ⇒ HostConnector::Response
Perform a chef client run on a node
116 117 118 |
# File 'lib/ridley-connectors/host_commander.rb', line 116 def chef_client(host, = {}) execute(__method__, host, ) end |
#connector_for(host, options = {}) ⇒ HostConnector::SSH, ...
Finds and returns the best HostConnector for a given host
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/ridley-connectors/host_commander.rb', line 212 def connector_for(host, = {}) [:ssh] ||= Hash.new [:winrm] ||= Hash.new [:ssh][:port] ||= HostConnector::SSH::DEFAULT_PORT [:winrm][:port] ||= HostConnector::WinRM::DEFAULT_PORT [:retries] ||= RETRY_COUNT connector = [:connector] if !VALID_CONNECTORS.include?(connector) log.warn { "Received connector '#{connector}' is not one of #{VALID_CONNECTORS}. Checking default connectors..." } connector = nil end if (connector == DEFAULT_WINDOWS_CONNECTOR || connector.nil?) && connector_port_open?(host, [:winrm][:port], [:winrm][:timeout], [:retries]) .delete(:ssh) winrm elsif (connector == DEFAULT_LINUX_CONNECTOR || connector.nil?) && connector_port_open?(host, [:ssh][:port], [:ssh][:timeout], [:retries]) .delete(:winrm) ssh else nil end end |
#put_secret(host, secret, options = {}) ⇒ HostConnector::Response
Write your encrypted data bag secret on a node
141 142 143 |
# File 'lib/ridley-connectors/host_commander.rb', line 141 def put_secret(host, secret, = {}) execute(__method__, host, secret, ) end |
#ruby_script(host, command_lines, options = {}) ⇒ HostConnector::Response
Execute line(s) of Ruby code on a node using Chef’s embedded Ruby
166 167 168 |
# File 'lib/ridley-connectors/host_commander.rb', line 166 def ruby_script(host, command_lines, = {}) execute(__method__, host, command_lines, ) end |
#run(host, command, options = {}) ⇒ HostConnector::Response
Execute a shell command on a node
72 73 74 |
# File 'lib/ridley-connectors/host_commander.rb', line 72 def run(host, command, = {}) execute(__method__, host, command, ) end |
#uninstall_chef(host, options = {}) ⇒ HostConnector::Response
Uninstall Chef from a node
193 194 195 |
# File 'lib/ridley-connectors/host_commander.rb', line 193 def uninstall_chef(host, = {}) execute(__method__, host, ) end |