Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# $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