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