summaryrefslogtreecommitdiff
path: root/lib/chef/resource/mount.rb
blob: ed5d9a0e0b4d5a9b0f4a73819846c10b51932f84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#
# Author:: Joshua Timberman (<joshua@chef.io>)
# Author:: Tyler Cloke (<tyler@chef.io>)
# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require_relative "../resource"

class Chef
  class Resource
    class Mount < Chef::Resource
      description "Use the **mount** resource to manage a mounted file system."
      unified_mode true

      provides :mount

      default_action :mount
      allowed_actions :mount, :umount, :unmount, :remount, :enable, :disable

      # this is a poor API please do not re-use this pattern
      property :supports, [Array, Hash],
        description: "Specify a Hash of supported mount features.",
        default: lazy { { remount: false } },
        coerce: proc { |x| x.is_a?(Array) ? x.each_with_object({}) { |i, m| m[i] = true } : x }

      property :password, String,
        description: "Windows only:. Use to specify the password for username.",
        sensitive: true

      property :mount_point, String, name_property: true,
               description: "The directory (or path) in which the device is to be mounted. Defaults to the name of the resource block if not provided."

      property :device, String, identity: true,
               description: "Required for :umount and :remount actions (for the purpose of checking the mount command output for presence). The special block device or remote node, a label, or a uuid to be mounted."

      property :device_type, [String, Symbol],
        description: "The type of device: :device, :label, or :uuid",
        coerce: proc { |arg| arg.is_a?(String) ? arg.to_sym : arg },
        default: :device,
        equal_to: RUBY_PLATFORM.match?(/solaris/i) ? %i{ device } : %i{ device label uuid }

      # @todo this should get refactored away: https://github.com/chef/chef/issues/7621
      property :mounted, [TrueClass, FalseClass], default: false, skip_docs: true

      property :fsck_device, String,
        description: "Solaris only: The fsck device.",
        default: "-"

      property :fstype, [String, nil],
        description: "The file system type (fstype) of the device.",
        default: "auto"

      property :options, [Array, String, nil],
        description: "An array or comma separated list of options for the mount.",
        coerce: proc { |arg| arg.is_a?(String) ? arg.split(",") : arg },
        default: %w{defaults}

      property :dump, [Integer, FalseClass],
        description: "The dump frequency (in days) used while creating a file systems table (fstab) entry.",
        default: 0

      property :pass, [Integer, FalseClass],
        description: "The pass number used by the file system check (fsck) command while creating a file systems table (fstab) entry.",
        default: 2

      property :enabled, [TrueClass, FalseClass],
        description: "Use to specify if a mounted file system is enabled.",
        default: false

      property :username, String,
        description: "Windows only: Use to specify the user name."

      property :domain, String,
        description: "Windows only: Use to specify the domain in which the `username` and `password` are located."

      private

      # Used by the AIX provider to set fstype to nil.
      # @todo use property to make nil a valid value for fstype
      def clear_fstype
        @fstype = nil
      end

    end
  end
end