Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
# $Id: parsed.rb 2612 2009-06-21 17:29:50Z uwaechte $ require 'puppet/provider/parsedfile' exports="/etc/exports" Puppet::Type.type(:nfs_export).provide( :parsed, :parent => Puppet::Provider::ParsedFile, :default_target => exports, :filetype => :flat ) do confine :exists => exports text_line :comment, :match => /^#/ text_line :blank, :match => /^\s*$/ record_line :parsed, :fields => %w{name export_point client options}, :optional => %w{export_point}, :block_eval => :instance do def process(line) record = {} parseregex = nil case Facter.value(:kernel) when "Linux" parseregex = /^(\S+)\s+(\S+)\((\S+)\)\s#PuppetName:\s(\S+)$/ else parseregex = /^(\S+)\s+(.*)\s(\S+)\s#PuppetName:\s(\S+)$/ end if line =~ parseregex record[:export_point] = $1 case Facter.value(:kernel) when "Linux" record[:client] = $3 record[:options] = $2 else record[:client] = $2 record[:options] = $3 end record[:name] = $4 else raise Puppet::Error, "Could not match '%s'" % line end return record end def self.to_line(record) return super unless record[:record_type] == :parsed [:client, :options, :name].each do |n| unless record[n] and record[n] != :absent raise ArgumentError, "%s is a required attribute for nfs_export" % n end end str = "" if !record[:export_point] record[:export_point] = record[:name] end case Facter.value(:kernel) when "Linux" return "%s\t%s(%s) #PuppetName: %s" %[record[:export_point], record[:client], record[:options], record[:name]] else return "%s\t%s %s #PuppetName: %s" %[record[:export_point], record[:options], record[:client], record[:name]] end end end def flush cmd=nil if Facter.value(:kernel) == "Linux" cmd = "/usr/sbin/exportfs -ra" elsif Facter.value(:kernel) == "FreeBSD" cmd = "/etc/rc.d/mountd reload" end out = %x{#{cmd}} unless $? == 0 raise ArgumentError, "Failed to apply new exports: #{out}" end end end
This paste will be private.
From the Design Piracy series on my blog: