Class: Chef::Provider::Mdadm

Inherits:
Chef::Provider show all
Includes:
Mixin::Command
Defined in:
lib/chef/provider/mdadm.rb

Instance Attribute Summary

Attributes inherited from Chef::Provider

#current_resource, #new_resource, #node

Instance Method Summary collapse

Methods included from Mixin::Command

chdir_or_tmpdir, handle_command_failures, not_if, only_if, output_of_command, popen4, run_command, run_command_with_systems_locale

Methods inherited from Chef::Provider

#action_nothing, build_from_file, #initialize

Methods included from Mixin::ConvertToClassName

#convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string, #snake_case_basename

Methods included from Mixin::RecipeDefinitionDSLCore

#method_missing

Methods included from Mixin::Language

#data_bag, #data_bag_item, #platform?, #search, #value_for_platform

Constructor Details

This class inherits a constructor from Chef::Provider

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Chef::Mixin::RecipeDefinitionDSLCore

Instance Method Details

#action_assembleObject



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/chef/provider/mdadm.rb', line 58

def action_assemble
  unless @current_resource.exists
    command = "yes | mdadm --assemble #{@new_resource.raid_device} #{@new_resource.devices.collect{|x| x + " "}.to_s.chop}"
    Chef::Log.debug("mdadm command: #{command}")
    pid, stdin, stdout, stderr = popen4(command)
    Chef::Log.info("Assembled mdadm raid device (#{@new_resource.raid_device})")
    @new_resource.updated = true
  else
    Chef::Log.debug("mdadm raid device already exists (#{@new_resource.raid_device})")
  end
end

#action_createObject



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/chef/provider/mdadm.rb', line 46

def action_create
  unless @current_resource.exists
    command = "yes | mdadm --create #{@new_resource.raid_device} --chunk=#{@new_resource.chunk} --level #{@new_resource.level} --raid-devices #{@new_resource.devices.length} #{@new_resource.devices.collect{|x| x + " "}.to_s.chop}"
    Chef::Log.debug("mdadm command: #{command}")
    pid, stdin, stdout, stderr = popen4(command)
    Chef::Log.info("Created mdadm raid device (#{@new_resource.raid_device})")
    @new_resource.updated = true
  else
    Chef::Log.debug("mdadm raid device already exists (#{@new_resource.raid_device})")
  end
end

#action_stopObject



70
71
72
73
74
75
76
77
78
79
80
# File 'lib/chef/provider/mdadm.rb', line 70

def action_stop
  if @current_resource.exists
    command = "yes | mdadm --stop #{@new_resource.raid_device}"
    Chef::Log.debug("mdadm command: #{command}")
    pid, stdin, stdout, stderr = popen4(command)
    Chef::Log.info("Stopped mdadm raid device (#{@new_resource.raid_device})")
    @new_resource.updated = true
  else
    Chef::Log.debug("mdadm raid device doesn't exist (#{@new_resource.raid_device})")
  end
end

#load_current_resourceObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/chef/provider/mdadm.rb', line 29

def load_current_resource
  @current_resource = Chef::Resource::Mdadm.new(@new_resource.name)
  @current_resource.raid_device(@new_resource.raid_device)
  Chef::Log.debug("Checking for software raid device #{@current_resource.raid_device}")

  command = "mdadm --detail --scan"
  exists = false
  status = popen4(command) do |pid, stdin, stdout, stderr|
    stdout.each do |line|
      if line.include? @new_resource.raid_device
        exists = true
      end
    end
  end
  @current_resource.exists(exists)
end