Skip to content

Instantly share code, notes, and snippets.

@aaronbbrown
Created June 21, 2012 15:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronbbrown/2966320 to your computer and use it in GitHub Desktop.
Save aaronbbrown/2966320 to your computer and use it in GitHub Desktop.
get ec2 volumes from md device
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