Class: VMMount

Inherits:
Object
  • Object
show all
Defined in:
lib/metadata/VMMount/VMMount.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, ost = nil) ⇒ VMMount

Returns a new instance of VMMount.



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
# File 'lib/metadata/VMMount/VMMount.rb', line 10

def initialize(filename, ost = nil)
  $log.debug "Initializing VMMount, filename: #{filename}" if $log
  @mountDrive = nil
  @diskInfo = OpenStruct.new
  @ost = OpenStruct.new unless ost
  @disk = nil
  @fs = nil

  # Use the MIQ functions to load virtual disk image
  # Check if there is a flat file and redirect to the proper name
  # TODO: This function should be improved to open the current file and check for the
  #       redirection.  Right now it just looks for the expected flat filename.
  $log.debug "vmmount called for disk image: [#{filename}]"
  @diskInfo.fileName = getMountFile(filename)

  @platMount = VMPlatformMount.new(@diskInfo, @ost)
  @platMount.preMount
  begin
    @disk = MiqDisk.getDisk(@diskInfo)
    raise "Failed to open disk: #{@diskInfo.fileName}" if @disk.nil?

    @parts = @disk.getPartitions
    raise "No Partitions found on disk: #{@diskInfo.fileName}" if @parts.nil?

    $log.debug "VMMount mounting partitions of #{filename}" if $log
    @parts.each do |p|
      fsPartitions = MiqFS.getFS(p)
      unless fsPartitions.nil?
        # Always set the fs pointer to the first partition so we return something.
        @fs = fsPartitions if @fs.nil?

        # If the systemRoot does not throw an error then we found it
        # and should return this fs.  Otherwise, continue looking.
        begin
          Win32::SystemPath.systemRoot(fsPartitions)
          @fs = fsPartitions
          break
        rescue
          # $log.warn "No Windows partition here."
        end
      end
    end
    $log.debug "vmmount complete for: [#{filename}]"
  rescue => err
    @platMount.postMount
    raise err
  end
end

Instance Attribute Details

#diskObject (readonly)

Returns the value of attribute disk.



8
9
10
# File 'lib/metadata/VMMount/VMMount.rb', line 8

def disk
  @disk
end

Instance Method Details

#getMountDriveObject



72
73
74
75
# File 'lib/metadata/VMMount/VMMount.rb', line 72

def getMountDrive
  return @fs if @fs
  @mountDrive
end

#getMountFile(fn) ⇒ Object



59
60
61
62
63
# File 'lib/metadata/VMMount/VMMount.rb', line 59

def getMountFile(fn)
  file_miq = File.join(File.dirname(fn), File.basename(fn, ".*") + ".miq")
  return file_miq if File.exist?(file_miq)
  fn
end

#mounted?Boolean

Returns:

  • (Boolean)


77
78
79
80
# File 'lib/metadata/VMMount/VMMount.rb', line 77

def mounted?
  return true unless getMountDrive.nil?
  false
end

#unMountImageObject



65
66
67
68
69
70
# File 'lib/metadata/VMMount/VMMount.rb', line 65

def unMountImage
  if @disk
    @disk.close
    @platMount.postMount
  end
end