Module: Chef::DataCollector::Messages::Helpers
- Included in:
- Chef::DataCollector::Messages
- Defined in:
- lib/chef/data_collector/messages/helpers.rb
Instance Method Summary collapse
-
#chef_server_fqdn(run_status) ⇒ String
Fully-qualified domain name of the Chef Server configured in Chef::Config If the chef_server_url cannot be parsed as a URI, the node attribute will be returned, or “localhost” if the run_status is unavailable to us.
-
#chef_server_organization ⇒ String
Return the organization assumed by the configured chef_server_url.
-
#collector_source ⇒ String
The source of the data collecting during this run, used by the DataCollector endpoint to determine if Chef was in Solo mode or not.
-
#data_collector_organization ⇒ String
Returns the user-configured organization, or “chef_solo” if none is configured.
-
#generate_node_uuid ⇒ String
Generates a UUID for the node via SecureRandom.uuid and writes out metadata file so the UUID persists between runs.
-
#metadata ⇒ Hash
Returns the DataCollector metadata for this node.
- #metadata_filename ⇒ Object
-
#node_uuid ⇒ String
Returns a UUID that uniquely identifies this node for reporting reasons.
-
#organization ⇒ String
The organization name the node is associated with.
-
#read_node_uuid ⇒ String
Reads in the node UUID from the node metadata file.
-
#solo_run? ⇒ Boolean
If we’re running in Solo (legacy) mode, or in Solo (formerly “Chef Client Local Mode”), we’re considered to be in a “solo run”.
- #update_metadata(key, value) ⇒ Object
Instance Method Details
#chef_server_fqdn(run_status) ⇒ String
Fully-qualified domain name of the Chef Server configured in Chef::Config If the chef_server_url cannot be parsed as a URI, the node attribute will be returned, or “localhost” if the run_status is unavailable to us.
34 35 36 37 38 39 40 41 42 |
# File 'lib/chef/data_collector/messages/helpers.rb', line 34 def chef_server_fqdn(run_status) if !Chef::Config[:chef_server_url].nil? URI(Chef::Config[:chef_server_url]).host elsif !Chef::Config[:node_name].nil? Chef::Config[:node_name] else "localhost" end end |
#chef_server_organization ⇒ String
Return the organization assumed by the configured chef_server_url.
We must parse this from the Chef::Config because a node has no knowledge of an organization or to which organization is belongs.
If we cannot determine the organization, we return “unknown_organization”
76 77 78 79 80 |
# File 'lib/chef/data_collector/messages/helpers.rb', line 76 def chef_server_organization return "unknown_organization" unless Chef::Config[:chef_server_url] Chef::Config[:chef_server_url].match(%r{/+organizations/+(\w+)}).nil? ? "unknown_organization" : $1 end |
#collector_source ⇒ String
The source of the data collecting during this run, used by the DataCollector endpoint to determine if Chef was in Solo mode or not.
88 89 90 |
# File 'lib/chef/data_collector/messages/helpers.rb', line 88 def collector_source solo_run? ? "chef_solo" : "chef_client" end |
#data_collector_organization ⇒ String
Returns the user-configured organization, or “chef_solo” if none is configured.
This is only used when Chef is run in Solo mode.
62 63 64 |
# File 'lib/chef/data_collector/messages/helpers.rb', line 62 def data_collector_organization Chef::Config[:data_collector][:organization] || "chef_solo" end |
#generate_node_uuid ⇒ String
Generates a UUID for the node via SecureRandom.uuid and writes out metadata file so the UUID persists between runs.
120 121 122 123 124 125 |
# File 'lib/chef/data_collector/messages/helpers.rb', line 120 def generate_node_uuid uuid = SecureRandom.uuid ("node_uuid", uuid) uuid end |
#metadata ⇒ Hash
Returns the DataCollector metadata for this node
If the metadata file does not exist in the file cache path, an empty hash will be returned.
144 145 146 147 148 |
# File 'lib/chef/data_collector/messages/helpers.rb', line 144 def JSON.load(Chef::FileCache.load()) rescue Chef::Exceptions::FileNotFound {} end |
#metadata_filename ⇒ Object
155 156 157 |
# File 'lib/chef/data_collector/messages/helpers.rb', line 155 def "data_collector_metadata.json" end |
#node_uuid ⇒ String
Returns a UUID that uniquely identifies this node for reporting reasons.
The node is read in from disk if it exists, or it’s generated if it does does not exist.
110 111 112 |
# File 'lib/chef/data_collector/messages/helpers.rb', line 110 def node_uuid read_node_uuid || generate_node_uuid end |
#organization ⇒ String
The organization name the node is associated with. For Chef Solo runs, a user-configured organization string is returned, or the string “chef_solo” if such a string is not configured.
51 52 53 |
# File 'lib/chef/data_collector/messages/helpers.rb', line 51 def organization solo_run? ? data_collector_organization : chef_server_organization end |
#read_node_uuid ⇒ String
Reads in the node UUID from the node metadata file
132 133 134 |
# File 'lib/chef/data_collector/messages/helpers.rb', line 132 def read_node_uuid ["node_uuid"] end |