summaryrefslogtreecommitdiff
path: root/lib/chef
diff options
context:
space:
mode:
authorThom May <thom@chef.io>2018-03-20 18:32:26 +0000
committerThom May <thom@chef.io>2018-03-21 10:45:52 +0000
commit38f11a01425445c161f1dfd2c17ceacbaabf6341 (patch)
treef82f1fda08a5a7e5ba3ab90624a0433377153a06 /lib/chef
parente2eaa3fdcd9a5e2f46d90f799eedcd86cc41eb6a (diff)
downloadchef-38f11a01425445c161f1dfd2c17ceacbaabf6341.tar.gz
Save the node's UUID as an attributetm/chef_guid
We generate the UUID as part of the data collector report, but we didn't make that available to the node or the chef server otherwise. Signed-off-by: Thom May <thom@chef.io>
Diffstat (limited to 'lib/chef')
-rw-r--r--lib/chef/client.rb23
-rw-r--r--lib/chef/data_collector/messages/helpers.rb2
-rw-r--r--lib/chef/node.rb1
3 files changed, 25 insertions, 1 deletions
diff --git a/lib/chef/client.rb b/lib/chef/client.rb
index 6ff2d78ee6..3efaf6f4cf 100644
--- a/lib/chef/client.rb
+++ b/lib/chef/client.rb
@@ -256,6 +256,8 @@ class Chef
enforce_path_sanity
run_ohai
+ generate_guid
+
register unless Chef::Config[:solo_legacy_mode]
register_data_collector_reporter
@@ -994,6 +996,27 @@ class Chef
Chef::ReservedNames::Win32::Security.has_admin_privileges?
end
+ # Ensure that we have a GUID for this node
+ # If we've got the proper configuration, we'll simply set that.
+ # If we're registed with the data collector, we'll migrate that UUID into our configuration and use that
+ # Otherwise, we'll create a new GUID and save it
+ def generate_guid
+ Chef::Config[:chef_guid] ||=
+ if File.exists?(Chef::Config[:chef_guid_path])
+ File.read(Chef::Config[:chef_guid_path])
+ else
+ uuid = UUIDFetcher.node_uuid
+ File.open(Chef::Config[:chef_guid_path], "w+") do |fh|
+ fh.write(uuid)
+ end
+ uuid
+ end
+ end
+
+ class UUIDFetcher
+ extend Chef::DataCollector::Messages::Helpers
+ end
+
# Register the data collector reporter to send event information to the
# data collector server
def register_data_collector_reporter
diff --git a/lib/chef/data_collector/messages/helpers.rb b/lib/chef/data_collector/messages/helpers.rb
index e451db2c63..e4eda5ebb2 100644
--- a/lib/chef/data_collector/messages/helpers.rb
+++ b/lib/chef/data_collector/messages/helpers.rb
@@ -106,7 +106,7 @@ class Chef
# @return [String] UUID for the node
#
def node_uuid
- read_node_uuid || generate_node_uuid
+ Chef::Config[:chef_guid] || read_node_uuid || generate_node_uuid
end
#
diff --git a/lib/chef/node.rb b/lib/chef/node.rb
index 496bfedc15..977c2d5e92 100644
--- a/lib/chef/node.rb
+++ b/lib/chef/node.rb
@@ -330,6 +330,7 @@ class Chef
Chef::Log.debug("Platform is #{platform} version #{version}")
automatic[:platform] = platform
automatic[:platform_version] = version
+ automatic[:chef_guid] = Chef::Config[:chef_guid]
automatic[:name] = name
automatic[:chef_environment] = chef_environment
end