7 # IMPORTANT To bring up the machines, use the "--no-parallel" option
8 # to vagrant up. This is to workaround dependencies between the jump
9 # machine and the machine pool machines. Specifically, the pool
10 # machines will fail to come up until the baremetal network (created
11 # by vagrant from the jump machine definition) is up.
13 site = ENV['ICN_SITE'] || 'vm'
15 # Calculate the baremetal network address from the bmcAddress (aka
16 # IPMI address) specified in the machine pool values. IPMI in the
17 # virtual environment is emulated by virtualbmc listening on the host.
19 Dir.glob("deploy/site/#{site}/*.yaml") do |file|
20 YAML.load_stream(File.read(file)) do |document|
21 values = document.fetch('spec', {}).fetch('values', {})
22 next if values['machineName'].nil? || values['bootMACAddress'].nil?
23 bmc_host = URI.parse(values['bmcAddress']).host
24 baremetal_cidr = "#{IPAddr.new(bmc_host).mask(24)}/24"
27 if baremetal_cidr.nil?
28 puts "Missing bmcAddress value in site definition, can't determine baremetal network address"
32 $post_up_message = <<MSG
33 ------------------------------------------------------
35 To get started with ICN:
38 vagrant@jump:~$ sudo su
39 root@jump:/home/vagrant# cd /icn
40 root@jump:/icn# make jump_server
41 root@jump:/icn# make vm_cluster
43 ------------------------------------------------------
49 # The ICN baremetal network will be the vagrant management network.
50 # It is created automatically by vagrant. The provisioning network
51 # will be a vagrant private network, and is required to be created by
52 # this script. The IPMI network is created with virtualbmc.
57 Vagrant.configure("2") do |config|
59 config.vm.define 'jump' do |m|
60 # Note the apparent typo in the name below, it is correct as-is
61 m.vm.box = 'intergratedcloudnative/ubuntu2004'
62 m.vm.hostname = 'jump'
63 m.vm.synced_folder '.', '/icn'
64 m.vm.provider :libvirt do |libvirt|
65 libvirt.graphics_ip = '0.0.0.0'
66 libvirt.default_prefix = "#{site}-"
67 libvirt.cpu_mode = 'host-passthrough'
69 libvirt.memory = 24576
72 # The ICN baremetal network is the vagrant management network,
73 # and is created by vagrant for us
74 libvirt.management_network_name = "#{site}-baremetal"
75 libvirt.management_network_address = baremetal_cidr
76 libvirt.management_network_autostart = true
79 # The ICN provisioning network will be a vagrant private network
80 # created upon bringing up the jump machine
81 m.trigger.before [:up] do |trigger|
82 trigger.name = 'Creating provisioning network'
83 trigger.run = {inline: "./tools/vagrant/create_provisioning_network.sh #{site}"}
85 m.trigger.after [:destroy] do |trigger|
86 trigger.name = 'Destroying provisioning network'
87 trigger.run = {inline: "./tools/vagrant/destroy_provisioning_network.sh #{site}"}
89 m.vm.network :private_network,
90 :libvirt__network_name => "#{site}-provisioning",
93 # IPMI control of machines is provided by vbmc on the host
94 m.trigger.after [:up] do |trigger|
95 trigger.name = 'Starting virtualbmc for IPMI network'
96 trigger.run = {inline: "./tools/vagrant/start_vbmc.sh"}
98 m.trigger.after [:destroy] do |trigger|
99 trigger.name = 'Stopping virtualbmc for IPMI network'
100 trigger.run = {inline: "./tools/vagrant/stop_vbmc.sh"}
103 m.trigger.after [:up] do |trigger|
104 trigger.name = 'Creating ICN user_config.sh'
105 trigger.run = {inline: "./tools/vagrant/create_user_config.sh"}
107 m.vm.provision 'Configuring ICN prerequisites', type: 'shell', privileged: true, inline: <<-SHELL
108 ssh-keygen -f "${HOME}/.ssh/id_rsa" -P "" <<<y
109 DEBIAN_FRONTEND=noninteractive apt-get install -y make
111 m.vm.post_up_message = $post_up_message
114 # Look for any HelmReleases in the site directory with machineName in
115 # the values dictionary. This will provide the values needed to
116 # create the machine pool.
117 legacy_machine_args = ""
118 Dir.glob("deploy/site/#{site}/*.yaml") do |file|
119 YAML.load_stream(File.read(file)) do |document|
120 values = document.fetch('spec', {}).fetch('values', {})
121 next if values['machineName'].nil? || values['bootMACAddress'].nil?
122 machine_name = values['machineName']
123 boot_mac_address = values['bootMACAddress']
124 bmc_port = URI.parse(values['bmcAddress']).port
125 config.vm.define machine_name do |m|
126 m.vm.hostname = machine_name
127 m.vm.provider :libvirt do |libvirt|
128 libvirt.graphics_ip = '0.0.0.0'
129 libvirt.default_prefix = "#{site}-"
130 libvirt.cpu_mode = 'host-passthrough'
132 libvirt.memory = 16384
133 libvirt.nested = true
134 # The image will be provisioned by ICN so just create an empty
135 # disk for the machine
136 libvirt.storage :file, :size => 50, :type => 'raw', :cache => 'none'
137 # Management attach is false so that vagrant will not interfere
138 # with these machines: the jump server will manage them
140 libvirt.mgmt_attach = false
142 # The provisioning network must be listed first for PXE boot to
143 # the metal3/ironic provided image
144 m.vm.network :private_network,
145 :libvirt__network_name => "#{site}-provisioning",
146 :mac => boot_mac_address,
148 m.vm.network :private_network,
149 :libvirt__network_name => "#{site}-baremetal",
153 m.trigger.after [:up] do |trigger|
154 trigger.name = 'Adding machine to IPMI network'
155 trigger.run = {inline: "./tools/vagrant/add_machine_to_vbmc.sh #{site} #{machine_name} #{bmc_port}"}
157 m.trigger.after [:destroy] do |trigger|
158 trigger.name = 'Removing machine from IPMI network'
159 trigger.run = {inline: "./tools/vagrant/remove_machine_from_vbmc.sh #{site} #{machine_name} #{bmc_port}"}
162 # Create configuration for ICN provisioning
163 legacy_machine_args = "#{legacy_machine_args} #{machine_name} #{bmc_port}"
164 m.trigger.after [:up] do |trigger|
165 trigger.info = 'Creating nodes.json.sample describing the machines'
166 trigger.run = {inline: "./tools/vagrant/create_nodes_json_sample.sh #{site} #{legacy_machine_args}"}
168 m.trigger.after [:up] do |trigger|
169 trigger.info = 'Creating Provisioning resource describing the cluster'
170 trigger.run = {inline: "./tools/vagrant/create_provisioning_cr.sh #{site} #{legacy_machine_args}"}