Class: Tenderloin::Actions::VM::Import

Inherits:
Base
  • Object
show all
Defined in:
lib/tenderloin/actions/vm/import.rb

Instance Attribute Summary

Attributes inherited from Base

#run_args, #runner

Instance Method Summary collapse

Methods inherited from Base

#cleanup, #initialize, #prepare, #rescue

Methods included from Util

#error_and_exit, included, #logger, #wrap_output

Constructor Details

This class inherits a constructor from Tenderloin::Actions::Base

Instance Method Details

#execute!Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/tenderloin/actions/vm/import.rb', line 7

def execute!
  @runner.invoke_around_callback(:import) do
    Busy.busy do
      logger.info "Importing base VM (#{Tenderloin::Env.box.vmx_file})..."
      # Use the first argument passed to the action
      # @runner.vm = VirtualBox::VM.import(Tenderloin::Env.box.ovf_file)
      @runner.vm_id = (0...15).map{ ('a'..'z').to_a[rand(26)] }.join
      vmdir = File.join(Tenderloin::Env.vms_path, @runner.vm_id)

      FileUtils.mkdir_p(vmdir) unless Dir.exists?(vmdir)

      # Copy the VMX over
      FileUtils.cp(Tenderloin::Env.box.vmx_file, File.join(vmdir, @runner.vm_id + ".vmx"))

      # Copy all VMDK's over
      Dir.glob(File.join(File.dirname(Tenderloin::Env.box.vmx_file), "*.vmdk")) do |f|
        FileUtils.cp File.expand_path(f), vmdir
      end

    end
  end
end