summaryrefslogtreecommitdiffstats
path: root/lib/puppet/provider/mount/parsed.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet/provider/mount/parsed.rb')
-rwxr-xr-xlib/puppet/provider/mount/parsed.rb164
1 files changed, 28 insertions, 136 deletions
diff --git a/lib/puppet/provider/mount/parsed.rb b/lib/puppet/provider/mount/parsed.rb
index 086cd5cd9..af67ca6ff 100755
--- a/lib/puppet/provider/mount/parsed.rb
+++ b/lib/puppet/provider/mount/parsed.rb
@@ -1,150 +1,43 @@
require 'puppet/provider/parsedfile'
-Puppet::Type.type(:mount).provide :parsed, :parent => Puppet::Provider::ParsedFile do
- @filetype = Puppet::FileType.filetype(:flat)
-
- commands :mountcmd => "mount", :umount => "umount", :df => "df"
-
- def self.init
- @platform = Facter["operatingsystem"].value
- case @platform
- when "Solaris":
- @path = "/etc/vfstab"
- @fields = [:device, :blockdevice, :path, :fstype, :pass, :atboot,
- :options]
- @fielddefaults = [ nil ] * @fields.size
- when "Darwin":
- @filetype = Puppet::FileType.filetype(:netinfo)
- @filetype.format = "fstab"
- @path = "mounts"
- @fields = [:device, :path, :fstype, :options, :dump, :pass]
- @fielddefaults = [ nil ] * @fields.size
-
- # How to map the dumped table to what we want
- @fieldnames = {
- "name" => :device,
- "dir" => :path,
- "dump_freq" => :dump,
- "passno" => :pass,
- "vfstype" => :fstype,
- "opts" => :options
- }
- else
- @path = "/etc/fstab"
- @fields = [:device, :path, :fstype, :options, :dump, :pass]
- @fielddefaults = [ nil ] * 4 + [ "0", "2" ]
- end
-
- # Allow Darwin to override the default filetype
- unless defined? @filetype
- @filetype = Puppet::FileType.filetype(:flat)
- end
- end
-
- init
-
- # XXX This needs to change to being a netinfo provider
- unless @platform == "Darwin"
- confine :exists => @path
- end
-
- def self.clear
- init
- super
- end
-
- # Parse a mount tab.
- #
- # This method also stores existing comments, and it stores all
- # mounts in order, mostly so that comments are retained in the
- # order they were written and in proximity to the same fses.
- def self.parse(text)
- # provide a single exception for darwin & netinfo
- if @filetype == Puppet::FileType.filetype(:netinfo)
- return parseninfo(text)
- end
- count = 0
-
- instances = []
- text.chomp.split("\n").each { |line|
- hash = {}
- case line
- when /^#/, /^\s*$/:
- # add comments and blank lines to the list as they are
- instances << line
- comment(line)
- else
- values = line.split(/\s+/)
- if @fields.length < values.length
- raise Puppet::Error, "Could not parse line %s" % line
- end
+fstab = nil
+case Facter.value(:operatingsystem)
+when "Solaris": fstab = "/etc/vfstab"
+else
+ fstab = "/etc/fstab"
+end
- values = @fielddefaults.zip(values).collect { |d, v| v || d }
- unless @fields.length == values.length
- raise Puppet::Error, "Could not parse line %s" % line
- end
-
- @fields.zip(values).each do |field, value|
- hash[field] = value
- end
+Puppet::Type.type(:mount).provide(:parsed,
+ :parent => Puppet::Provider::ParsedFile,
+ :default_target => fstab,
+ :filetype => :flat
+) do
- instances << hash
- count += 1
- end
- }
+ commands :mountcmd => "mount", :umount => "umount", :df => "df"
- return instances
+ @platform = Facter["operatingsystem"].value
+ case @platform
+ when "Solaris":
+ @fields = [:device, :blockdevice, :name, :fstype, :pass, :atboot,
+ :options]
+ else
+ @fields = [:device, :name, :fstype, :options, :dump, :pass]
+ @fielddefaults = [ nil ] * 4 + [ "0", "2" ]
end
- # Parse a netinfo table.
- def self.parseninfo(text)
- array = @fileobj.to_array(text)
+ text_line :comment, :match => /^\s*#/
+ text_line :blank, :match => /^\s*$/
- instances = []
- array.each do |record|
- hash = {}
- @fieldnames.each do |name, field|
- if value = record[name]
- if field == :options
- hash[field] = value.join(",")
- else
- hash[field] = value[0]
- end
- else
- raise ArgumentError, "Field %s was not provided" % [name]
- end
- end
-
- instances << hash
- end
-
- return instances
- end
-
- # Convert the current object into an fstab-style string.
- def self.to_record(hash)
- self.fields.collect do |field|
- if value = hash[field]
- value
- else
- raise Puppet::Error,
- "Could not retrieve value for %s" % field
- end
- end.join("\t")
- end
+ record_line self.name, :fields => @fields, :separator => /\s+/, :joiner => "\t"
# This only works when the mount point is synced to the fstab.
def mount
- mountcmd @model[:path]
+ mountcmd @model[:name]
end
# This only works when the mount point is synced to the fstab.
def unmount
- output = %x{#{command(:umount)} #{@model[:path]}}
-
- unless $? == 0
- raise Puppet::Error, "Could not unmount %s" % @model[:path]
- end
+ umount @model[:name]
end
# Is the mount currently mounted?
@@ -156,13 +49,12 @@ Puppet::Type.type(:mount).provide :parsed, :parent => Puppet::Provider::ParsedFi
when "Solaris": df = "#{command(:df)} -k"
end
%x{#{df}}.split("\n").find do |line|
- p line
fs = line.split(/\s+/)[-1]
if platform == "Darwin"
- fs == "/private/var/automount" + @model[:path] or
- fs == @model[:path]
+ fs == "/private/var/automount" + @model[:name] or
+ fs == @model[:name]
else
- fs == @model[:path]
+ fs == @model[:name]
end
end
end