Class: MDInspector
- Inherits:
-
Object
- Object
- MDInspector
- Defined in:
- lib/ec2-consistent-backup.rb
Overview
Cheap alternative to using FFI to interface with libdm
Constant Summary collapse
- MDFILE =
"/proc/mdstat"- PERSONALITIES =
"Personalities :"
Instance Attribute Summary collapse
-
#drives ⇒ Object
readonly
Returns the value of attribute drives.
-
#has_md ⇒ Object
readonly
Returns the value of attribute has_md.
-
#personalities ⇒ Object
readonly
Returns the value of attribute personalities.
Instance Method Summary collapse
-
#initialize(mdfile = MDFILE) ⇒ MDInspector
constructor
A new instance of MDInspector.
-
#set(name) ⇒ Object
Returns the information about the MD set @name.
Constructor Details
#initialize(mdfile = MDFILE) ⇒ MDInspector
Returns a new instance of MDInspector.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ec2-consistent-backup.rb', line 30 def initialize(mdfile = MDFILE) @has_md = false if File.exists?(mdfile) stat_data = File.open(mdfile).read.split(/\n/) personalities_line = stat_data.grep(/#{PERSONALITIES}/) if personalities_line =~ /#{PERSONALITIES}(.+)/ @personalities = $1 else @has_md = false end @set_metadata = {} stat_data.grep(/^md[0-9]+ : /).each do |md_info| if md_info =~ /^md([0-9]+) : active ([^ ]+) (.*)$/ set_name = "md#{$1}" personality = $2 drives = $3.split(/ /).map{ |i| "/dev/"+i.gsub(/\[[0-9]+\]/,'') }.to_a @set_metadata[set_name] = { :set_name=> set_name, :personality => personality, :drives => drives} end end @has_md = true if @set_metadata.keys.length > 0 end end |
Instance Attribute Details
#drives ⇒ Object (readonly)
Returns the value of attribute drives.
29 30 31 |
# File 'lib/ec2-consistent-backup.rb', line 29 def drives @drives end |
#has_md ⇒ Object (readonly)
Returns the value of attribute has_md.
28 29 30 |
# File 'lib/ec2-consistent-backup.rb', line 28 def has_md @has_md end |
#personalities ⇒ Object (readonly)
Returns the value of attribute personalities.
28 29 30 |
# File 'lib/ec2-consistent-backup.rb', line 28 def personalities @personalities end |
Instance Method Details
#set(name) ⇒ Object
Returns the information about the MD set @name
54 55 56 57 58 59 60 61 |
# File 'lib/ec2-consistent-backup.rb', line 54 def set(name) # Handle "/dev/foobar" instead of "foobar" if name =~ /\/dev\/(.*)$/ name = $1 end return @set_metadata[name] if @set_metadata.has_key?(name) raise NoSuchSetException.new(name) end |