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

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

Methods included from Mixin::ConvertToClassName

#convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string

Methods included from Mixin::RecipeDefinitionDSLCore

#method_missing

Methods included from Mixin::Language

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

Constructor Details

#initialize(node, new_resource) ⇒ Mdadm

Returns a new instance of Mdadm.



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

def initialize(node, new_resource)
  super(node, new_resource)
end

Dynamic Method Handling

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

Instance Method Details

#action_assembleObject



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/chef/provider/mdadm.rb', line 62

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



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

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



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/chef/provider/mdadm.rb', line 74

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



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

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