Class: Ridley::NodeResource
- Defined in:
- lib/ridley/resources/node_resource.rb
Overview
Class Method Summary collapse
- .bootstrap(client, nodes, options = {}) ⇒ SSH::ResponseSet
-
.merge_data(client, target, options = {}) ⇒ Ridley::NodeResource
Merges the given data with the the data of the target node on the remote.
Instance Method Summary collapse
-
#chef_client(options = {}) ⇒ SSH::Response
Run Chef-Client on the instantiated node.
-
#cloud? ⇒ Boolean
Returns true if the node is identified as a cloud node.
-
#cloud_provider ⇒ nil, String
Returns the cloud provider of the instantiated node.
-
#ec2? ⇒ Boolean
Returns true if the node is identified as a cloud node using the ec2 provider.
-
#eucalyptus? ⇒ Boolean
Returns true if the node is identified as a cloud node using the eucalyptus provider.
-
#merge_data(options = {}) ⇒ Ridley::NodeResource
Merges the instaniated nodes data with the given data and updates the remote with the merged results.
-
#public_hostname ⇒ String
Returns the public hostname of the instantiated node.
-
#public_ipv4 ⇒ String
(also: #public_ipaddress)
Returns the public IPv4 address of the instantiated node.
-
#put_secret(options = {}) ⇒ SSH::Response?
Put the client’s encrypted data bag secret onto the instantiated node.
-
#rackspace? ⇒ Boolean
Returns true if the node is identified as a cloud node using the rackspace provider.
-
#set_chef_attribute(key, value) ⇒ Hashie::Mash
Set a node level normal attribute given the dotted path representation of the Chef attribute and value.
Methods inherited from Resource
#<=>, #==, all, chef_id, #chef_id, chef_json_class, chef_type, create, delete, delete_all, #eql?, find, find!, #hash, #initialize, #reload, resource_path, #save, set_chef_id, set_chef_json_class, set_chef_type, set_resource_path, #to_s, #update, update
Constructor Details
This class inherits a constructor from Ridley::Resource
Class Method Details
.bootstrap(client, nodes, options = {}) ⇒ SSH::ResponseSet
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ridley/resources/node_resource.rb', line 36 def bootstrap(client, *args) = args. = { server_url: client.server_url, validator_path: client.validator_path, validator_client: client.validator_client, encrypted_data_bag_secret_path: client.encrypted_data_bag_secret_path, ssh: client.ssh } = .merge() Bootstrapper.new(*args, ).run end |
.merge_data(client, target, options = {}) ⇒ Ridley::NodeResource
Merges the given data with the the data of the target node on the remote
66 67 68 |
# File 'lib/ridley/resources/node_resource.rb', line 66 def merge_data(client, target, = {}) find!(client, target).merge_data() end |
Instance Method Details
#chef_client(options = {}) ⇒ SSH::Response
Run Chef-Client on the instantiated node
199 200 201 202 203 204 205 206 |
# File 'lib/ridley/resources/node_resource.rb', line 199 def chef_client( = {}) = client.ssh.merge() Ridley.log.debug "Running Chef Client on: #{self.public_hostname}" Ridley::SSH.start(self, ) do |ssh| ssh.run("sudo chef-client").first end end |
#cloud? ⇒ Boolean
Returns true if the node is identified as a cloud node.
168 169 170 |
# File 'lib/ridley/resources/node_resource.rb', line 168 def cloud? self.automatic.has_key?(:cloud) end |
#cloud_provider ⇒ nil, String
Returns the cloud provider of the instantiated node. If the node is not identified as a cloud node, then nil is returned.
161 162 163 |
# File 'lib/ridley/resources/node_resource.rb', line 161 def cloud_provider self.cloud? ? self.automatic[:cloud][:provider] : nil end |
#ec2? ⇒ Boolean
Returns true if the node is identified as a cloud node using the ec2 provider.
182 183 184 |
# File 'lib/ridley/resources/node_resource.rb', line 182 def ec2? self.cloud_provider == "ec2" end |
#eucalyptus? ⇒ Boolean
Returns true if the node is identified as a cloud node using the eucalyptus provider.
175 176 177 |
# File 'lib/ridley/resources/node_resource.rb', line 175 def eucalyptus? self.cloud_provider == "eucalyptus" end |
#merge_data(options = {}) ⇒ Ridley::NodeResource
Merges the instaniated nodes data with the given data and updates the remote with the merged results
242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/ridley/resources/node_resource.rb', line 242 def merge_data( = {}) unless [:run_list].nil? self.run_list = (self.run_list + Array([:run_list])).uniq end unless [:attributes].nil? self.normal = self.normal.deep_merge([:attributes]) end self.update self end |
#public_hostname ⇒ String
Returns the public hostname of the instantiated node. This hostname should be used for public communications to the node.
135 136 137 |
# File 'lib/ridley/resources/node_resource.rb', line 135 def public_hostname self.cloud? ? self.automatic[:cloud][:public_hostname] : self.automatic[:fqdn] end |
#public_ipv4 ⇒ String Also known as: public_ipaddress
Returns the public IPv4 address of the instantiated node. This ip address should be used for public communications to the node.
146 147 148 |
# File 'lib/ridley/resources/node_resource.rb', line 146 def public_ipv4 self.cloud? ? self.automatic[:cloud][:public_ipv4] : self.automatic[:ipaddress] end |
#put_secret(options = {}) ⇒ SSH::Response?
Put the client’s encrypted data bag secret onto the instantiated node. If no encrypted data bag key path is set on the resource’s client then nil will be returned
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/ridley/resources/node_resource.rb', line 216 def put_secret( = {}) if client.encrypted_data_bag_secret_path.nil? || !File.exists?(client.encrypted_data_bag_secret_path) return nil end = client.ssh.merge() secret = File.read(client.encrypted_data_bag_secret_path).chomp command = "echo '#{secret}' > /etc/chef/encrypted_data_bag_secret; chmod 0600 /etc/chef/encrypted_data_bag_secret" Ridley.log.debug "Writing Encrypted Data Bag Secret to: #{self.public_hostname}" Ridley::SSH.start(self, ) do |ssh| ssh.run(command).first end end |
#rackspace? ⇒ Boolean
Returns true if the node is identified as a cloud node using the rackspace provider.
189 190 191 |
# File 'lib/ridley/resources/node_resource.rb', line 189 def rackspace? self.cloud_provider == "rackspace" end |
#set_chef_attribute(key, value) ⇒ Hashie::Mash
It is not possible to set any other attribute level on a node and have it persist after a Chef Run. This is because all other attribute levels are truncated at the start of a Chef Run.
Set a node level normal attribute given the dotted path representation of the Chef attribute and value.
123 124 125 126 |
# File 'lib/ridley/resources/node_resource.rb', line 123 def set_chef_attribute(key, value) attr_hash = Hashie::Mash.from_dotted_path(key, value) self.normal = self.normal.deep_merge(attr_hash) end |