Class: Chef::Provider::Mount::Aix

Inherits:
Mount show all
Defined in:
lib/chef/provider/mount/aix.rb

Instance Attribute Summary

Attributes inherited from Mount

#real_device

Attributes inherited from Chef::Provider::Mount

#unmount_retries

Attributes inherited from Chef::Provider

#action, #after_resource, #current_resource, #logger, #new_resource, #run_context

Instance Method Summary collapse

Methods inherited from Mount

#default_mount_options, #device_should_exist?, #load_current_resource, #mountable?, #network_device?, #remount_fs, #umount_fs

Methods inherited from Chef::Provider::Mount

#device_unchanged?, #load_current_resource, #remount_fs, #umount_fs

Methods inherited from Chef::Provider

action, action_description, action_descriptions, #action_nothing, #check_resource_semantics!, #cleanup_after_converge, #compile_and_converge_action, #converge_by, #converge_if_changed, #cookbook_name, #define_resource_requirements, #description, #events, include_resource_dsl?, include_resource_dsl_module, #introduced, #load_after_resource, #load_current_resource, #node, #process_resource_requirements, provides, provides?, #recipe_name, #requirements, #resource_collection, #resource_updated?, #run_action, #set_updated_status, supports?, use, use_inline_resources, #validate_required_properties!, #whyrun_mode?, #whyrun_supported?

Methods included from Mixin::Provides

#provided_as, #provides, #provides?

Methods included from Mixin::DescendantsTracker

#descendants, descendants, direct_descendants, #direct_descendants, find_descendants_by_name, #find_descendants_by_name, #inherited, store_inherited

Methods included from Mixin::LazyModuleInclude

#descendants, #include, #included

Methods included from Mixin::PowershellOut

#powershell_out, #powershell_out!

Methods included from Mixin::WindowsArchitectureHelper

#assert_valid_windows_architecture!, #disable_wow64_file_redirection, #forced_32bit_override_required?, #is_i386_process_on_x86_64_windows?, #node_supports_windows_architecture?, #node_windows_architecture, #restore_wow64_file_redirection, #valid_windows_architecture?, #with_os_architecture, #wow64_architecture_override_required?, #wow64_directory

Methods included from DSL::Secret

#default_secret_config, #default_secret_service, #secret, #with_secret_config, #with_secret_service

Methods included from DSL::RenderHelpers

#render_json, #render_toml, #render_yaml

Methods included from DSL::ReaderHelpers

#parse_file, #parse_json, #parse_toml, #parse_yaml

Methods included from DSL::Powershell

#ps_credential

Methods included from DSL::RegistryHelper

#registry_data_exists?, #registry_get_subkeys, #registry_get_values, #registry_has_subkeys?, #registry_key_exists?, #registry_value_exists?

Methods included from DSL::ChefVault

#chef_vault, #chef_vault_item, #chef_vault_item_for_environment

Methods included from DSL::DataQuery

#data_bag, #data_bag_item, #search, #tagged?

Methods included from EncryptedDataBagItem::CheckEncrypted

#encrypted?

Methods included from DSL::PlatformIntrospection

#older_than_win_2012_or_8?, #platform?, #platform_family?, #value_for_platform, #value_for_platform_family

Methods included from DSL::Recipe

#exec, #have_resource_class_for?, #resource_class_for

Methods included from DSL::Definitions

add_definition, #evaluate_resource_definition, #has_resource_definition?

Methods included from DSL::Resources

add_resource_dsl, remove_resource_dsl

Methods included from DSL::Cheffish

load_cheffish

Methods included from DSL::RebootPending

#reboot_pending?

Methods included from DSL::IncludeRecipe

#include_recipe, #load_recipe

Methods included from Mixin::NotifyingBlock

#notifying_block, #subcontext_block

Methods included from DSL::DeclareResource

#build_resource, #declare_resource, #delete_resource, #delete_resource!, #edit_resource, #edit_resource!, #find_resource, #find_resource!, #resources, #with_run_context

Methods included from DSL::Compliance

#include_input, #include_profile, #include_waiver

Constructor Details

#initialize(new_resource, run_context) ⇒ Aix

Override for aix specific handling



27
28
29
30
31
32
33
34
35
36
# File 'lib/chef/provider/mount/aix.rb', line 27

def initialize(new_resource, run_context)
  super
  # options and fstype are set to "defaults" and "auto" respectively in the Mount Resource class. These options are not valid for AIX, override them.
  if @new_resource.options[0] == "defaults"
    @new_resource.options([])
  end
  if @new_resource.fstype == "auto"
    @new_resource.send(:clear_fstype)
  end
end

Instance Method Details

#disable_fsObject



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/chef/provider/mount/aix.rb', line 193

def disable_fs
  contents = []
  if @current_resource.enabled
    found_device = false
    ::File.open("/etc/filesystems", "r").each_line do |line|
      case line
      when %r{^/.+:\s*$}
        if /#{Regexp.escape(@new_resource.mount_point)}+:/.match?(line)
          found_device = true
        else
          found_device = false
        end
      end
      unless found_device
        contents << line
      end
    end
    ::File.open("/etc/filesystems", "w") do |fstab|
      contents.each { |line| fstab.puts line }
    end
  else
    logger.debug("#{@new_resource} is not enabled - nothing to do")
  end
end

#enable_fsObject



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/chef/provider/mount/aix.rb', line 155

def enable_fs
  if @current_resource.enabled && mount_options_unchanged?
    logger.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/filesystems", "a") do |fstab|
    fstab.puts("\n\n#{@new_resource.mount_point}:")
    if network_device?
      device_details = device_fstab.split(":")
      fstab.puts("\tdev\t\t= #{device_details[1]}")
      fstab.puts("\tnodename\t\t= #{device_details[0]}")
    else
      fstab.puts("\tdev\t\t= #{device_fstab}")
    end
    fstab.puts("\tvfs\t\t= #{@new_resource.fstype}")
    fstab.puts("\tmount\t\t= false")
    fstab.puts "\toptions\t\t= #{@new_resource.options.join(",")}" unless @new_resource.options.nil? || @new_resource.options.empty?
    logger.trace("#{@new_resource} is enabled at #{@new_resource.mount_point}")
  end
end

#enabled?Boolean

Returns:

  • (Boolean)


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
# File 'lib/chef/provider/mount/aix.rb', line 38

def enabled?
  # Check to see if there is an entry in /etc/filesystems. Last entry for a volume wins. Using command "lsfs" to fetch entries.
  enabled = false

  regex_arr = device_fstab_regex.split(":")
  if regex_arr.size == 2
    nodename = regex_arr[0]
    devicename = regex_arr[1]
  else
    devicename = regex_arr[0]
  end
  # lsfs o/p = #MountPoint:Device:Vfs:Nodename:Type:Size:Options:AutoMount:Acct
  # search only for current mount point
  shell_out("lsfs", "-c", @new_resource.mount_point).stdout.each_line do |line|
    case line
    when /^#\s/
      next
    when /^#{Regexp.escape(@new_resource.mount_point)}:#{devicename}:(\S+):#{nodename}:(\S+)?:(\S+):(\S+):(\S+):(\S+)/
      # mount point entry with ipv6 address for nodename (ipv6 address use ':')
      enabled = true
      @current_resource.fstype($1)
      @current_resource.options($4)
      logger.trace("Found mount point #{@new_resource.mount_point} :: device_type #{@current_resource.device_type} in /etc/filesystems")
      next
    when /^#{Regexp.escape(@new_resource.mount_point)}:#{nodename}:(\S+)::(\S+)?:(\S+):(\S+):(\S+):(\S+)/
      # mount point entry with hostname or ipv4 address
      enabled = true
      @current_resource.fstype($1)
      @current_resource.options($4)
      @current_resource.device("")
      logger.trace("Found mount point #{@new_resource.mount_point} :: device_type #{@current_resource.device_type} in /etc/filesystems")
      next
    when /^#{Regexp.escape(@new_resource.mount_point)}:(\S+)?:(\S+):#{devicename}:(\S+)?:(\S+):(\S+):(\S+):(\S+)/
      # mount point entry with hostname or ipv4 address
      enabled = true
      @current_resource.fstype($2)
      @current_resource.options($5)
      @current_resource.device(devicename + "/")
      logger.trace("Found mount point #{@new_resource.mount_point} :: device_type #{@current_resource.device_type} in /etc/filesystems")
      next
    when /^#{Regexp.escape(@new_resource.mount_point)}:(.*?):(.*?):(.*?):(.*?):(.*?):(.*?):(.*?):(.*?)/
      if $3.split("=")[0] == "LABEL" || $1.split("=")[0] == "LABEL"
        @current_resource.device_type("label")
      elsif $3.split("=")[0] == "UUID" || $1.split("=")[0] == "UUID"
        @current_resource.device_type("uuid")
      else
        @current_resource.device_type("device")
      end

      if @current_resource.device_type != @new_resource.device_type
        enabled = true
        logger.trace("Found mount point #{@new_resource.mount_point} :: device_type #{@current_resource.device_type} in /etc/filesystems")
      else
        enabled = false
        logger.trace("Found conflicting mount point #{@new_resource.mount_point} in /etc/filesystems")
      end
    end

  end
  @current_resource.enabled(enabled)
end

#mount_fsObject



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/chef/provider/mount/aix.rb', line 121

def mount_fs
  unless @current_resource.mounted
    mountable?
    command = [ "mount", "-v", @new_resource.fstype ]

    unless @new_resource.options.nil? || @new_resource.options.empty?
      command << "-o"
      command << @new_resource.options.join(",")
    end

    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)
    logger.trace("#{@new_resource} is mounted at #{@new_resource.mount_point}")
  else
    logger.debug("#{@new_resource} is already mounted at #{@new_resource.mount_point}")
  end
end

#mount_options_unchanged?Boolean

Returns:

  • (Boolean)


182
183
184
185
186
187
188
189
190
191
# File 'lib/chef/provider/mount/aix.rb', line 182

def mount_options_unchanged?
  current_resource_options = @current_resource.options.delete_if { |x| x == "rw" }

  @current_resource.device == @new_resource.device &&
    @current_resource.fsck_device == @new_resource.fsck_device &&
    @current_resource.fstype == @new_resource.fstype &&
    current_resource_options == @new_resource.options &&
    @current_resource.dump == @new_resource.dump &&
    @current_resource.pass == @new_resource.pass
end

#mounted?Boolean

Returns:

  • (Boolean)


100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/chef/provider/mount/aix.rb', line 100

def mounted?
  mounted = false
  shell_out!("mount").stdout.each_line do |line|
    if network_device?
      device_details = device_fstab.split(":")
      search_device = device_details[1]
    else
      search_device = device_fstab_regex
    end
    case line
    when /#{search_device}\s+#{Regexp.escape(@new_resource.mount_point)}/
      mounted = true
      logger.trace("Special device #{device_logstring} mounted as #{@new_resource.mount_point}")
    when %r{^[/\w]+\s+#{Regexp.escape(@new_resource.mount_point)}\s+}
      mounted = false
      logger.trace("Found conflicting mount point #{@new_resource.mount_point} in /etc/fstab")
    end
  end
  @current_resource.mounted(mounted)
end

#remount_commandObject



147
148
149
150
151
152
153
# File 'lib/chef/provider/mount/aix.rb', line 147

def remount_command
  if !(@new_resource.options.nil? || @new_resource.options.empty?)
    [ "mount", "-o", "remount,#{@new_resource.options.join(",")}", @new_resource.device, @new_resource.mount_point ]
  else
    [ "mount", "-o", "remount", @new_resource.device, @new_resource.mount_point ]
  end
end