hello, guys in the puppet erb template ,I want get the vaule of the memorysize * 75%. but I don''t know ruby and erb. the memorysize like "251.02 MB" ,how to change to a number like 170 somting. maybe be the firset step is to delete the "MB" then math the 251.02 then get the integer ? who can help me! hmy --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
I''m Pair. On Sun, Apr 27, 2008 at 12:08:31AM -0700, huangmingyou wrote:> > hello, guys > in the puppet erb template ,I want get the vaule of the > memorysize * 75%. but I don''t know ruby and erb. > > the memorysize like "251.02 MB" ,how to change to a number like 170 > somting. > > maybe be the firset step is to delete the "MB" then math the 251.02 > then get the integer ?puppet''s memorysize value is provide by facter. http://reductivelabs.com/trac/facter/browser/lib/facter/memory.rb * Your answers * add custom facts * write dirty code * example <% val=memorysize.sub(/ MB$/, "") val=val.to_f*0.75 puts "#{val} MB" %> -- Pair <pairsan@gmail.com> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
thank you replay, yes,it works. I just test anoter method, in the template.erb file, write this <% memorysize.to_i*0.75 -%> ,it also work :D On Apr 27, 4:21 pm, Pair <pair...@gmail.com> wrote:> I''m Pair. > > On Sun, Apr 27, 2008 at 12:08:31AM -0700, huangmingyou wrote: > > > hello, guys > > in the puppet erb template ,I want get the vaule of the > > memorysize * 75%. but I don''t know ruby and erb. > > > the memorysize like "251.02 MB" ,how to change to a number like 170 > > somting. > > > maybe be the firset step is to delete the "MB" then math the 251.02 > > then get the integer ? > > puppet''s memorysize value is provide by facter. > > http://reductivelabs.com/trac/facter/browser/lib/facter/memory.rb > > * Your answers > * add custom facts > * write dirty code > * example > <% > val=memorysize.sub(/ MB$/, "") > val=val.to_f*0.75 > puts "#{val} MB" > %> > > -- > Pair <pair...@gmail.com>--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
I''m Pair.> I just test anoter method, in the template.erb file, write this > > <% memorysize.to_i*0.75 -%> ,it also work :D >Oh! it''s a good method! I wish I could sink into the floor. -- Pair <pairsan@gmail.com> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
I do mine a little different in the fact that i need to calculate squid memory assignment so i want total system memory minus 512M and if the system only has 512M i want it set to 32M so something like: def calcMem() memory = '''' memoryLess512 = '''' File.readlines("/proc/meminfo").each { |line| if line =~ /MemTotal\:\s+(\d+)\skB/ memory = ( $1.to_i / 1024 ) # Check if total memory is 512mb or less, if so set the output var to 32mb if not memory <= 512 memoryLess512 = ( memory - 512 ) else memoryLess512 = 32 end end } return memoryLess512 end Facter.add("mem_minus_512") do setcode do calcMem end end Cheers Brendan Pair wrote:> I''m Pair. > > >> I just test anoter method, in the template.erb file, write this >> >> <% memorysize.to_i*0.75 -%> ,it also work :D >> >> > Oh! it''s a good method! > > I wish I could sink into the floor. > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
thats good for me, because I do this for squid.conf''s cache_mem too. but now,I only do some math like this : totoal_memory_size * 0.45 . On Apr 30, 2:28 pm, Brendan Beveridge <bren...@sitesuite.com.au> wrote:> I do mine a little different in the fact that i need to calculate squid > memory assignment > so i want total system memory minus 512M and if the system only has 512M > i want it set to 32M > > so something like: > def calcMem() > memory = '''' > memoryLess512 = '''' > File.readlines("/proc/meminfo").each { |line| > if line =~ /MemTotal\:\s+(\d+)\skB/ > memory = ( $1.to_i / 1024 ) > # Check if total memory is 512mb or less, if so set the output var to 32mb > if not memory <= 512 > memoryLess512 = ( memory - 512 ) > else > memoryLess512 = 32 > end > end} > > return memoryLess512 > end > > Facter.add("mem_minus_512") do > setcode do > calcMem > end > end > > Cheers > Brendan > > Pair wrote: > > I''m Pair. > > >> I just test anoter method, in the template.erb file, write this > > >> <% memorysize.to_i*0.75 -%> ,it also work :D > > > Oh! it''s a good method! > > > I wish I could sink into the floor.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---