Class: VagrantPlugins::Dotvm::ConfigInjecter

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

Class Method Summary collapse

Class Method Details

.inject(config, vc) ⇒ Object



5
6
7
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
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/vagrant-dotvm/configinjecter.rb', line 5

def self.inject(config, vc)
  config[:machines].each do |machine_cfg|
    vc.vm.define machine_cfg[:nick], primary: machine_cfg[:primary] do |machine|
      machine.vm.box      = machine_cfg[:box]
      machine.vm.hostname = machine_cfg[:name]

      machine.vm.provider "virtualbox" do |vb|
        vb.customize ['modifyvm', :id, '--memory', machine_cfg['memory'] ||= 1024]
        vb.customize ['modifyvm', :id, '--cpus',   machine_cfg['cpus']   ||= 1]
        vb.customize ['modifyvm', :id, '--cpuexecutioncap', machine_cfg['cpucap'] ||= 100]
      end

      machine_cfg[:networks].each do |net|
        if net[:net] == 'private_network'
          machine.vm.network net[:net], type: net[:type] ||= 'static', ip: net[:ip], netmask: net[:mask]
        end
      end

      machine_cfg[:provision].each do |provision|
        machine.vm.provision provision[:type] do |p|
          if provision[:type] == 'shell'
            p.path           = provision[:path]
            p.privileged     = provision[:privileged] ||= true
          elsif provision[:type] == 'file'
            p.source         = provision[:source]
            p.destination    = provision[:destination]
          elsif provision[:type] == 'puppet'
            p.module_path    = provision[:module_path]
            p.manifest_file  = provision[:manifest_file]
            p.manifests_path = provision[:manifests_path]
          end
        end
      end

      machine_cfg[:folders].each do |folder|
        machine.vm.synced_folder folder[:host], folder[:guest]
      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
end