Seems to me that this fact should just do:

Facter.add(:operatingsystemmajrelease) do
   setcode do
     if release = Facter.value(:operatingsystemrelease)
       release.sub(/\..+/, '')
     else
       nil
     end
end

That is, why duplicate the code for looking in the releases, and why  
restrict the fact to those that currently need it, when really it's  
just a string substitution.

The above code would strip off the first period and anything after it;  
I dunno if it's more valid to strip of the second period and anything  
after it (i.e., what you'd need for OS X).

On Mar 20, 2009, at 5:03 AM, James Turnbull wrote:

>
>
> Signed-off-by: James Turnbull <[email protected]>
> ---
> lib/facter/operatingsystemmajrelease.rb |   84 ++++++++++++++++++++++ 
> +++++++++
> lib/facter/operatingsystemrelease.rb    |    6 +-
> 2 files changed, 87 insertions(+), 3 deletions(-)
> create mode 100644 lib/facter/operatingsystemmajrelease.rb
>
> diff --git a/lib/facter/operatingsystemmajrelease.rb b/lib/facter/ 
> operatingsystemmajrelease.rb
> new file mode 100644
> index 0000000..153caf2
> --- /dev/null
> +++ b/lib/facter/operatingsystemmajrelease.rb
> @@ -0,0 +1,84 @@
> +Facter.add(:operatingsystemmajrelease) do
> +    confine :operatingsystem => :fedora
> +    setcode do
> +        File::open("/etc/fedora-release", "r") do |f|
> +            line = f.readline.chomp
> +            if line =~ /\(Rawhide\)$/
> +                "Rawhide"
> +            elsif line =~ /release (\d+)/
> +                $1
> +            end
> +        end
> +    end
> +end
> +
> +Facter.add(:operatingsystemmajrelease) do
> +    confine :operatingsystem => %w{RedHat CentOS}
> +    setcode do
> +        File::open("/etc/redhat-release", "r") do |f|
> +            line = f.readline.chomp
> +            if line =~ /\(Rawhide\)$/
> +                "Rawhide"
> +            elsif line =~ /release (\d+)/
> +                $1
> +            end
> +        end
> +    end
> +end
> +
> +Facter.add(:operatingsystemmajrelease) do
> +    confine :operatingsystem => :oel
> +    setcode do
> +        File::open("/etc/enterprise-release", "r") do |f|
> +            line = f.readline.chomp
> +            if line =~ /release (\d+)/
> +                $1
> +            end
> +        end
> +    end
> +end
> +
> +Facter.add(:operatingsystemmajrelease) do
> +    confine :operatingsystem => :ovs
> +    setcode do
> +        File::open("/etc/ovs-release", "r") do |f|
> +            line = f.readline.chomp
> +            if line =~ /release (\d+)/
> +                $1
> +            end
> +        end
> +    end
> +end
> +
> +Facter.add(:operatingsystemmajrelease) do
> +    confine :operatingsystem => %w{Debian}
> +    setcode do
> +        release = Facter::Util::Resolution.exec('cat /etc/ 
> debian_version')
> +    end
> +end
> +
> +Facter.add(:operatingsystemmajrelease) do
> +    confine :operatingsystem => %w{Ubuntu}
> +    setcode do
> +        release = Facter::Util::Resolution.exec('cat /etc/issue')
> +        if release =~ /Ubuntu (\d+)/
> +            $1
> +        end
> +    end
> +end
> +
> +Facter.add(:operatingsystemmajrelease) do
> +    confine :operatingsystem => %w{SLES OpenSuSE}
> +    setcode do
> +        releasefile = Facter::Util::Resolution.exec('cat /etc/SuSE- 
> release')
> +        if releasefile =~ /^VERSION\s*=\s*(\d+)/
> +            $1
> +        else
> +            "unknown"
> +        end
> +    end
> +end
> +
> +Facter.add(:operatingsystemmajrelease) do
> +    setcode do Facter[:kernelrelease].value end
> +end
> diff --git a/lib/facter/operatingsystemrelease.rb b/lib/facter/ 
> operatingsystemrelease.rb
> index 25a226d..3a68708 100644
> --- a/lib/facter/operatingsystemrelease.rb
> +++ b/lib/facter/operatingsystemrelease.rb
> @@ -19,7 +19,7 @@ Facter.add(:operatingsystemrelease) do
>             line = f.readline.chomp
>             if line =~ /\(Rawhide\)$/
>                 "Rawhide"
> -            elsif line =~ /release (\d+)/
> +            elsif line =~ /release (\d+.\d+)/
>                 $1
>             end
>         end
> @@ -31,7 +31,7 @@ Facter.add(:operatingsystemrelease) do
>     setcode do
>         File::open("/etc/enterprise-release", "r") do |f|
>             line = f.readline.chomp
> -            if line =~ /release (\d+)/
> +            if line =~ /release (\d+.\d+)/
>                 $1
>             end
>         end
> @@ -43,7 +43,7 @@ Facter.add(:operatingsystemrelease) do
>     setcode do
>         File::open("/etc/ovs-release", "r") do |f|
>             line = f.readline.chomp
> -            if line =~ /release (\d+)/
> +            if line =~ /release (\d+.\d+)/
>                 $1
>             end
>         end
> -- 
> 1.6.0.6
>
>
> >


-- 
I conclude that there are two ways of constructing a software design:
One way is to make it so simple that there are 'obviously' no
deficiencies and the other way is to make it so complicated that there
are no 'obvious' deficiencies.
     -- C.A.R. Hoare, Turing Lecture "The Emperor's Old Clothes" CACM
     February 1981, pp. 75-83.
---------------------------------------------------------------------
Luke Kanies | http://reductivelabs.com | http://madstop.com


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to