diff options
| author | Stefan Schulte <stefan.schulte@taunusstein.net> | 2011-01-23 13:03:15 +0100 |
|---|---|---|
| committer | Stefan Schulte <stefan.schulte@taunusstein.net> | 2011-01-25 21:23:35 +0100 |
| commit | 2884660768fbea22a91e3c5bab9595ce075e67a5 (patch) | |
| tree | a1574c0e674e165948d92489bfea076a45ef5e40 | |
| parent | ade951aa9d0017743059f282cbc1611a8b0b02f0 (diff) | |
| download | puppet-2884660768fbea22a91e3c5bab9595ce075e67a5.tar.gz puppet-2884660768fbea22a91e3c5bab9595ce075e67a5.tar.xz puppet-2884660768fbea22a91e3c5bab9595ce075e67a5.zip | |
(#4914) Prefetch mountstate
Add a method mountinstances that returns a list of currently mounted
filesystems and overwrite prefetch to update the :ensure state of a
mount resource to either
- :absent => not in fstab and not mounted
- :unmounted => in fstab but not mounted
- :mounted => in fstab and mounted
- :ghost => not in fstab but mounted
This is just one step towards 4914. Next will be query the property_hash
when asking mounted? and update the insync? methods to handle the
different states.
| -rwxr-xr-x | lib/puppet/provider/mount/parsed.rb | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/puppet/provider/mount/parsed.rb b/lib/puppet/provider/mount/parsed.rb index a8c8bc118..9422ca6bb 100755 --- a/lib/puppet/provider/mount/parsed.rb +++ b/lib/puppet/provider/mount/parsed.rb @@ -36,5 +36,55 @@ Puppet::Type.type(:mount).provide(:parsed,:parent => Puppet::Provider::ParsedFil record_line self.name, :fields => @fields, :separator => /\s+/, :joiner => "\t", :optional => optional_fields + # Every entry in fstab is :unmounted until we can prove different + def self.prefetch_hook(target_records) + target_records.collect do |record| + record[:ensure] = :unmounted if record[:record_type] == :parsed + record + end + end + + def self.prefetch(resources = nil) + # Get providers for all resources the user defined and that match + # a record in /etc/fstab. + super + # We need to do two things now: + # - Update ensure from :unmounted to :mounted if the resource is mounted + # - Check for mounted devices that are not in fstab and + # set ensure to :ghost (if the user wants to add an entry + # to fstab we need to know if the device was mounted before) + mountinstances.each do |hash| + if mount = resources[hash[:name]] + case mount.provider.get(:ensure) + when :absent # Mount not in fstab + mount.provider.set(:ensure => :ghost) + when :unmounted # Mount in fstab + mount.provider.set(:ensure => :mounted) + end + end + end + end + + def self.mountinstances + # XXX: Will not work for mount points that have spaces in path (does fstab support this anyways?) + regex = case Facter.value("operatingsystem") + when "Darwin" + / on (?:\/private\/var\/automount)?(\S*)/ + when "Solaris", "HP-UX" + /^(\S*) on / + else + / on (\S*)/ + end + instances = [] + mountcmd.split("\n").each do |line| + if match = regex.match(line) and name = match.captures.first + instances << {:name => name, :mounted => :yes} # Only :name is important here + else + raise Puppet::Error, "Could not understand line #{line} from mount output" + end + end + instances + end + end |
