Class: Ridley::NodeObject

Inherits:
ChefObject show all
Defined in:
lib/ridley/chef_objects/node_object.rb

Instance Method Summary collapse

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_attributeshashie::Mash

A merged hash containing a deep merge of all of the attributes respecting the node attribute precedence level.

Returns:

  • (hashie::Mash)


37
38
39
# File 'lib/ridley/chef_objects/node_object.rb', line 37

def chef_attributes
  default.merge(normal.merge(override.merge(automatic)))
end

#chef_runHostConnector::Response

Executes a Chef run on the node



130
131
132
# File 'lib/ridley/chef_objects/node_object.rb', line 130

def chef_run
  resource.chef_run(self.public_hostname)
end

#cloud?Boolean

Returns true if the node is identified as a cloud node.

Returns:

  • (Boolean)


102
103
104
# File 'lib/ridley/chef_objects/node_object.rb', line 102

def cloud?
  self.automatic.has_key?(:cloud)
end

#cloud_providernil, String

Returns the cloud provider of the instantiated node. If the node is not identified as a cloud node, then nil is returned.

Examples:

node_1.cloud_provider => "eucalyptus"
node_2.cloud_provider => "ec2"
node_3.cloud_provider => "rackspace"
node_4.cloud_provider => nil

Returns:

  • (nil, String)


95
96
97
# File 'lib/ridley/chef_objects/node_object.rb', line 95

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.

Returns:

  • (Boolean)


116
117
118
# File 'lib/ridley/chef_objects/node_object.rb', line 116

def ec2?
  self.cloud_provider == "ec2"
end

#eucalyptus?Boolean

Returns true if the node is identified as a cloud node using the eucalyptus provider.

Returns:

  • (Boolean)


109
110
111
# File 'lib/ridley/chef_objects/node_object.rb', line 109

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

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :run_list (Array)

    run list items to merge

  • :attributes (Hash)

    attributes of normal precedence to merge

Returns:



150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/ridley/chef_objects/node_object.rb', line 150

def merge_data(options = {})
  new_run_list   = Array(options[:run_list])
  new_attributes = options[: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_hostnameString

Returns the public hostname of the instantiated node. This hostname should be used for public communications to the node.

Examples:

node.public_hostname => "reset.riotgames.com"

Returns:

  • (String)


69
70
71
# File 'lib/ridley/chef_objects/node_object.rb', line 69

def public_hostname
  self.cloud? ? self.automatic[:cloud][:public_hostname] : self.automatic[:fqdn]
end

#public_ipv4String 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.

Examples:

node.public_ipv4 => "10.33.33.1"

Returns:

  • (String)


80
81
82
# File 'lib/ridley/chef_objects/node_object.rb', line 80

def public_ipv4
  self.cloud? ? self.automatic[:cloud][:public_ipv4] : self.automatic[:ipaddress]
end

#put_secretHostConnector::Response

Puts the configured encrypted data bag secret on the node



137
138
139
# File 'lib/ridley/chef_objects/node_object.rb', line 137

def put_secret
  resource.put_secret(self.public_hostname)
end

#rackspace?Boolean

Returns true if the node is identified as a cloud node using the rackspace provider.

Returns:

  • (Boolean)


123
124
125
# File 'lib/ridley/chef_objects/node_object.rb', line 123

def rackspace?
  self.cloud_provider == "rackspace"
end

#set_chef_attribute(key, value) ⇒ Hashie::Mash

Note:

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.

Examples:

setting and saving a node level normal attribute


obj = node.find("jwinsor-1")
obj.set_chef_attribute("my_app.billing.enabled", false)
obj.save

Parameters:

  • key (String)
  • value (Object)

Returns:

  • (Hashie::Mash)


57
58
59
60
# File 'lib/ridley/chef_objects/node_object.rb', line 57

def set_chef_attribute(key, value)
  attr_hash   = Hashie::Mash.from_dotted_path(key, value)
  self.normal = self.normal.deep_merge(attr_hash)
end