William, Thanks for sending the updated patch. It would be really nice to see some tests around this, especially given a lot of the issues you pointed out around the inconsistency of what the Windows API returns. Definitely not something that we'd want accidentally regressing because someone didn't fully understand the variety of values the API could give back.
The windowsrelease fact should also really be split out into its own commit, with its own tests. Feel free to holler if there's anything that would help out with the testing. -- Jacob Helwig On Thu, 26 May 2011 20:23:51 -0700, William Van Hevelingen wrote: > > This patch queries wmi for the Caption property in the > Win32_OperatingSystem class. The result is a string that > is parsed by comparing it to a hardcode list of possible > versions. A hardcoded list is not ideal but Microsoft does > not provide a function to grab just the release string. > > A possible alternative would be using regex to grab the > value, accounting for the various cases between windows > version names and then hoping Mircrosoft doesn't change > the format of the caption property in future releases. > > The patch also adds a windowsrelease fact which is the full > name of the specific version of windows. > ie. "Microsoft Windows 7 Professional" > > Signed-off-by: William Van Hevelingen <[email protected]> > --- > Local-branch: feature/master/7621-windows_osrelease > lib/facter/operatingsystemrelease.rb | 15 +++++++++++++++ > lib/facter/util/mswindows.rb | 12 ++++++++++++ > lib/facter/windowsrelease.rb | 18 ++++++++++++++++++ > 3 files changed, 45 insertions(+), 0 deletions(-) > create mode 100644 lib/facter/util/mswindows.rb > create mode 100644 lib/facter/windowsrelease.rb > > diff --git a/lib/facter/operatingsystemrelease.rb > b/lib/facter/operatingsystemrelease.rb > index 347fe7f..b0a2108 100644 > --- a/lib/facter/operatingsystemrelease.rb > +++ b/lib/facter/operatingsystemrelease.rb > @@ -123,5 +123,20 @@ Facter.add(:operatingsystemrelease) do > end > > Facter.add(:operatingsystemrelease) do > + confine :operatingsystem => :windows > + require 'facter/util/mswindows' > + setcode do > + result = nil > + # Added spaces to make the values unique > + [" XP ", " Vista ", " 7 ", " 2003 ", " 2008 ", "2008 R2 ", " 8 > "].each do |r| > + if Facter::Util::MSWindows.getWindowsRelease.include?(r) > + result = r.gsub(/\s/, "") > + end > + end > + result > + end > +end > + > +Facter.add(:operatingsystemrelease) do > setcode do Facter[:kernelrelease].value end > end > diff --git a/lib/facter/util/mswindows.rb b/lib/facter/util/mswindows.rb > new file mode 100644 > index 0000000..32ab0ed > --- /dev/null > +++ b/lib/facter/util/mswindows.rb > @@ -0,0 +1,12 @@ > +module Facter::Util::MSWindows > + > + def self.getWindowsRelease > + require 'win32ole' > + # WMI returns an IEnumVariant object > + wmi = WIN32OLE.connect("winmgmts://").ExecQuery("select Caption from > Win32_OperatingSystem") > + result = nil > + wmi.each { |x| result = x["Caption"] } > + result > + end > + > +end > diff --git a/lib/facter/windowsrelease.rb b/lib/facter/windowsrelease.rb > new file mode 100644 > index 0000000..3469622 > --- /dev/null > +++ b/lib/facter/windowsrelease.rb > @@ -0,0 +1,18 @@ > +# Fact: windowsrelease > +# > +# Purpose: > +# Returns the windowsrelease of the system. > +# > +# Resolution: > +# Uses WMI to query for the OS caption string > +# > +# Caveats: > +# > +require 'facter/util/mswindows' > + > +Facter.add(:windowsrelease) do > + confine :operatingsystem => :windows > + setcode do > + Facter::Util::MSWindows.getWindowsRelease > + end > +end > -- > 1.7.0.4 >
signature.asc
Description: Digital signature
