]> git.openstreetmap.org Git - chef.git/blobdiff - cookbooks/chef/libraries/cpu.rb
Add a library routine to get the CPU core count
[chef.git] / cookbooks / chef / libraries / cpu.rb
diff --git a/cookbooks/chef/libraries/cpu.rb b/cookbooks/chef/libraries/cpu.rb
new file mode 100644 (file)
index 0000000..a7992a4
--- /dev/null
@@ -0,0 +1,11 @@
+module OpenStreetMap
+  module Mixin
+    module CPU
+      def cpu_cores
+        [self.dig("cpu", "total").to_i, self.dig("cpu", "cores").to_i, 4].max
+      end
+    end
+  end
+end
+
+Chef::Node.include(OpenStreetMap::Mixin::CPU)