Module: Puppet::Provider::Mount

Defined in:
core_modules/mount_core/lib/puppet/provider/mount.rb

Overview

A module just to store the mount/unmount methods. Individual providers still need to add the mount commands manually.

Instance Method Summary collapse

Instance Method Details

#mountObject

This only works when the mount point is synced to the fstab.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'core_modules/mount_core/lib/puppet/provider/mount.rb', line 7

def mount
  args = []

  # In general we do not have to pass mountoptions because we always
  # flush /etc/fstab before attempting to mount. But old code suggests
  # that MacOS always needs the mount options to be explicitly passed to
  # the mount command
  if Facter.value(:kernel) == 'Darwin'
    args << '-o' << options if options && options != :absent
  end
  args << resource[:name]

  mountcmd(*args)
  case get(:ensure)
  when :absent then set(ensure: :ghost)
  when :unmounted then set(ensure: :mounted)
  end
end

#mounted?Boolean

Is the mount currently mounted?

Returns:

  • (Boolean)


73
74
75
# File 'core_modules/mount_core/lib/puppet/provider/mount.rb', line 73

def mounted?
  [:mounted, :ghost].include?(get(:ensure))
end

#remountObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'core_modules/mount_core/lib/puppet/provider/mount.rb', line 26

def remount
  # TRANSLATORS refers to remounting a file system
  info _('Remounting')
  os = Facter.value(:operatingsystem)
  supports_remounts = (resource[:remounts] == :true)
  if supports_remounts && os == 'AIX'
    remount_with_option('remount')
  elsif %r{^(FreeBSD|DragonFly|OpenBSD)$}.match?(os)
    remount_with_option('update')
  elsif supports_remounts
    mountcmd '-o', 'remount', resource[:name]
  else
    unmount
    mount
  end
end

#remount_with_option(option) ⇒ Object

Remount by appending the supplied param “option” to any existing explicitly defined options. If resource has no explicitly defined options, will mount with only “option”.

Parameters:

  • option (String)

    A remount option to use or append with existing options



48
49
50
51
52
53
54
55
# File 'core_modules/mount_core/lib/puppet/provider/mount.rb', line 48

def remount_with_option(option)
  options = if using_explicit_options?
              self.options + ',' + option
            else
              option
            end
  mountcmd '-o', options, resource[:name]
end

#unmountObject

This only works when the mount point is synced to the fstab.



62
63
64
65
66
67
68
69
70
# File 'core_modules/mount_core/lib/puppet/provider/mount.rb', line 62

def unmount
  umount resource[:name]

  # Update property hash for future queries (e.g. refresh is called)
  case get(:ensure)
  when :mounted then set(ensure: :unmounted)
  when :ghost then set(ensure: :absent)
  end
end

#using_explicit_options?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'core_modules/mount_core/lib/puppet/provider/mount.rb', line 57

def using_explicit_options?
  !options.nil? && !options.empty?
end