Class: Lvm2MdParser

Inherits:
Object
  • Object
show all
Defined in:
lib/VolumeManager/LVM/parser.rb

Constant Summary collapse

HASH_START =
'{'
HASH_END =
'}'
ARRAY_START =
'['
ARRAY_END =
']'
STRING_START =
'"'
STRING_END =
'"'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mdStr, pvHdrs) ⇒ Lvm2MdParser

Returns a new instance of Lvm2MdParser.



13
14
15
16
17
# File 'lib/VolumeManager/LVM/parser.rb', line 13

def initialize(mdStr, pvHdrs)
  @pvHdrs = pvHdrs        # PV headers hashed by UUID
  @mda = mdStr.gsub(/#.*$/, "").gsub("[", "[ ").gsub("]", " ]").gsub('"', ' " ').delete("=,").gsub(/\s+/, " ").split(' ')
  @vgName = @mda.shift
end

Instance Attribute Details

#vgNameObject (readonly)

Returns the value of attribute vgName.



11
12
13
# File 'lib/VolumeManager/LVM/parser.rb', line 11

def vgName
  @vgName
end

Class Method Details

.dumpMetadata(md) ⇒ Object

def parse



27
28
29
30
31
32
33
34
35
# File 'lib/VolumeManager/LVM/parser.rb', line 27

def self.(md)
  level = 0
  md.lines do |line|
    line.strip!
    level -= 1 if line[0, 1] == HASH_END || line[0, 1] == ARRAY_END
    $log.debug((level > 0 ? "    " * level : "") + line)
    level += 1 if line[-1, 1] == HASH_START || line[-1, 1] == ARRAY_START
  end
end

Instance Method Details

#parseObject

def initialize



19
20
21
22
23
24
25
# File 'lib/VolumeManager/LVM/parser.rb', line 19

def parse
  vgHash = {}
  parseObj(vgHash, @vgName)
  vg = vgHash[@vgName]

  getVgObj(@vgName, vg)
end