Fix version of box used in Vagrantfile
[icn.git] / Vagrantfile
1 # -*- mode: ruby -*-
2 # vi: set ft=ruby :
3
4 # IMPORTANT To bring up the machines, use the "--no-parallel" option
5 # to vagrant up.  This is to workaround dependencies between the jump
6 # machine and the machine pool machines.  Specifically, the pool
7 # machines will fail to come up until the baremetal network (created
8 # by vagrant from the jump machine definition) is up.
9
10 vars = {
11   :site => 'vm',
12   :baremetal_cidr => '192.168.151.0/24',
13   :num_machines => 2
14 }
15
16 $post_up_message = <<MSG
17 ------------------------------------------------------
18
19 To get started with ICN:
20
21   $ vagrant ssh jump
22   vagrant@jump:~$ sudo su
23   root@jump:/home/vagrant# cd /icn
24   root@jump:/home/vagrant# make install
25
26 ------------------------------------------------------
27 MSG
28
29 #
30 # Networks
31 #
32 # The ICN baremetal network will be the vagrant management network.
33 # It is created automatically by vagrant.  The provisioning network
34 # will be a vagrant private network, and is required to be created by
35 # this script.  The IPMI network is created with virtualbmc.
36
37 #
38 # Machines
39 #
40 Vagrant.configure("2") do |config|
41   # The jump machine
42   config.vm.define 'jump' do |m|
43     # Note the apparent typo in the name below, it is correct as-is
44     m.vm.box = 'intergratedcloudnative/ubuntu1804'
45     m.vm.box_version = '1.0.0'
46     m.vm.hostname = 'jump'
47     m.vm.synced_folder '.', '/icn'
48     m.vm.provider :libvirt do |libvirt|
49       libvirt.graphics_ip = '0.0.0.0'
50       libvirt.default_prefix = "#{vars[:site]}-"
51       libvirt.cpu_mode = 'host-passthrough'
52       libvirt.cpus = 8
53       libvirt.memory = 24576
54       libvirt.nested = true
55
56       # The ICN baremetal network is the vagrant management network,
57       # and is created by vagrant for us
58       libvirt.management_network_name = "#{vars[:site]}-baremetal"
59       libvirt.management_network_address = vars[:baremetal_cidr]
60       libvirt.management_network_autostart = true
61     end
62
63     # The ICN provisioning network will be a vagrant private network
64     # created upon bringing up the jump machine
65     m.trigger.before [:up] do |trigger|
66       trigger.name = 'Creating provisioning network'
67       trigger.run = {inline: "./tools/vagrant/create_provisioning_network.sh #{vars[:site]}"}
68     end
69     m.trigger.after [:destroy] do |trigger|
70       trigger.name = 'Destroying provisioning network'
71       trigger.run = {inline: "./tools/vagrant/destroy_provisioning_network.sh #{vars[:site]}"}
72     end
73     m.vm.network :private_network,
74                  :libvirt__network_name => "#{vars[:site]}-provisioning",
75                  :type => 'dhcp'
76
77     # IPMI control of machines is provided by vbmc on the host
78     m.trigger.after [:up] do |trigger|
79       trigger.name = 'Starting virtualbmc for IPMI network'
80       trigger.run = {inline: "./tools/vagrant/start_vbmc.sh"}
81     end
82     m.trigger.after [:destroy] do |trigger|
83       trigger.name = 'Stopping virtualbmc for IPMI network'
84       trigger.run = {inline: "./tools/vagrant/stop_vbmc.sh"}
85     end
86
87     m.trigger.after [:up] do |trigger|
88       trigger.name = 'Creating ICN user_config.sh'
89       trigger.run = {inline: "./tools/vagrant/create_user_config.sh"}
90     end
91     m.vm.provision 'Configuring ICN prerequisites', type: 'shell', privileged: true, inline: <<-SHELL
92       ssh-keygen -f "${HOME}/.ssh/id_rsa" -P "" <<<y
93       DEBIAN_FRONTEND=noninteractive apt-get install -y make
94     SHELL
95     m.vm.post_up_message = $post_up_message
96   end
97
98   # The machine pool used by cluster creation
99   (1..vars[:num_machines]).each do |i|
100     config.vm.define "machine-#{i}" do |m|
101       m.vm.hostname = "machine-#{i}"
102       m.vm.provider :libvirt do |libvirt|
103         libvirt.graphics_ip = '0.0.0.0'
104         libvirt.default_prefix = "#{vars[:site]}-"
105         libvirt.cpu_mode = 'host-passthrough'
106         libvirt.cpus = 8
107         libvirt.memory = 16384
108         libvirt.nested = true
109         # The image will be provisioned by ICN so just create an empty
110         # disk for the machine
111         libvirt.storage :file, :size => 50, :type => 'raw', :cache => 'none'
112         # Management attach is false so that vagrant will not interfere
113         # with these machines: the jump server will manage them
114         # completely
115         libvirt.mgmt_attach = false
116       end
117       # The provisioning network must be listed first for PXE boot to
118       # the metal3/ironic provided image
119       m.vm.network :private_network,
120                    :libvirt__network_name => "#{vars[:site]}-provisioning",
121                    :type => 'dhcp'
122       m.vm.network :private_network,
123                    :libvirt__network_name => "#{vars[:site]}-baremetal",
124                    :type => 'dhcp'
125
126       # IPMI control
127       m.trigger.after [:up] do |trigger|
128         trigger.name = 'Adding machine to IPMI network'
129         trigger.run = {inline: "./tools/vagrant/add_machine_to_vbmc.sh #{i} #{vars[:site]} machine-#{i}"}
130       end
131       m.trigger.after [:destroy] do |trigger|
132         trigger.name = 'Removing machine from IPMI network'
133         trigger.run = {inline: "./tools/vagrant/remove_machine_from_vbmc.sh #{i} #{vars[:site]} machine-#{i}"}
134       end
135
136       # Create configuration for ICN provisioning
137       m.trigger.after [:up] do |trigger|
138         if i == vars[:num_machines] then
139           trigger.info = 'Creating nodes.json.sample describing the machines'
140           trigger.run = {inline: "./tools/vagrant/create_nodes_json_sample.sh #{vars[:num_machines]} #{vars[:site]} machine-"}
141         end
142       end
143       m.trigger.after [:up] do |trigger|
144         if i == vars[:num_machines] then
145           trigger.info = 'Creating Provisioning resource describing the cluster'
146           trigger.run = {inline: "./tools/vagrant/create_provisioning_cr.sh #{vars[:num_machines]} #{vars[:site]} machine-"}
147         end
148       end
149     end
150   end
151 end