Class: MiqNativeVolumeManager

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(vmCfg, _ost = nil) ⇒ MiqNativeVolumeManager

Returns a new instance of MiqNativeVolumeManager.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/VolumeManager/MiqNativeVolumeManager.rb', line 10

def initialize(vmCfg, _ost = nil)
  @logicalVolumes     = []         # visible logical volumes
  @physicalVolumes    = []         # visible physical volumes
  @hiddenVolumes      = []         # hidded volumes (in volume groups)
  @allPhysicalVolumes = []         # all physical volumes
  @wholeDisks         = []         # a list of open base disks
  @visibleVolumes   = nil       # logical and physical volumes that should eb checked for filesystems
  @vgHash             = {}          # volume groups hashed by name
  @lvHash             = {}
  @rootTrees          = nil               # the MiqMountManager objects using this MiqVolumeManager object

  @diskFileNames = vmCfg.getDiskFileHash

  `vgdisplay -c 2> /dev/null`.each { |vgl| vg = getVg(vgl); @vgHash[vg.vgName] = vg }
  `lvdisplay -c 2> /dev/null`.each { |lvl| lv = getLv(lvl); @lvHash[lv.lvPath] = lv }

  vgNames     = @vgHash.keys
  lvNames     = @lvHash.keys
  hiddenDevNames  = `pvdisplay -c 2> /dev/null`.split("\n").collect! { |p| p.lstrip.split(":", 2)[0] }

  if $log.debug?
    $log.debug "\nVolume Groups: (#{vgNames.class}: #{vgNames.length})"
    vgNames.each { |dn| $log.debug "\t#{dn}" }
    $log.debug "\nLogical Volumes: (#{lvNames.class}: #{lvNames.length})"
    lvNames.each { |dn| $log.debug "\t#{dn}" }
    $log.debug "\nHidden devs: (#{hiddenDevNames.class}: #{hiddenDevNames.length})"
  end

  physVolumes = openPhysicalVolumes(@diskFileNames)

  $log.debug "\nMiqNativeVolumeManager: physVolumes:" if $log.debug?
  physVolumes.each do |pv|
    if $log.debug?
      $log.debug "\t#{pv.devFile} => #{pv.dInfo.hardwareId} (SIG: #{pv.dInfo.diskSig})"
      $log.debug "\t\tPartition: #{pv.partNum}, Type: #{pv.partType}"
    end
    if hiddenDevNames.include?(pv.devFile)
      $log.debug "\t\t\tHIDDEN VOLUME" if $log.debug?
      hiddenVolumes << pv
    else
      @physicalVolumes << pv
    end
    @allPhysicalVolumes << pv
  end

  vgNames.each { |vgn| `vgchange -a y #{vgn}` }

  @logicalVolumes = openLogicalVolumes(lvNames)
  @visibleVolumes = @logicalVolumes + @physicalVolumes
end

Instance Attribute Details

#allPhysicalVolumesObject (readonly)

Returns the value of attribute allPhysicalVolumes.



8
9
10
# File 'lib/VolumeManager/MiqNativeVolumeManager.rb', line 8

def allPhysicalVolumes
  @allPhysicalVolumes
end

#diskInitErrorsObject (readonly)

Returns the value of attribute diskInitErrors.



8
9
10
# File 'lib/VolumeManager/MiqNativeVolumeManager.rb', line 8

def diskInitErrors
  @diskInitErrors
end

#hiddenVolumesObject (readonly)

Returns the value of attribute hiddenVolumes.



8
9
10
# File 'lib/VolumeManager/MiqNativeVolumeManager.rb', line 8

def hiddenVolumes
  @hiddenVolumes
end

#logicalVolumesObject (readonly)

Returns the value of attribute logicalVolumes.



8
9
10
# File 'lib/VolumeManager/MiqNativeVolumeManager.rb', line 8

def logicalVolumes
  @logicalVolumes
end

#physicalVolumesObject (readonly)

Returns the value of attribute physicalVolumes.



8
9
10
# File 'lib/VolumeManager/MiqNativeVolumeManager.rb', line 8

def physicalVolumes
  @physicalVolumes
end

#rootTreesObject

Returns the value of attribute rootTrees.



7
8
9
# File 'lib/VolumeManager/MiqNativeVolumeManager.rb', line 7

def rootTrees
  @rootTrees
end

#vgHashObject (readonly)

Returns the value of attribute vgHash.



8
9
10
# File 'lib/VolumeManager/MiqNativeVolumeManager.rb', line 8

def vgHash
  @vgHash
end

#visibleVolumesObject (readonly)

Returns the value of attribute visibleVolumes.



8
9
10
# File 'lib/VolumeManager/MiqNativeVolumeManager.rb', line 8

def visibleVolumes
  @visibleVolumes
end

#wholeDisksObject (readonly)

Returns the value of attribute wholeDisks.



8
9
10
# File 'lib/VolumeManager/MiqNativeVolumeManager.rb', line 8

def wholeDisks
  @wholeDisks
end

Instance Method Details

#closeAllObject



61
62
63
64
65
66
67
68
69
70
# File 'lib/VolumeManager/MiqNativeVolumeManager.rb', line 61

def closeAll
  @wholeDisks.each(&:close)
  @logicalVolumes     = []
  @physicalVolumes    = []
  @hiddenVolumes      = []
  @wholeDisks         = []
  @vgHash             = nil
  @ost.miqVim.closeVdlConnection(@vdlConnection) if @vdlConnection
  @volMgrPS.postMount
end

#getLv(lvl) ⇒ Object



138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/VolumeManager/MiqNativeVolumeManager.rb', line 138

def getLv(lvl)
  lva = lvl.lstrip.split(":")
  lvPath = lva[0]
  vgName = lva[1]
  lvId   = `lvdisplay -v #{lvPath} 2> /dev/null | grep "LV UUID"`.split(" ").last
  lv  = LogicalVolume.new(lvId, File.basename(lvPath))

  vg = @vgHash[vgName]
  lv.vgObj  = vg
  lv.lvPath = lvPath
  vg.logicalVolumes[lv.lvName] = lv
end

#getVg(vgl) ⇒ Object

def openPhysicalVolumes



133
134
135
136
# File 'lib/VolumeManager/MiqNativeVolumeManager.rb', line 133

def getVg(vgl)
  vga = vgl.lstrip.split(":")
  (VolumeGroup.new(vga[16], vga[0]))
end

#openLogicalVolumes(lvnames) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/VolumeManager/MiqNativeVolumeManager.rb', line 72

def openLogicalVolumes(lvnames)
  lvList = []
  lvnames.each do |lvn|
    #
    # get MiqDisk object for each LV and add to lvList.
    #
    dInfo = OpenStruct.new
    dInfo.localDev = lvn
    dInfo.lvObj = @lvHash[lvn]
    dInfo.hardwareId = ""
    lvList << MiqDisk.getDisk(dInfo)
  end
  lvList
end

#openPhysicalVolumes(diskFiles) ⇒ Object

def openLogicalVolumes



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/VolumeManager/MiqNativeVolumeManager.rb', line 87

def openPhysicalVolumes(diskFiles)
  pVolumes = []

  $log.debug "openPhysicalVolumes: no disk files supplied." unless diskFiles

  #
  # Build a list of the VM's physical volumes.
  #
  diskFiles.each do |dtag, df|
    $log.debug "openPhysicalVolumes: processing disk file (#{dtag}): #{df}"
    dInfo = OpenStruct.new
    dInfo.localDev = df
    dInfo.hardwareId = dtag

    begin
      d = MiqDisk.getDisk(dInfo)
      # I am not sure if getting a nil handle back should throw an error or not.
      # For now I am just skipping to the next disk.  (GMM)
      next if d.nil?
    rescue => err
      $log.error "Couldn't open disk file: #{df}"
      $log.error err.to_s
      $log.debug err.backtrace.join("\n")
      @diskInitErrors[df] = err.to_s
      next
    end

    @wholeDisks << d
    p = d.getPartitions
    if p.empty?
      #
      # If the disk has no partitions, the whole disk can be a single volume.
      #
      pVolumes << d
    else
      #
      # If the disk is partitioned, the partitions are physical volumes,
      # but not the whild disk.
      #
      pVolumes.concat(p)
    end
  end

  pVolumes
end