# File lib/chef/provider/mount/mount.rb, line 193 def device_should_exist? ( @new_resource.device != "none" ) && ( not network_device? ) && ( not ] tmpfs fuse ].include? @new_resource.fstype ) end
# File lib/chef/provider/mount/mount.rb, line 166 def disable_fs if @current_resource.enabled contents = [] found = false ::File.readlines("/etc/fstab").reverse_each do |line| if !found && line =~ /^#{device_fstab_regex}\s+#{Regexp.escape(@new_resource.mount_point)}/ found = true Chef::Log.debug("#{@new_resource} is removed from fstab") next else contents << line end end ::File.open("/etc/fstab", "w") do |fstab| contents.reverse_each { |line| fstab.puts line} end else Chef::Log.debug("#{@new_resource} is not enabled - nothing to do") end end
# File lib/chef/provider/mount/mount.rb, line 149 def enable_fs if @current_resource.enabled && mount_options_unchanged? Chef::Log.debug("#{@new_resource} is already enabled - nothing to do") return nil end if @current_resource.enabled # The current options don't match what we have, so # disable, then enable. disable_fs end ::File.open("/etc/fstab", "a") do |fstab| fstab.puts("#{device_fstab} #{@new_resource.mount_point} #{@new_resource.fstype} #{@new_resource.options.nil? ? "defaults" : @new_resource.options.join(",")} #{@new_resource.dump} #{@new_resource.pass}") Chef::Log.debug("#{@new_resource} is enabled at #{@new_resource.mount_point}") end end
# File lib/chef/provider/mount/mount.rb, line 53 def enabled? # Check to see if there is a entry in /etc/fstab. Last entry for a volume wins. enabled = false ::File.foreach("/etc/fstab") do |line| case line when /^[#\s]/ next when /^#{device_fstab_regex}\s+#{Regexp.escape(@new_resource.mount_point)}\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/ enabled = true @current_resource.fstype($1) @current_resource.options($2) @current_resource.dump($3.to_i) @current_resource.pass($4.to_i) Chef::Log.debug("Found mount #{device_fstab} to #{@new_resource.mount_point} in /etc/fstab") next when /^[\/\w]+\s+#{Regexp.escape(@new_resource.mount_point)}\s+/ enabled = false Chef::Log.debug("Found conflicting mount point #{@new_resource.mount_point} in /etc/fstab") end end @current_resource.enabled(enabled) end
# File lib/chef/provider/mount/mount.rb, line 35 def load_current_resource @current_resource = Chef::Resource::Mount.new(@new_resource.name) @current_resource.mount_point(@new_resource.mount_point) @current_resource.device(@new_resource.device) mounted? enabled? end
# File lib/chef/provider/mount/mount.rb, line 101 def mount_fs unless @current_resource.mounted mountable? command = "mount -t #{@new_resource.fstype}" command << " -o #{@new_resource.options.join(',')}" unless @new_resource.options.nil? || @new_resource.options.empty? command << case @new_resource.device_type when :device " #{device_real}" when :label " -L #{@new_resource.device}" when :uuid " -U #{@new_resource.device}" end command << " #{@new_resource.mount_point}" shell_out!(command) Chef::Log.debug("#{@new_resource} is mounted at #{@new_resource.mount_point}") else Chef::Log.debug("#{@new_resource} is already mounted at #{@new_resource.mount_point}") end end
# File lib/chef/provider/mount/mount.rb, line 43 def mountable? # only check for existence of non-remote devices if (device_should_exist? && !::File.exists?(device_real) ) raise Chef::Exceptions::Mount, "Device #{@new_resource.device} does not exist" elsif( @new_resource.mount_point != "none" && !::File.exists?(@new_resource.mount_point) ) raise Chef::Exceptions::Mount, "Mount point #{@new_resource.mount_point} does not exist" end return true end
# File lib/chef/provider/mount/mount.rb, line 76 def mounted? mounted = false # "mount" outputs the mount points as real paths. Convert # the mount_point of the resource to a real path in case it # contains symlinks in its parents dirs. real_mount_point = if ::File.exists? @new_resource.mount_point ::File.realpath(@new_resource.mount_point) else @new_resource.mount_point end shell_out!("mount").stdout.each_line do |line| case line when /^#{device_mount_regex}\s+on\s+#{Regexp.escape(real_mount_point)}/ mounted = true Chef::Log.debug("Special device #{device_logstring} mounted as #{real_mount_point}") when /^([\/\w])+\son\s#{Regexp.escape(real_mount_point)}\s+/ mounted = false Chef::Log.debug("Special device #{$~[1]} mounted as #{real_mount_point}") end end @current_resource.mounted(mounted) end
# File lib/chef/provider/mount/mount.rb, line 189 def network_device? @new_resource.device =~ /:/ || @new_resource.device =~ /\/\// end
# File lib/chef/provider/mount/mount.rb, line 131 def remount_command return "mount -o remount #{@new_resource.mount_point}" end
# File lib/chef/provider/mount/mount.rb, line 135 def remount_fs if @current_resource.mounted and @new_resource.supports[:remount] shell_out!(remount_command) @new_resource.updated_by_last_action(true) Chef::Log.debug("#{@new_resource} is remounted at #{@new_resource.mount_point}") elsif @current_resource.mounted umount_fs sleep 1 mount_fs else Chef::Log.debug("#{@new_resource} is not mounted at #{@new_resource.mount_point} - nothing to do") end end
# File lib/chef/provider/mount/mount.rb, line 122 def umount_fs if @current_resource.mounted shell_out!("umount #{@new_resource.mount_point}") Chef::Log.debug("#{@new_resource} is no longer mounted at #{@new_resource.mount_point}") else Chef::Log.debug("#{@new_resource} is not mounted at #{@new_resource.mount_point}") end end
Generated with the Darkfish Rdoc Generator 2.