summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorThom May <thom@may.lt>2018-03-21 16:49:46 +0000
committerGitHub <noreply@github.com>2018-03-21 16:49:46 +0000
commitf52b31f01cd4d11e503aa73aa614d5ccbb00b8f7 (patch)
treecc86e8b9e91a6317084f29af488733a28f373ea8 /lib
parent26a5e48aa7f447beaee016b0b54ee2076c308dda (diff)
parent38f11a01425445c161f1dfd2c17ceacbaabf6341 (diff)
downloadchef-f52b31f01cd4d11e503aa73aa614d5ccbb00b8f7.tar.gz
Merge pull request #7016 from chef/tm/chef_guid
Save the node's UUID as an attribute
Diffstat (limited to 'lib')
-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 b7ea92b506..7218c3bb49 100644
--- a/lib/chef/client.rb
+++ b/lib/chef/client.rb
@@ -259,6 +259,8 @@ class Chef
enforce_path_sanity
run_ohai
+ generate_guid
+
register unless Chef::Config[:solo_legacy_mode]
register_data_collector_reporter
@@ -997,6 +999,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 eb0f21ea2e..4391118f06 100644
--- a/lib/chef/node.rb
+++ b/lib/chef/node.rb
@@ -335,6 +335,7 @@ class Chef
logger.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