Class: BoxGrinder::MultiDiskPlugin

Inherits:
BasePlugin
  • Object
show all
Defined in:
lib/multidisk-boxgrinder-plugin.rb

Instance Method Summary collapse

Instance Method Details

#after_initObject



8
9
10
11
12
13
14
15
16
# File 'lib/multidisk-boxgrinder-plugin.rb', line 8

def after_init
  register_deliverable(:vmdk_sparse => "#{@appliance_config.name}-sparse.vmdk")
  register_deliverable(:qcow_sparse => "#{@appliance_config.name}-sparse.qcow2")
  register_deliverable(:qcow_compressed => "#{@appliance_config.name}-compressed.qcow2")
  if !`which VBoxManage`.empty?
    register_deliverable(:vmdk_stream => "#{@appliance_config.name}-streamoptimized.vmdk")
    register_deliverable(:vhd => "#{@appliance_config.name}.vhd")
  end
end

#executeObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/multidisk-boxgrinder-plugin.rb', line 18

def execute
  @log.info "Converting RAW to multiple disk formats"

  @log.info "Converting to VMDK Sparse using qemu-img..."
  @exec_helper.execute "qemu-img convert -O vmdk '#{@previous_deliverables.disk}' '#{@deliverables.vmdk_sparse}'"

  @log.info "Converting to QCow2 Sparse using qemu-img..."
  @exec_helper.execute "qemu-img convert -O qcow2 '#{@previous_deliverables.disk}' '#{@deliverables.qcow_sparse}'"

  @log.info "Converting to QCow2 Compressed Sparse using qemu-img..."
  @exec_helper.execute "qemu-img convert -c -O qcow2 '#{@previous_deliverables.disk}' '#{@deliverables.qcow_compressed}'"

  if `which VBoxManage`.empty?
    @log.error "VBoxManage binary not found in your path, skipping VMDK Stream format."
  else
    @log.info "Using VBoxManage to convert the image..."
    @log.info "Converting to VMDK..."
    @exec_helper.execute "VBoxManage clonehd --format VMDK --variant Stream '#{@deliverables.vmdk_sparse}' '#{@deliverables.vmdk_stream}'"
    @log.info "Converting to VHD..."
    @exec_helper.execute "VBoxManage clonehd --format VHD '#{@deliverables.vmdk_sparse}' '#{@deliverables.vhd}'"
  end

  @log.info "Conversions done."
end