-
-
Save thehar/1246307 to your computer and use it in GitHub Desktop.
aws_ebs_raid6 lwrp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
include Chef::Mixin::Command | |
action :create do | |
size = new_resource.size | |
volumes = new_resource.volumes.times.map{|i| (i == 0 ? "/dev/sdf" : "/dev/sdf#{i}") } | |
setra = new_resource.blockdev_setra | |
volume_group = new_resource.volume_group | |
logical_volume = new_resource.name | |
mdadm_device = new_resource.mdadm_device | |
mount_point = new_resource.mount_point | |
log "aws_ebs_raid6: setting up #{volumes.count}x #{size}G EBS volumes" | |
log "aws_ebs_raid6: VG: #{volume_group} LV: #{logical_volume} MP: #{mount_point}" | |
aws = data_bag_item("aws", node.app_environment) | |
volumes.map do |vol| | |
aws_ebs_volume "aws_ebs_raid6: #{vol} #{size}" do | |
aws_access_key aws['aws_access_key_id'] | |
aws_secret_access_key aws['aws_secret_access_key'] | |
size size | |
device vol | |
action [ :create, :attach ] | |
end | |
end | |
package "mdadm" | |
kernel_module "raid456" | |
mdadm mdadm_device do | |
devices volumes | |
level 6 | |
chunk new_resource.chunk | |
action [ :create, :assemble] | |
end | |
execute "LVM: Initialize physical disk '#{mdadm_device}'" do | |
command "pvcreate #{mdadm_device}" | |
not_if "pvdisplay #{mdadm_device}" | |
end | |
execute "LVM: Create volume group #{volume_group}" do | |
command "vgcreate #{volume_group} #{mdadm_device}" | |
not_if "vgdisplay #{volume_group}" | |
end | |
execute "LVM: Create #{logical_volume}" do | |
command "lvcreate -n #{logical_volume} -l 100%FREE #{volume_group}" | |
not_if "lvdisplay /dev/mapper/#{volume_group}-#{logical_volume}" | |
end | |
execute "XFS: Format /dev/mapper/#{volume_group}-#{logical_volume}" do | |
action :nothing | |
subscribes :run, resources(:execute => "LVM: Create #{logical_volume}"), :immediately | |
command "mkfs.xfs -d su=64k,sw=#{volumes.count - 2}" + | |
" /dev/mapper/#{volume_group}-#{logical_volume}" | |
end | |
execute "LVM: Expand #{logical_volume}" do | |
command "lvextend -l 100%FREE /dev/mapper/#{volume_group}-#{logical_volume}" | |
only_if do | |
status, | |
stdout, | |
stderr = output_of_command "lvs --nosuffix --noheadings -o size --units m " + | |
"/dev/mapper/#{volume_group}-#{logical_volume}", {} #lameo | |
raid6_efficiency = (1 - (2 / volumes.count.to_f)) | |
total_size = (size * volumes.count.to_f) | |
available_storage = stdout.strip.to_f | |
Chef::Log.debug "aws_ebs_raid6: expand check: " + | |
"#{available_storage} < #{total_size} * #{raid6_efficiency}: " + | |
"#{available_storage < total_size * raid6_efficiency}" | |
available_storage < total_size * raid6_efficiency | |
end | |
end | |
execute "XFS: Grow FS /dev/mapper/#{volume_group}-#{logical_volume}" do | |
action :nothing | |
subscribes :run, resources(:execute => "LVM: Expand #{logical_volume}"), :immediately | |
command "xfs_growfs /dev/mapper/#{volume_group}-#{logical_volume}" | |
end | |
directory mount_point do | |
recursive true | |
end | |
execute "blockdev --setra #{setra} /dev/mapper/#{volume_group}-#{logical_volume}" do | |
not_if "blockdev --getra /dev/mapper/#{volume_group}-#{logical_volume} | grep #{setra}" | |
end | |
mount mount_point do | |
device "/dev/mapper/#{volume_group}-#{logical_volume}" | |
fstype "xfs" | |
options "rw,noatime,inode64,nobarrier" | |
action [ :mount, :enable ] | |
end | |
log "aws_ebs_raid6: mount #{mount_point} now available" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
actions :create, :snapshot | |
attribute :size, :kind_of => Integer, :default => 100 | |
attribute :volumes, :kind_of => Integer, :default => 7 | |
attribute :chunk, :kind_of => Integer, :default => 64 | |
attribute :blockdev_setra, :kind_of => Integer, :default => 65536 | |
attribute :volume_group, :kind_of => String, :default => "ebs_raid6" | |
attribute :mdadm_device, :kind_of => String, :default => "/dev/md0" | |
attribute :mount_point, :kind_of => String, :default => "/mnt/raid6" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment