Class: Ridley::NodeObject
- Inherits:
-
ChefObject
- Object
- ChefObject
- Ridley::NodeObject
- Defined in:
- lib/ridley/chef_objects/node_object.rb
Instance Method Summary collapse
-
#chef_attributes ⇒ hashie::Mash
A merged hash containing a deep merge of all of the attributes respecting the node attribute precedence level.
-
#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::NodeObject
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.
-
#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.
-
#unset_chef_attribute(key) ⇒ Hashie::Mash
Unset a node level normal attribute given the dotted path representation of the Chef attribute and value.
Methods inherited from ChefObject
#<=>, #==, chef_id, #chef_id, chef_json_class, chef_type, #eql?, #hash, #initialize, #inspect, #reload, #save, set_chef_id, set_chef_json_class, set_chef_type, #update
Constructor Details
This class inherits a constructor from Ridley::ChefObject
Instance Method Details
#chef_attributes ⇒ hashie::Mash
A merged hash containing a deep merge of all of the attributes respecting the node attribute precedence level.
37 38 39 |
# File 'lib/ridley/chef_objects/node_object.rb', line 37 def chef_attributes default.merge(normal.merge(override.merge(automatic))) end |
#cloud? ⇒ Boolean
Returns true if the node is identified as a cloud node.
131 132 133 |
# File 'lib/ridley/chef_objects/node_object.rb', line 131 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.
124 125 126 |
# File 'lib/ridley/chef_objects/node_object.rb', line 124 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.
145 146 147 |
# File 'lib/ridley/chef_objects/node_object.rb', line 145 def ec2? self.cloud_provider == "ec2" end |
#eucalyptus? ⇒ Boolean
Returns true if the node is identified as a cloud node using the eucalyptus provider.
138 139 140 |
# File 'lib/ridley/chef_objects/node_object.rb', line 138 def eucalyptus? self.cloud_provider == "eucalyptus" end |
#merge_data(options = {}) ⇒ Ridley::NodeObject
Merges the instaniated nodes data with the given data and updates the remote with the merged results
165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/ridley/chef_objects/node_object.rb', line 165 def merge_data( = {}) new_run_list = Array([:run_list]) new_attributes = [:attributes] unless new_run_list.empty? self.run_list = self.run_list | new_run_list end unless new_attributes.nil? self.normal = self.normal.deep_merge(new_attributes) end self end |
#public_hostname ⇒ String
Returns the public hostname of the instantiated node. This hostname should be used for public communications to the node.
98 99 100 |
# File 'lib/ridley/chef_objects/node_object.rb', line 98 def public_hostname self.cloud? ? self.automatic[:cloud][:public_hostname] || self.automatic[:fqdn] : 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.
109 110 111 |
# File 'lib/ridley/chef_objects/node_object.rb', line 109 def public_ipv4 self.cloud? ? self.automatic[:cloud][:public_ipv4] || self.automatic[:ipaddress] : self.automatic[:ipaddress] end |
#rackspace? ⇒ Boolean
Returns true if the node is identified as a cloud node using the rackspace provider.
152 153 154 |
# File 'lib/ridley/chef_objects/node_object.rb', line 152 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.
58 59 60 61 |
# File 'lib/ridley/chef_objects/node_object.rb', line 58 def set_chef_attribute(key, value) attr_hash = Hashie::Mash.from_dotted_path(key, value) self.normal = self.normal.deep_merge(attr_hash) end |
#unset_chef_attribute(key) ⇒ Hashie::Mash
Unset a node level normal attribute given the dotted path representation of the Chef attribute and value.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/ridley/chef_objects/node_object.rb', line 76 def unset_chef_attribute(key) keys = key.split(".") leaf_key = keys.pop attributes = keys.inject(self.normal) do |attributes, key| if attributes[key] && attributes[key].kind_of?(Hashie::Mash) attributes = attributes[key] else return self.normal end end attributes.delete(leaf_key) return self.normal end |