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
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
Thanks for the feedback Paul. The change was intentional as the Solaris
MemoryFree code would have been identical. I'll resubmit this as two
separate commits and use split().
Cheers,
--
Dominic Cleal
Red Hat Consulting
m: +44 (0)7818 512168
Cool - yeah use a single branch and two commits and mail_patches will
do the right thing in making it a patch series.
Paul
Signed-off-by: Dominic Cleal <dcl...@redhat.com>
---
Local-branch: tickets/master/1423
lib/facter/memory.rb | 43 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 43 insertions(+), 0 deletions(-)
diff --git a/lib/facter/memory.rb b/lib/facter/memory.rb
index 8eab377..f744c3f 100644
--- a/lib/facter/memory.rb
+++ b/lib/facter/memory.rb
@@ -79,3 +79,46 @@ if Facter.value(:kernel) == "OpenBSD"
--
1.7.3.2
Signed-off-by: Dominic Cleal <dcl...@redhat.com>
---
Local-branch: tickets/master/1423
lib/facter/memory.rb | 8 +-------
lib/facter/util/memory.rb | 10 ++++++++++
2 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/lib/facter/memory.rb b/lib/facter/memory.rb
index 06640e6..8eab377 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
diff --git a/lib/facter/util/memory.rb b/lib/facter/util/memory.rb
index 2004491..5687ff2 100644
--- a/lib/facter/util/memory.rb
+++ b/lib/facter/util/memory.rb
@@ -50,5 +50,15 @@ module Facter::Memory
return "%.2f %s" % [size, s]
end
+
+ def self.vmstat_find_free_memory()
+ row = Facter::Util::Resolution.exec("vmstat").split("\n")[-1]
+ Facter.add("MemoryFree") do
+ memfree = row.split[4]
+ setcode do
+ Facter::Memory.scale_number(memfree.to_f, "kB")
+ end
+ end
+ end
end
--
1.7.3.2
> --
> You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
> To post to this group, send email to puppe...@googlegroups.com.
> To unsubscribe from this group, send email to puppet-dev+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
>
>