Class: Chef::Provider::Mdadm

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

Instance Attribute Summary

Attributes inherited from Chef::Provider

#current_resource, #new_resource, #run_context

Instance Method Summary collapse

Methods included from Mixin::ShellOut

#shell_out, #shell_out!

Methods inherited from Chef::Provider

#action_nothing, build_from_file, #cookbook_name, #initialize, #node, #resource_collection

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



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/chef/provider/mdadm.rb', line 65

def action_assemble
  unless @current_resource.exists
    command = "yes | mdadm --assemble #{@new_resource.raid_device} #{@new_resource.devices.join(" ")}"
    Chef::Log.debug("mdadm command: #{command}")
    shell_out!(command)
    Chef::Log.info("Assembled mdadm raid device (#{@new_resource.raid_device})")
    @new_resource.updated_by_last_action(true)
  else
    Chef::Log.debug("mdadm raid device already exists, skipping assemble (#{@new_resource.raid_device})")
  end
end

#action_createObject



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/chef/provider/mdadm.rb', line 52

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.join(" ")}"
    Chef::Log.debug("mdadm command: #{command}")
    #pid, stdin, stdout, stderr = popen4(command)
    shell_out!(command)
    Chef::Log.info("Created mdadm raid device (#{@new_resource.raid_device})")
    @new_resource.updated_by_last_action(true)
  else
    Chef::Log.debug("mdadm raid device already exists, skipping create (#{@new_resource.raid_device})")
  end
end

#action_stopObject



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/chef/provider/mdadm.rb', line 77

def action_stop
  if @current_resource.exists
    command = "yes | mdadm --stop #{@new_resource.raid_device}"
    Chef::Log.debug("mdadm command: #{command}")
    shell_out!(command)
    Chef::Log.info("Stopped mdadm raid device (#{@new_resource.raid_device})")
    @new_resource.updated_by_last_action(true)
  else
    Chef::Log.debug("mdadm raid device doesn't exist (#{@new_resource.raid_device})")
  end
end

#load_current_resourceObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/chef/provider/mdadm.rb', line 34

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}")

  mdadm = shell_out!("mdadm --detail --scan")
  exists = mdadm.stdout.include?(@new_resource.raid_device)
  #exists = false
  # 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

#popen4Object

Raises:

  • (Exception)


30
31
32
# File 'lib/chef/provider/mdadm.rb', line 30

def popen4
  raise Exception, "deprecated, bitches"
end