Sha256: 945c28d4e7f8ba7bda76a335ed1ada1faf0aaccfaa61ebcb5e658d43ef51777b

Contents?: true

Size: 1.59 KB

Versions: 66

Compression:

Stored size: 1.59 KB

Contents

module RhevmDiskProbe
  DESC_MOD = "RhevmDescriptor"
  QCOW_MOD = "QcowDisk"
  RAW_MOD  = 'RawDisk'

  def self.probe(ostruct)
    return nil unless ostruct.fileName

    ext = File.extname(ostruct.fileName).downcase
    return nil unless ext.length.zero?

    format = ostruct.format.to_s.downcase
    return RAW_MOD  if format == 'raw'
    return QCOW_MOD if format == 'cow'

    descriptor_file = ostruct.fileName + '.meta'
    return nil unless File.exist?(descriptor_file)

    # If this ostruct already has a descriptor don't bother checking.
    # NOTE: If it does have a descriptor, we're coming from RhevmDescriptor.rb
    #       trying to open a disk - so don't regress infinitely.
    if ostruct.Descriptor.nil?
      # Get descriptor metadata
      f = File.open(descriptor_file, "r")
      descriptor = f.read; f.close
      if descriptor.include?('EOF')
        ostruct.Descriptor = descriptor
        desc = parseDescriptor(descriptor)
        return RAW_MOD if desc[:format].to_s.include?('RAW')
        return QCOW_MOD if desc[:format].to_s.include?('COW')
        return DESC_MOD
      end
    else
      desc = parseDescriptor(ostruct.Descriptor)
      return RAW_MOD  if desc[:format].to_s.include?('RAW')
      return QCOW_MOD if desc[:format].to_s.include?('COW')
    end
    nil
  end

  def self.parseDescriptor(descriptor)
    desc = {}
    descriptor.each_line do |line|
      line.strip!
      break if line == 'EOF'
      next unless line.include?('=')
      key, *value = line.split('=')
      desc[key.downcase.to_sym] = value = value.join('=')
    end
    desc
  end
end # module RhevmDiskProbe

Version data entries

66 entries across 66 versions & 1 rubygems

Version Path
manageiq-smartstate-0.10.1 lib/disk/modules/RhevmDiskProbe.rb
manageiq-smartstate-0.10.0 lib/disk/modules/RhevmDiskProbe.rb
manageiq-smartstate-0.9.0 lib/disk/modules/RhevmDiskProbe.rb
manageiq-smartstate-0.8.1 lib/disk/modules/RhevmDiskProbe.rb
manageiq-smartstate-0.8.0 lib/disk/modules/RhevmDiskProbe.rb
manageiq-smartstate-0.7.0 lib/disk/modules/RhevmDiskProbe.rb
manageiq-smartstate-0.6.2 lib/disk/modules/RhevmDiskProbe.rb
manageiq-smartstate-0.5.10 lib/disk/modules/RhevmDiskProbe.rb
manageiq-smartstate-0.3.10 lib/disk/modules/RhevmDiskProbe.rb
manageiq-smartstate-0.6.1 lib/disk/modules/RhevmDiskProbe.rb
manageiq-smartstate-0.3.9 lib/disk/modules/RhevmDiskProbe.rb
manageiq-smartstate-0.6.0 lib/disk/modules/RhevmDiskProbe.rb
manageiq-smartstate-0.5.9 lib/disk/modules/RhevmDiskProbe.rb
manageiq-smartstate-0.5.8 lib/disk/modules/RhevmDiskProbe.rb
manageiq-smartstate-0.3.8 lib/disk/modules/RhevmDiskProbe.rb
manageiq-smartstate-0.5.7 lib/disk/modules/RhevmDiskProbe.rb
manageiq-smartstate-0.3.7 lib/disk/modules/RhevmDiskProbe.rb
manageiq-smartstate-0.5.6 lib/disk/modules/RhevmDiskProbe.rb
manageiq-smartstate-0.3.6 lib/disk/modules/RhevmDiskProbe.rb
manageiq-smartstate-0.5.5 lib/disk/modules/RhevmDiskProbe.rb