Class: Ridley::NodeResource
- Includes:
- Logging
- Defined in:
- lib/ridley/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) ⇒ 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.
-
#merge_data(target, options = {}) ⇒ Ridley::NodeObject
Merges the given data with the the data of the target node on the remote.
-
#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) ⇒ HostConnector::Response
Puts a secret on the host using the best worker available for the given host.
-
#ruby_script(host, command_lines) ⇒ HostConnector::Response
Executes an arbitrary ruby script using the best worker available for the given host.
-
#run(host, command) ⇒ 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.
Methods included from Logging
Methods inherited from Resource
#all, #connection, #create, #delete, #delete_all, #find, #from_file, #from_json, #new, representation, represented_by, resource_path, set_resource_path, #update
Constructor Details
#initialize(connection_registry, options = {}) ⇒ NodeResource
Returns a new instance of NodeResource.
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ridley/resources/node_resource.rb', line 38 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 end |
Instance Attribute Details
#chef_version ⇒ Object (readonly)
Returns the value of attribute chef_version.
14 15 16 |
# File 'lib/ridley/resources/node_resource.rb', line 14 def chef_version @chef_version end |
#encrypted_data_bag_secret ⇒ Object (readonly)
Returns the value of attribute encrypted_data_bag_secret.
11 12 13 |
# File 'lib/ridley/resources/node_resource.rb', line 11 def encrypted_data_bag_secret @encrypted_data_bag_secret end |
#server_url ⇒ Object (readonly)
Returns the value of attribute server_url.
8 9 10 |
# File 'lib/ridley/resources/node_resource.rb', line 8 def server_url @server_url end |
#ssh ⇒ Object (readonly)
Returns the value of attribute ssh.
12 13 14 |
# File 'lib/ridley/resources/node_resource.rb', line 12 def ssh @ssh end |
#validator_client ⇒ Object (readonly)
Returns the value of attribute validator_client.
10 11 12 |
# File 'lib/ridley/resources/node_resource.rb', line 10 def validator_client @validator_client end |
#validator_path ⇒ Object (readonly)
Returns the value of attribute validator_path.
9 10 11 |
# File 'lib/ridley/resources/node_resource.rb', line 9 def validator_path @validator_path end |
#winrm ⇒ Object (readonly)
Returns the value of attribute winrm.
13 14 15 |
# File 'lib/ridley/resources/node_resource.rb', line 13 def winrm @winrm end |
Instance Method Details
#bootstrap(host, options = {}) ⇒ HostConnector::Response
84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/ridley/resources/node_resource.rb', line 84 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) ⇒ HostConnector::Response
Executes a Chef run using the best worker available for the given host.
104 105 106 107 108 |
# File 'lib/ridley/resources/node_resource.rb', line 104 def chef_run(host) host_commander.chef_client(host, ssh: ssh, winrm: winrm) rescue Errors::HostConnectionError => ex abort(ex) end |
#merge_data(target, options = {}) ⇒ Ridley::NodeObject
Merges the given data with the the data of the target node on the remote
181 182 183 184 185 186 187 |
# File 'lib/ridley/resources/node_resource.rb', line 181 def merge_data(target, = {}) unless node = find(target) abort Errors::ResourceNotFound.new end update(node.merge_data()) 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.
153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/ridley/resources/node_resource.rb', line 153 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) ⇒ HostConnector::Response
Puts a secret on the host using the best worker available for the given host.
116 117 118 |
# File 'lib/ridley/resources/node_resource.rb', line 116 def put_secret(host) host_commander.put_secret(host, encrypted_data_bag_secret, ssh: ssh, winrm: winrm) end |
#ruby_script(host, command_lines) ⇒ HostConnector::Response
Executes an arbitrary ruby script using the best worker available for the given host.
127 128 129 |
# File 'lib/ridley/resources/node_resource.rb', line 127 def ruby_script(host, command_lines) host_commander.ruby_script(host, command_lines, ssh: ssh, winrm: winrm) end |
#run(host, command) ⇒ HostConnector::Response Also known as: execute_command
Executes the given command on a node using the best worker available for the given host.
138 139 140 |
# File 'lib/ridley/resources/node_resource.rb', line 138 def run(host, command) host_commander.run(host, command, ssh: ssh, winrm: winrm) end |
#uninstall_chef(host, options = {}) ⇒ HostConnector::Response
Uninstall Chef from a node
210 211 212 213 |
# File 'lib/ridley/resources/node_resource.rb', line 210 def uninstall_chef(host, = {}) = .reverse_merge(ssh: ssh, winrm: winrm) host_commander.uninstall_chef(host, ) end |