Created
June 21, 2012 15:12
-
-
Save aaronbbrown/2966320 to your computer and use it in GitHub Desktop.
get ec2 volumes from md device
This file contains hidden or 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
def get_volumes (mount = nil) | |
return [] unless @ec2_instance_id | |
mount ||= @datadir | |
vols = [] | |
devs = get_devs(mount) | |
instance = @ec2.instances[@ec2_instance_id] | |
vols = instance.block_device_mappings.map { |dev,attach| attach.volume.id if devs.include?(dev) }.compact | |
return vols | |
end | |
# connect to the remote host via ssh and get the underlying device names | |
# return array of device names | |
def get_devs (mount) | |
@ssh || ssh_start | |
output = @ssh.exec!("mount").grep(/#{mount}/) | |
dev = output.first.split(/\s+/)[0] | |
if dev =~ /^\/dev\/md/ | |
# it is a RAID device, get the mapping from /proc/mdstat | |
output = @ssh.exec!("cat /proc/mdstat | grep #{dev.split(/\//)[2]}") | |
return output.scan(/(\D{3}\d+)\[\d+\]\s*/).map{ |x| "/dev/#{x}" } | |
else | |
return [dev] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment