Class: VagrantPlugins::Dotvm::Injector::Machine

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-dotvm/injector/machine.rb

Constant Summary collapse

BOX_OPTIONS =
[
  :box,
  :hostname,
  :boot_timeout,
  :box_check_update,
  :box_version,
  :graceful_halt_timeout,
  :post_up_message,
  :box_download_checksum,
  :box_download_checksum_type,
  :box_download_client_cert,
  :box_download_ca_cert,
  :box_download_ca_path,
  :box_download_insecure,
  :box_download_location_trusted,
  :box_url,
  :communicator,
  :guest,
  :usable_port_range,
]

Class Method Summary collapse

Class Method Details

.inject(machine_cfg: nil, vc: nil) ⇒ Object



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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/vagrant-dotvm/injector/machine.rb', line 26

def self.inject(machine_cfg: nil, vc: nil)
  define_opts = {}
  define_opts[:primary]   = machine_cfg.primary   unless machine_cfg.primary.nil?
  define_opts[:autostart] = machine_cfg.autostart unless machine_cfg.autostart.nil?

  vc.vm.define machine_cfg.nick, **define_opts do |machine|
    BOX_OPTIONS.each do |opt|
      val = machine_cfg.send(opt)
      machine.vm.send("#{opt}=", val) unless val.nil?
    end

    machine.vm.provider "virtualbox" do |vb|
      vb.customize ["modifyvm", :id, "--memory",          machine_cfg.memory] unless machine_cfg.memory.nil?
      vb.customize ["modifyvm", :id, "--cpus",            machine_cfg.cpus]   unless machine_cfg.cpus.nil?
      vb.customize ["modifyvm", :id, "--cpuexecutioncap", machine_cfg.cpucap] unless machine_cfg.cpucap.nil?
      vb.customize ["modifyvm", :id, "--natnet1",         machine_cfg.natnet] unless machine_cfg.natnet.nil?

      machine_cfg.options[:virtualbox].each do |option|
        vb.customize ["modifyvm", :id, option.name, option.value]
      end
    end

    machine.vm.provider "vmware_fusion" do |vf|
      vf.vmx["memsize"]  = machine_cfg.memory unless machine_cfg.memory.nil?
      vf.vmz["numvcpus"] = machine_cfg.cpus   unless machine_cfg.cpus.nil?
    end

    machine_cfg.networks.each do |net|
      Network.inject net: net,
                     machine: machine
    end

    machine_cfg.routes.each do |route|
      Route.inject route: route,
                   machine: machine
    end

    machine_cfg.hosts.each do |host|
      Host.inject host: host,
               machine: machine
    end

    machine_cfg.provision.each do |provision|
      Provision.inject provision_cfg: provision,
                       machine: machine
    end

    machine_cfg.shared_folders.each do |folder|
      SharedFolder.inject folder: folder,
                          machine: machine
    end

    machine_cfg.authorized_keys.each do |key|
      AuthorizedKey.inject key: key,
                           machine: machine
    end

    if Vagrant.has_plugin?("vagrant-group")
      vc.group.groups = {} unless vc.group.groups.kind_of?(Hash)

      machine_cfg.groups.each do |group|
        vc.group.groups[group] = [] unless vc.group.groups.has_key?(group)
        vc.group.groups[group] << machine_cfg.nick
      end
    end
  end
end