Skip to content

Commit 0cacde9

Browse files
committed
Updating mdadm to 0.8, adding new_resource.updated
1 parent 17e0170 commit 0cacde9

6 files changed

Lines changed: 452 additions & 20 deletions

File tree

chef/lib/chef/platform.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,34 +45,39 @@ class Platform
4545
:package => Chef::Provider::Package::Apt,
4646
:service => Chef::Provider::Service::Debian,
4747
:cron => Chef::Provider::Cron,
48+
:mdadm => Chef::Provider::Mdadm
4849
}
4950
},
5051
:debian => {
5152
:default => {
5253
:package => Chef::Provider::Package::Apt,
5354
:service => Chef::Provider::Service::Debian,
5455
:cron => Chef::Provider::Cron,
56+
:mdadm => Chef::Provider::Mdadm
5557
}
5658
},
5759
:centos => {
5860
:default => {
5961
:service => Chef::Provider::Service::Redhat,
6062
:cron => Chef::Provider::Cron,
61-
:package => Chef::Provider::Package::Yum
63+
:package => Chef::Provider::Package::Yum,
64+
:mdadm => Chef::Provider::Mdadm
6265
}
6366
},
6467
:redhat => {
6568
:default => {
6669
:service => Chef::Provider::Service::Redhat,
6770
:cron => Chef::Provider::Cron,
68-
:package => Chef::Provider::Package::Yum
71+
:package => Chef::Provider::Package::Yum,
72+
:mdadm => Chef::Provider::Mdadm
6973
}
7074
},
7175
:gentoo => {
7276
:default => {
7377
:package => Chef::Provider::Package::Portage,
7478
:service => Chef::Provider::Service::Gentoo,
7579
:cron => Chef::Provider::Cron,
80+
:mdadm => Chef::Provider::Mdadm
7681
}
7782
},
7883
:solaris => {},

chef/lib/chef/provider/mdadm.rb

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#
2+
# Author:: Joe Williams (<joe@joetify.com>)
3+
# Copyright:: Copyright (c) 2009 Joe Williams
4+
# License:: Apache License, Version 2.0
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
19+
require 'chef/log'
20+
require 'chef/mixin/command'
21+
require 'chef/provider'
22+
23+
class Chef
24+
class Provider
25+
class Mdadm < Chef::Provider
26+
27+
include Chef::Mixin::Command
28+
29+
def initialize(node, new_resource)
30+
super(node, new_resource)
31+
end
32+
33+
def load_current_resource
34+
@current_resource = Chef::Resource::Mdadm.new(@new_resource.name)
35+
@current_resource.raid_device(@new_resource.raid_device)
36+
Chef::Log.debug("Checking for software raid device #{@current_resource.raid_device}")
37+
38+
command = "mdadm --detail --scan"
39+
exists = false
40+
status = popen4(command) do |pid, stdin, stdout, stderr|
41+
stdout.each do |line|
42+
if line.include? @new_resource.raid_device
43+
exists = true
44+
end
45+
end
46+
end
47+
@current_resource.exists(exists)
48+
end
49+
50+
def action_create
51+
unless @current_resource.exists
52+
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}"
53+
Chef::Log.debug("mdadm command: #{command}")
54+
pid, stdin, stdout, stderr = popen4(command)
55+
Chef::Log.info("Created mdadm raid device (#{@new_resource.raid_device})")
56+
@new_resource.updated = true
57+
else
58+
Chef::Log.debug("mdadm raid device already exists (#{@new_resource.raid_device})")
59+
end
60+
end
61+
62+
def action_assemble
63+
unless @current_resource.exists
64+
command = "yes | mdadm --assemble #{@new_resource.raid_device} #{@new_resource.devices.collect{|x| x + " "}.to_s.chop}"
65+
Chef::Log.debug("mdadm command: #{command}")
66+
pid, stdin, stdout, stderr = popen4(command)
67+
Chef::Log.info("Assembled mdadm raid device (#{@new_resource.raid_device})")
68+
@new_resource.updated = true
69+
else
70+
Chef::Log.debug("mdadm raid device already exists (#{@new_resource.raid_device})")
71+
end
72+
end
73+
74+
def action_stop
75+
if @current_resource.exists
76+
command = "yes | mdadm --stop #{@new_resource.raid_device}"
77+
Chef::Log.debug("mdadm command: #{command}")
78+
pid, stdin, stdout, stderr = popen4(command)
79+
Chef::Log.info("Stopped mdadm raid device (#{@new_resource.raid_device})")
80+
@new_resource.updated = true
81+
else
82+
Chef::Log.debug("mdadm raid device doesn't exist (#{@new_resource.raid_device})")
83+
end
84+
end
85+
86+
end
87+
end
88+
end

chef/lib/chef/resource/mdadm.rb

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#
2+
# Author:: Joe Williams (<joe@joetify.com>)
3+
# Copyright:: Copyright (c) 2009 Joe Williams
4+
# License:: Apache License, Version 2.0
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
19+
require 'chef/resource'
20+
21+
class Chef
22+
class Resource
23+
class Mdadm < Chef::Resource
24+
25+
def initialize(name, collection=nil, node=nil)
26+
super(name, collection, node)
27+
@resource_name = :mdadm
28+
29+
@chunk = 16
30+
@devices = []
31+
@exists = false
32+
@level = 1
33+
@raid_device = name
34+
35+
@action = :create
36+
@allowed_actions.push(:create, :assemble, :stop)
37+
end
38+
39+
def chunk(arg=nil)
40+
set_or_return(
41+
:chunk,
42+
arg,
43+
:kind_of => [ Integer ]
44+
)
45+
end
46+
47+
def devices(arg=nil)
48+
set_or_return(
49+
:devices,
50+
arg,
51+
:kind_of => [ Array ]
52+
)
53+
end
54+
55+
def exists(arg=nil)
56+
set_or_return(
57+
:exists,
58+
arg,
59+
:kind_of => [ TrueClass, FalseClass ]
60+
)
61+
end
62+
63+
def level(arg=nil)
64+
set_or_return(
65+
:level,
66+
arg,
67+
:kind_of => [ Integer ]
68+
)
69+
end
70+
71+
def raid_device(arg=nil)
72+
set_or_return(
73+
:raid_device,
74+
arg,
75+
:kind_of => [ String ]
76+
)
77+
end
78+
79+
80+
end
81+
end
82+
end

0 commit comments

Comments
 (0)