Class: VagrantPlugins::PackageVMware::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-package-vmware/command.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.synopsisObject



4
5
6
# File 'lib/vagrant-package-vmware/command.rb', line 4

def self.synopsis
  "packages a running VMware vagrant environment into a box"
end

Instance Method Details

#executeObject



8
9
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
# File 'lib/vagrant-package-vmware/command.rb', line 8

def execute
  options = {}
  options[:tty] = true

  opts = OptionParser.new do |o|
    o.banner = "Usage: vagrant package-vmware [options] [name]"
    o.separator ""
    o.separator "Options:"
    o.separator ""

    o.on("--output NAME", "Name of the file to output") do |output|
      options[:output] = output
    end

    o.on("--include FILE,FILE..", Array, "Comma separated additional files to package with the box") do |i|
      options[:include] = i
    end

    o.on("--vagrantfile FILE", "Vagrantfile to package with the box") do |v|
      options[:vagrantfile] = v
    end
  end

  # Parse the options
  argv = parse_options(opts)
  return if !argv

  @logger.debug("package options: #{options.inspect}")

  package_target(argv[0], options)

  # Success, exit status 0
  0
end

#package_target(name, options) ⇒ Object



43
44
45
46
47
48
# File 'lib/vagrant-package-vmware/command.rb', line 43

def package_target(name, options)
  with_target_vms(name, single_target: true) do |vm|
    @logger.debug("Packaging VM: #{vm.name}")
    package_vm(vm, options)
  end
end

#package_vm(vm, options) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/vagrant-package-vmware/command.rb', line 50

def package_vm(vm, options)
  require_relative 'action'

  opts = options.inject({}) do |acc, data|
    k,v = data
    acc["package.#{k}"] = v
    acc
  end
  opts[:machine] = vm

  @env.action_runner.run(VagrantPlugins::PackageVMware::Action.action_package_vmware, opts)
end