Class: Ridley::NodeResource
- Inherits:
-
Object
- Object
- Ridley::NodeResource
- Defined in:
- lib/ridley-connectors/resources/node_resource.rb
Instance Attribute Summary collapse
-
#chef_version ⇒ Object
readonly
Returns the value of attribute chef_version.
-
#encrypted_data_bag_secret ⇒ Object
readonly
Returns the value of attribute encrypted_data_bag_secret.
-
#server_url ⇒ Object
readonly
Returns the value of attribute server_url.
-
#ssh ⇒ Object
readonly
Returns the value of attribute ssh.
-
#validator_client ⇒ Object
readonly
Returns the value of attribute validator_client.
-
#validator_path ⇒ Object
readonly
Returns the value of attribute validator_path.
-
#winrm ⇒ Object
readonly
Returns the value of attribute winrm.
Instance Method Summary collapse
- #bootstrap(host, options = {}) ⇒ HostConnector::Response
-
#chef_run(host, options = {}) ⇒ HostConnector::Response
Executes a Chef run using the best worker available for the given host.
-
#initialize(connection_registry, options = {}) ⇒ NodeResource
constructor
A new instance of NodeResource.
-
#platform_specific_run(host, commands) ⇒ HostConnector::Response
(also: #execute_platform_specific_command)
Executes the given command on a node using a platform specific command.
-
#put_secret(host, options = {}) ⇒ HostConnector::Response
Puts a secret on the host using the best worker available for the given host.
-
#ruby_script(host, command_lines, options = {}) ⇒ HostConnector::Response
Executes an arbitrary ruby script using the best worker available for the given host.
-
#run(host, command, options = {}) ⇒ HostConnector::Response
(also: #execute_command)
Executes the given command on a node using the best worker available for the given host.
-
#uninstall_chef(host, options = {}) ⇒ HostConnector::Response
Uninstall Chef from a node.
-
#update_omnibus(host, options = {}) ⇒ HostConnector::Response
Update a node’s Omnibus installation of Chef.
Constructor Details
#initialize(connection_registry, options = {}) ⇒ NodeResource
Returns a new instance of NodeResource.
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ridley-connectors/resources/node_resource.rb', line 33 def initialize(connection_registry, = {}) super(connection_registry) @server_url = [:server_url] @validator_path = [:validator_path] @validator_client = [:validator_client] @encrypted_data_bag_secret = [:encrypted_data_bag_secret] @ssh = [:ssh] @winrm = [:winrm] @chef_version = [:chef_version] @host_commander = HostCommander.new_link([:connector_pool_size]) end |
Instance Attribute Details
#chef_version ⇒ Object (readonly)
Returns the value of attribute chef_version.
9 10 11 |
# File 'lib/ridley-connectors/resources/node_resource.rb', line 9 def chef_version @chef_version end |
#encrypted_data_bag_secret ⇒ Object (readonly)
Returns the value of attribute encrypted_data_bag_secret.
6 7 8 |
# File 'lib/ridley-connectors/resources/node_resource.rb', line 6 def encrypted_data_bag_secret @encrypted_data_bag_secret end |
#server_url ⇒ Object (readonly)
Returns the value of attribute server_url.
3 4 5 |
# File 'lib/ridley-connectors/resources/node_resource.rb', line 3 def server_url @server_url end |
#ssh ⇒ Object (readonly)
Returns the value of attribute ssh.
7 8 9 |
# File 'lib/ridley-connectors/resources/node_resource.rb', line 7 def ssh @ssh end |
#validator_client ⇒ Object (readonly)
Returns the value of attribute validator_client.
5 6 7 |
# File 'lib/ridley-connectors/resources/node_resource.rb', line 5 def validator_client @validator_client end |
#validator_path ⇒ Object (readonly)
Returns the value of attribute validator_path.
4 5 6 |
# File 'lib/ridley-connectors/resources/node_resource.rb', line 4 def validator_path @validator_path end |
#winrm ⇒ Object (readonly)
Returns the value of attribute winrm.
8 9 10 |
# File 'lib/ridley-connectors/resources/node_resource.rb', line 8 def winrm @winrm end |
Instance Method Details
#bootstrap(host, options = {}) ⇒ HostConnector::Response
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/ridley-connectors/resources/node_resource.rb', line 79 def bootstrap(host, = {}) = .reverse_merge( server_url: server_url, validator_path: validator_path, validator_client: validator_client, encrypted_data_bag_secret: encrypted_data_bag_secret, ssh: ssh, winrm: winrm, chef_version: chef_version ) host_commander.bootstrap(host, ) end |
#chef_run(host, options = {}) ⇒ HostConnector::Response
Executes a Chef run using the best worker available for the given host.
101 102 103 104 105 |
# File 'lib/ridley-connectors/resources/node_resource.rb', line 101 def chef_run(host, = {}) host_commander.chef_client(host, ssh: ssh, winrm: winrm, connector: [:connector]) rescue Errors::HostConnectionError => ex abort(ex) end |
#platform_specific_run(host, commands) ⇒ HostConnector::Response Also known as: execute_platform_specific_command
Executes the given command on a node using a platform specific command.
156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/ridley-connectors/resources/node_resource.rb', line 156 def platform_specific_run(host, commands) case (type = host_commander.connector_for(host, ssh: ssh, winrm: winrm)) when HostConnector::SSH raise Errors::CommandNotProvided.new(:ssh) unless commands[:ssh] and !commands[:ssh].empty? run(host, commands[:ssh]) when HostConnector::WinRM raise Errors::CommandNotProvided.new(:winrm) unless commands[:winrm] and !commands[:winrm].empty? run(host, commands[:winrm]) else raise RuntimeError, "#{type.class.to_s} is not a supported connector for #{self.class}##{__method__}" end end |
#put_secret(host, options = {}) ⇒ HostConnector::Response
Puts a secret on the host using the best worker available for the given host.
115 116 117 |
# File 'lib/ridley-connectors/resources/node_resource.rb', line 115 def put_secret(host, = {}) host_commander.put_secret(host, encrypted_data_bag_secret, ssh: ssh, winrm: winrm, connector: [:connector]) end |
#ruby_script(host, command_lines, options = {}) ⇒ HostConnector::Response
Executes an arbitrary ruby script using the best worker available for the given host.
128 129 130 |
# File 'lib/ridley-connectors/resources/node_resource.rb', line 128 def ruby_script(host, command_lines, = {}) host_commander.ruby_script(host, command_lines, ssh: ssh, winrm: winrm, connector: [:connector]) end |
#run(host, command, options = {}) ⇒ HostConnector::Response Also known as: execute_command
Executes the given command on a node using the best worker available for the given host.
141 142 143 |
# File 'lib/ridley-connectors/resources/node_resource.rb', line 141 def run(host, command, = {}) host_commander.run(host, command, ssh: ssh, winrm: winrm, connector: [:connector]) end |
#uninstall_chef(host, options = {}) ⇒ HostConnector::Response
Uninstall Chef from a node
191 192 193 194 |
# File 'lib/ridley-connectors/resources/node_resource.rb', line 191 def uninstall_chef(host, = {}) = .reverse_merge(ssh: ssh, winrm: winrm) host_commander.uninstall_chef(host, ) end |
#update_omnibus(host, options = {}) ⇒ HostConnector::Response
Update a node’s Omnibus installation of Chef
219 220 221 222 |
# File 'lib/ridley-connectors/resources/node_resource.rb', line 219 def update_omnibus(host, = {}) = .reverse_merge(ssh: ssh, winrm: winrm) host_commander.update_omnibus(host, ) end |