On 2 December 2010 23:27, Paul Berry <p...@puppetlabs.com> wrote:
> On Tue, Nov 30, 2010 at 4:27 AM, Dominic Cleal <dcl...@redhat.com> wrote:
>>
>> Add total memory from prtconf output, free from vmstat plus swap free and
>> total from swap -l listing.
>>
>> Signed-off-by: Dominic Cleal <dcl...@redhat.com>
>> ---
>> Local-branch: tickets/master/1423
>>  lib/facter/memory.rb      |   51
>> ++++++++++++++++++++++++++++++++++++++------
>>  lib/facter/util/memory.rb |   12 ++++++++++
>>  2 files changed, 56 insertions(+), 7 deletions(-)
>>
>> diff --git a/lib/facter/memory.rb b/lib/facter/memory.rb
>> index 06640e6..f744c3f 100644
>> --- a/lib/facter/memory.rb
>> +++ b/lib/facter/memory.rb
>> @@ -69,13 +69,7 @@ if Facter.value(:kernel) == "OpenBSD"
>>         end
>>     end
>>
>> -    Facter.add("MemoryFree") do
>> -        confine :kernel => :openbsd
>> -        memfree = Facter::Util::Resolution.exec("vmstat | tail -n 1 | awk
>> '{ print $5 }'")
>> -        setcode do
>> -            Facter::Memory.scale_number(memfree.to_f,"kB")
>> -        end
>> -    end
>> +    Facter::Memory.vmstat_find_free_memory()
>>
>>     Facter.add("MemoryTotal") do
>>         confine :kernel => :openbsd
>> @@ -85,3 +79,46 @@ if Facter.value(:kernel) == "OpenBSD"
>>         end
>>     end
>>  end
>> +
>> +if Facter.value(:kernel) == "SunOS"
>> +    swap = Facter::Util::Resolution.exec('/usr/sbin/swap -l')
>> +    swapfree, swaptotal = 0, 0
>> +    swap.each do |dev|
>> +        if dev =~ /^\/\S+\s.*\s+(\d+)\s+(\d+)$/
>> +            swaptotal += $1.to_i / 2
>> +            swapfree  += $2.to_i / 2
>> +        end
>> +    end
>> +
>> +    Facter.add("SwapSize") do
>> +        confine :kernel => :sunos
>> +        setcode do
>> +            Facter::Memory.scale_number(swaptotal.to_f,"kB")
>> +        end
>> +    end
>> +
>> +    Facter.add("SwapFree") do
>> +        confine :kernel => :sunos
>> +        setcode do
>> +            Facter::Memory.scale_number(swapfree.to_f,"kB")
>> +        end
>> +    end
>> +
>> +    # Total memory size available from prtconf
>> +    pconf = Facter::Util::Resolution.exec('/usr/sbin/prtconf')
>> +    phymem = ""
>> +    pconf.each do |line|
>> +        if line =~ /^Memory size:\s+(\d+) Megabytes/
>> +            phymem = $1
>> +        end
>> +    end
>> +
>> +    Facter.add("MemorySize") do
>> +        confine :kernel => :sunos
>> +        setcode do
>> +            Facter::Memory.scale_number(phymem.to_f,"MB")
>> +        end
>> +    end
>> +
>> +    Facter::Memory.vmstat_find_free_memory()
>> +end
>> diff --git a/lib/facter/util/memory.rb b/lib/facter/util/memory.rb
>> index 2004491..43abec6 100644
>> --- a/lib/facter/util/memory.rb
>> +++ b/lib/facter/util/memory.rb
>> @@ -50,5 +50,17 @@ module Facter::Memory
>>
>>         return "%.2f %s" % [size, s]
>>     end
>> +
>> +    def self.vmstat_find_free_memory()
>> +        row = Facter::Util::Resolution.exec('vmstat').split("\n")[-1]
>> +        if row =~ /^\s*\d+\s*\d+\s*\d+\s*\d+\s*(\d+)/
>> +            Facter.add("MemoryFree") do
>> +                memfree = $1
>> +                setcode do
>> +                    Facter::Memory.scale_number(memfree.to_f, "kB")
>> +                end
>> +            end
>> +        end
>> +    end
>>  end
>>
>> --
>> 1.7.3.2
>
> It looks like there are two independent changes here.  In addition to adding
> facts for SunOS, this change refactors the OpenBSD MemoryFree fact, moving
> it to util/memory.rb and rewriting it to use a regular expression.

Looks like it was basically extract method for common usage between
OpenBSD and SunOS

> Was the
> OpenBSD change intentional?  Because if so it should probably be in a
> separate commit, and also it probably could be better written using split()

Ideally yeah but tbh, I'd rather fix the platform support. Getting
community patches is valuable

> rather than a regular expression to pick out the fifth column.
> Regarding the SunOS changes, we are in the process of moving offices so our
> solaris box is unavailable, but we should be able to test the
> Solaris-related facts in the next week.

Umm EC2 OpenSolaris images? Obviously that doesn't help for sparc
specific things but you really should be able to test things whilst
your testlab is down.

Have you considered getting a cage in a DC for your test equipment as
that seems like it'd make sense.

Paul

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

Reply via email to