self.get_unmasked_base_mounts

in cookbooks/fb_fstab/libraries/default.rb [241:339]


      def self.get_unmasked_base_mounts(format, node, hash_by = 'device')
        res = case format
              when :hash
                {}
              when :lines
                []
              end
        hash_by_values = Set['device', 'mount_point']
        unless hash_by_values.include?(hash_by)
          fail "fb_fstab: Invalid hash_by value, allowed are: #{hash_by_values}"
        end

        desired_mounts = node['fb_fstab']['mounts'].to_hash
        FB::Fstab.base_fstab_contents(node).each_line do |line|
          next if line.strip.empty?
          
          next if line.include?('swap') && node['fb_fstab']['exclude_base_swap']

          line_parts = line.strip.split
          line_dev_spec = line_parts[0]

          
          
          
          
          
          next if desired_mounts.any? do |_name, data|
            line_dev_spec == data['device']
          end

          
          
          begin
            fs_spec = canonicalize_device(line_dev_spec, node)
          rescue StandardError => e
            
            
            
            
            raise e unless line_dev_spec.start_with?('UUID=')
            next if desired_mounts.any? do |_name, data|
              data['mount_point'] == line_parts[1] &&
                data['device'].start_with?('LABEL=')
            end

            raise e
          end
          
          next if desired_mounts.any? do |_name, data|
            begin
              cdev = canonicalize_device(data['device'], node)
            rescue RuntimeError => e
              
              
              
              
              
              
              
              
              next if data['allow_mount_failure']

              raise e
            end
            
            
            [data['device'], cdev].include?(fs_spec) &&
              !self.btrfs_subvol?(data['type'], data['opts'])
          end

          case format
          when :hash
            mount_point = line_parts[1]
            case hash_by
            when 'device'
              res[fs_spec] = {
                'mount_point' => mount_point,
                'type' => line_parts[2],
                'opts' => line_parts[3],
                'dump' => line_parts[4],
                'pass' => line_parts[5],
              }
            when 'mount_point'
              res[mount_point] = {
                'device' => fs_spec,
                'type' => line_parts[2],
                'opts' => line_parts[3],
                'dump' => line_parts[4],
                'pass' => line_parts[5],
              }
            end
          when :lines
            res << line.strip
          end
        end
        Chef::Log.debug("fb_fstab: base mounts: #{res}")
        res
      end