From 8a0926ac5069e4a0a3db37e436d7b6d3d243f19c Mon Sep 17 00:00:00 2001 From: Thom May Date: Thu, 22 Mar 2018 09:56:23 +0000 Subject: partially revert 61e3d4bb: do not use properties for mount Signed-off-by: Thom May --- lib/chef/provider/mount/solaris.rb | 8 +- 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 2b1a93becb..1a1f8c0565 100644 --- a/lib/chef/resource/mount.rb +++ b/lib/chef/resource/mount.rb @@ -24,37 +24,143 @@ class Chef # Use the mount resource to manage a mounted file system. class Mount < Chef::Resource + 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, nil], 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, nil], default: 0 - property :pass, [Integer, FalseClass, nil], 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 -- cgit v1.2.1