Module: VagrantPlugins::Dotvm::Injector::Machine

Extended by:
AbstractInjector
Defined in:
lib/vagrant-dotvm/injector/machine.rb

Overview

Injects DotVm machine configuration into Vagrant

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

Methods included from AbstractInjector

generate_hash, rewrite_options

Class Method Details

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



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/vagrant-dotvm/injector/machine.rb', line 83

def 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|
    inject_options machine_cfg, machine
    inject_vbox machine_cfg, machine
    inject_vmware machine_cfg, vc
    inject_groups machine_cfg, vc

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

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

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

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

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

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

.inject_groups(machine_cfg, vc) ⇒ Object



72
73
74
75
76
77
78
79
80
81
# File 'lib/vagrant-dotvm/injector/machine.rb', line 72

def inject_groups(machine_cfg, vc)
  return false unless Vagrant.has_plugin?('vagrant-group')

  vc.group.groups = {} unless vc.group.groups.is_a?(Hash)

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

.inject_options(machine_cfg, machine) ⇒ Object



31
32
33
34
35
36
# File 'lib/vagrant-dotvm/injector/machine.rb', line 31

def inject_options(machine_cfg, machine)
  BOX_OPTIONS.each do |opt|
    val = machine_cfg.send(opt)
    machine.vm.send("#{opt}=", val) unless val.nil?
  end
end

.inject_vbox(machine_cfg, machine) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/vagrant-dotvm/injector/machine.rb', line 38

def inject_vbox(machine_cfg, machine)
  mapping = [
    ['--memory', :memory],
    ['--cpus', :cpus],
    ['--cpuexecutioncap', :cpucap],
    ['--natnet1', :natnet]
  ]

  machine.vm.provider 'virtualbox' do |vb|
    mapping.each do |item|
      value = machine_cfg.send(item[1])
      vb.customize ['modifyvm', :id, item[0], value] unless value.nil?
    end

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

.inject_vmware(machine_cfg, machine) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/vagrant-dotvm/injector/machine.rb', line 58

def inject_vmware(machine_cfg, machine)
  mapping = [
    ['memsize', :memory],
    ['numvcpus', :cpus]
  ]

  machine.vm.provider 'vmware_fusion' do |vf|
    mapping.each do |item|
      value = machine_cfg.send(item[1])
      vf.vmx[item[1]] = value unless value.nil?
    end
  end
end