diff options
author | Thom May <thom@chef.io> | 2018-03-22 09:56:23 +0000 |
---|---|---|
committer | Thom May <thom@chef.io> | 2018-03-22 09:56:23 +0000 |
commit | 80a8f79f38bdc05c7a87b6659dd504993f8a89d0 (patch) | |
tree | 78edbddd6813ce4b921d40d3f5c761ec63e759d5 | |
parent | 65d26d53a70a7813c36e29f819868aadacd612f9 (diff) | |
download | chef-tm/revert_mount_properties.tar.gz |
partially revert 61e3d4bb: do not use properties for mounttm/revert_mount_properties
Signed-off-by: Thom May <thom@chef.io>
-rw-r--r-- | lib/chef/provider/mount/solaris.rb | 8 | ||||
-rw-r--r-- | lib/chef/resource/mount.rb | 146 |
2 files changed, 130 insertions, 24 deletions
diff --git a/lib/chef/provider/mount/solaris.rb b/lib/chef/provider/mount/solaris.rb index f59a2d2c6a..fc2c9483ce 100644 --- a/lib/chef/provider/mount/solaris.rb +++ b/lib/chef/provider/mount/solaris.rb @@ -74,8 +74,8 @@ class Chef end def mount_fs - actual_options = options || [] - actual_options.delete("noauto") + actual_options = native_options(options) + actual_options.delete("-") command = "mount -F #{fstype}" command << " -o #{actual_options.join(',')}" unless actual_options.empty? command << " #{device} #{mount_point}" @@ -88,8 +88,8 @@ class Chef def remount_fs # FIXME: Should remount always do the remount or only if the options change? - actual_options = options || [] - actual_options.delete("noauto") + actual_options = native_options(options) + actual_options.delete("-") mount_options = actual_options.empty? ? "" : ",#{actual_options.join(',')}" shell_out!("mount -o remount#{mount_options} #{mount_point}") end diff --git a/lib/chef/resource/mount.rb b/lib/chef/resource/mount.rb index dffb96cb53..f70267fd23 100644 --- a/lib/chef/resource/mount.rb +++ b/lib/chef/resource/mount.rb @@ -24,37 +24,143 @@ class Chef class Mount < Chef::Resource description "Use the mount resource to manage a mounted file system." + identity_attr :device + + state_attrs :mount_point, :device_type, :fstype, :username, :password, :domain + 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, Hash, - default: lazy { { remount: false } }, - coerce: proc { |x| x.is_a?(Array) ? x.each_with_object({}) { |i, m| m[i] = true } : x } + property :supports, Hash, default: lazy { { remount: false } }, + coerce: proc { |x| x.is_a?(Array) ? x.each_with_object({}) { |i, m| m[i] = true } : x } property :password, String, sensitive: true - property :mount_point, String, name_property: true - property :device, String, identity: true + def initialize(name, run_context = nil) + super + @mount_point = name + @device = nil + @device_type = :device + @fsck_device = "-" + @fstype = "auto" + @options = ["defaults"] + @dump = 0 + @pass = 2 + @mounted = false + @enabled = false + @username = nil + @password = nil + @domain = nil + end + + def mount_point(arg = nil) + set_or_return( + :mount_point, + arg, + :kind_of => [ String ] + ) + end + + def device(arg = nil) + set_or_return( + :device, + arg, + :kind_of => [ String ] + ) + end + + def device_type(arg = nil) + real_arg = arg.kind_of?(String) ? arg.to_sym : arg + valid_devices = if RUBY_PLATFORM =~ /solaris/i + [ :device ] + else + [ :device, :label, :uuid ] + end + set_or_return( + :device_type, + real_arg, + :equal_to => valid_devices + ) + end + + def fsck_device(arg = nil) + set_or_return( + :fsck_device, + arg, + :kind_of => [ String ] + ) + end + + def fstype(arg = nil) + set_or_return( + :fstype, + arg, + :kind_of => [ String ] + ) + end + + def options(arg = nil) + ret = set_or_return( + :options, + arg, + :kind_of => [ Array, String ] + ) + + if ret.is_a? String + ret.tr(",", " ").split(/ /) + else + ret + end + end + + def dump(arg = nil) + set_or_return( + :dump, + arg, + :kind_of => [ Integer, FalseClass ] + ) + end - property :device_type, [String, Symbol], - coerce: proc { |arg| arg.kind_of?(String) ? arg.to_sym : arg }, - default: :device, - equal_to: RUBY_PLATFORM =~ /solaris/i ? %i{ device } : %i{ device label uuid } + def pass(arg = nil) + set_or_return( + :pass, + arg, + :kind_of => [ Integer, FalseClass ] + ) + end + + def mounted(arg = nil) + set_or_return( + :mounted, + arg, + :kind_of => [ TrueClass, FalseClass ] + ) + end - property :fsck_device, String, default: "-" - property :fstype, [String, nil], default: "auto" + def enabled(arg = nil) + set_or_return( + :enabled, + arg, + :kind_of => [ TrueClass, FalseClass ] + ) + end - property :options, [Array, String, nil], - coerce: proc { |arg| arg.kind_of?(String) ? arg.split(",") : arg }, - default: %w{defaults} + def username(arg = nil) + set_or_return( + :username, + arg, + :kind_of => [ String ] + ) + end - property :dump, [Integer, FalseClass], default: 0 - property :pass, [Integer, FalseClass], default: 2 - property :mounted, [TrueClass, FalseClass], default: false - property :enabled, [TrueClass, FalseClass], default: false - property :username, String - property :domain, String + def domain(arg = nil) + set_or_return( + :domain, + arg, + :kind_of => [ String ] + ) + end private |