[Pkg-puppet-devel] [facter] 304/352: Use simpler DSL for declaring external commands.
Stig Sandbeck Mathisen
ssm at debian.org
Sun Apr 6 22:21:55 UTC 2014
This is an automated email from the git hooks/post-receive script.
ssm pushed a commit to branch master
in repository facter.
commit 94c218867240d93f9ece9f35028703a1859726c5
Author: Jeff McCune <jeff at puppetlabs.com>
Date: Wed Jan 30 14:59:10 2013 -0800
Use simpler DSL for declaring external commands.
When a fact is simply the result of running an external command, a block isn't
needed - just the command string.
This changes a bunch of facts to use that shorter, simpler form as an example
to those who follow about how they should be declared.
Signed-off-by: Daniel Pittman <daniel at puppetlabs.com>
Conflicts:
lib/facter/physicalprocessorcount.rb
lib/facter/processor.rb
---
lib/facter/hostname.rb | 4 +---
lib/facter/lsbdistcodename.rb | 4 +---
lib/facter/lsbdistid.rb | 4 +---
lib/facter/lsbdistrelease.rb | 4 +---
lib/facter/lsbrelease.rb | 4 +---
lib/facter/physicalprocessorcount.rb | 14 ++++++--------
lib/facter/processor.rb | 25 +++++--------------------
lib/facter/util/manufacturer.rb | 8 ++------
8 files changed, 18 insertions(+), 49 deletions(-)
diff --git a/lib/facter/hostname.rb b/lib/facter/hostname.rb
index 8847bfa..d630c4f 100644
--- a/lib/facter/hostname.rb
+++ b/lib/facter/hostname.rb
@@ -27,7 +27,5 @@ end
Facter.add(:hostname) do
confine :kernel => :darwin, :kernelrelease => "R7"
- setcode do
- Facter::Core::Execution.exec('/usr/sbin/scutil --get LocalHostName')
- end
+ setcode '/usr/sbin/scutil --get LocalHostName'
end
diff --git a/lib/facter/lsbdistcodename.rb b/lib/facter/lsbdistcodename.rb
index 8b191dd..01ec03e 100644
--- a/lib/facter/lsbdistcodename.rb
+++ b/lib/facter/lsbdistcodename.rb
@@ -12,7 +12,5 @@
Facter.add(:lsbdistcodename) do
confine :kernel => [ :linux, :"gnu/kfreebsd" ]
- setcode do
- Facter::Core::Execution.exec('lsb_release -c -s 2>/dev/null')
- end
+ setcode 'lsb_release -c -s 2>/dev/null'
end
diff --git a/lib/facter/lsbdistid.rb b/lib/facter/lsbdistid.rb
index e77ccbc..79290fb 100644
--- a/lib/facter/lsbdistid.rb
+++ b/lib/facter/lsbdistid.rb
@@ -12,7 +12,5 @@
Facter.add(:lsbdistid) do
confine :kernel => [ :linux, :"gnu/kfreebsd" ]
- setcode do
- Facter::Core::Execution.exec('lsb_release -i -s 2>/dev/null')
- end
+ setcode 'lsb_release -i -s 2>/dev/null'
end
diff --git a/lib/facter/lsbdistrelease.rb b/lib/facter/lsbdistrelease.rb
index c691b36..95e17eb 100644
--- a/lib/facter/lsbdistrelease.rb
+++ b/lib/facter/lsbdistrelease.rb
@@ -12,7 +12,5 @@
Facter.add(:lsbdistrelease) do
confine :kernel => [ :linux, :"gnu/kfreebsd" ]
- setcode do
- Facter::Core::Execution.exec('lsb_release -r -s 2>/dev/null')
- end
+ setcode 'lsb_release -r -s 2>/dev/null'
end
diff --git a/lib/facter/lsbrelease.rb b/lib/facter/lsbrelease.rb
index 9b89bc6..9fc4adf 100644
--- a/lib/facter/lsbrelease.rb
+++ b/lib/facter/lsbrelease.rb
@@ -12,7 +12,5 @@
Facter.add(:lsbrelease) do
confine :kernel => [ :linux, :"gnu/kfreebsd" ]
- setcode do
- Facter::Core::Execution.exec('lsb_release -v -s 2>/dev/null')
- end
+ setcode 'lsb_release -v -s 2>/dev/null'
end
diff --git a/lib/facter/physicalprocessorcount.rb b/lib/facter/physicalprocessorcount.rb
index 6973545..68917af 100644
--- a/lib/facter/physicalprocessorcount.rb
+++ b/lib/facter/physicalprocessorcount.rb
@@ -66,19 +66,17 @@ end
Facter.add('physicalprocessorcount') do
confine :kernel => :sunos
+ # (#16526) The -p flag was not added until Solaris 8. Our intent is to
+ # split the kernel release fact value on the dot, take the second element,
+ # and disable the -p flag for values < 8 when.
setcode do
- # (#16526) The -p flag was not added until Solaris 8. Our intent is to
- # split the kernel release fact value on the dot, take the second element,
- # and disable the -p flag for values < 8 when.
kernelrelease = Facter.value(:kernelrelease)
(major_version, minor_version) = kernelrelease.split(".").map { |str| str.to_i }
- cmd = "/usr/sbin/psrinfo"
- result = nil
if (major_version > 5) or (major_version == 5 and minor_version >= 8) then
- result = Facter::Core::Execution.exec("#{cmd} -p")
+ Facter::Core::Execution.exec("/usr/sbin/psrinfo -p")
else
- output = Facter::Core::Execution.exec(cmd)
- result = output.split("\n").length.to_s
+ output = Facter::Core::Execution.exec("/usr/sbin/psrinfo")
+ output.split("\n").length.to_s
end
end
end
diff --git a/lib/facter/processor.rb b/lib/facter/processor.rb
index 57d9459..3b254c0 100644
--- a/lib/facter/processor.rb
+++ b/lib/facter/processor.rb
@@ -90,23 +90,12 @@ end
Facter.add("Processor") do
confine :kernel => :openbsd
- setcode do
- Facter::Core::Execution.exec("uname -p")
- end
-end
-
-Facter.add("ProcessorCount") do
- confine :kernel => :openbsd
- setcode do
- Facter::Core::Execution.exec("sysctl -n hw.ncpu")
- end
+ setcode "uname -p"
end
Facter.add("ProcessorCount") do
confine :kernel => :Darwin
- setcode do
- Facter::Core::Execution.exec("sysctl -n hw.ncpu")
- end
+ setcode "sysctl -n hw.ncpu"
end
if Facter.value(:kernel) == "windows"
@@ -149,16 +138,12 @@ end
Facter.add("Processor") do
confine :kernel => [:dragonfly,:freebsd]
- setcode do
- Facter::Core::Execution.exec("sysctl -n hw.model")
- end
+ setcode "sysctl -n hw.model"
end
Facter.add("ProcessorCount") do
- confine :kernel => [:dragonfly,:freebsd]
- setcode do
- Facter::Core::Execution.exec("sysctl -n hw.ncpu")
- end
+ confine :kernel => [:dragonfly,:freebsd,:openbsd]
+ setcode "sysctl -n hw.ncpu"
end
Facter.add("ProcessorCount") do
diff --git a/lib/facter/util/manufacturer.rb b/lib/facter/util/manufacturer.rb
index 183c52f..6f93e6d 100644
--- a/lib/facter/util/manufacturer.rb
+++ b/lib/facter/util/manufacturer.rb
@@ -54,9 +54,7 @@ module Facter::Manufacturer
name.each do |sysctlkey,facterkey|
Facter.add(facterkey) do
confine :kernel => [:openbsd, :darwin]
- setcode do
- Facter::Core::Execution.exec("sysctl -n #{sysctlkey} 2>/dev/null")
- end
+ setcode "sysctl -n #{sysctlkey} 2>/dev/null"
end
end
end
@@ -80,9 +78,7 @@ module Facter::Manufacturer
end
Facter.add('serialnumber') do
- setcode do
- Facter::Core::Execution.exec("/usr/sbin/sneep")
- end
+ setcode "/usr/sbin/sneep"
end
end
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-puppet/facter.git
More information about the Pkg-puppet-devel
mailing list