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/ubuntu1804'
62 m.vm.box_version = '1.0.0'
63 m.vm.hostname = 'jump'
64 m.vm.synced_folder '.', '/icn'
65 m.vm.provider :libvirt do |libvirt|
66 libvirt.graphics_ip = '0.0.0.0'
67 libvirt.default_prefix = "#{site}-"
68 libvirt.cpu_mode = 'host-passthrough'
70 libvirt.memory = 24576
73 # The ICN baremetal network is the vagrant management network,
74 # and is created by vagrant for us
75 libvirt.management_network_name = "#{site}-baremetal"
76 libvirt.management_network_address = baremetal_cidr
77 libvirt.management_network_autostart = true
80 # The ICN provisioning network will be a vagrant private network
81 # created upon bringing up the jump machine
82 m.trigger.before [:up] do |trigger|
83 trigger.name = 'Creating provisioning network'
84 trigger.run = {inline: "./tools/vagrant/create_provisioning_network.sh #{site}"}
86 m.trigger.after [:destroy] do |trigger|
87 trigger.name = 'Destroying provisioning network'
88 trigger.run = {inline: "./tools/vagrant/destroy_provisioning_network.sh #{site}"}
90 m.vm.network :private_network,
91 :libvirt__network_name => "#{site}-provisioning",
94 # IPMI control of machines is provided by vbmc on the host
95 m.trigger.after [:up] do |trigger|
96 trigger.name = 'Starting virtualbmc for IPMI network'
97 trigger.run = {inline: "./tools/vagrant/start_vbmc.sh"}
99 m.trigger.after [:destroy] do |trigger|
100 trigger.name = 'Stopping virtualbmc for IPMI network'
101 trigger.run = {inline: "./tools/vagrant/stop_vbmc.sh"}
104 m.trigger.after [:up] do |trigger|
105 trigger.name = 'Creating ICN user_config.sh'
106 trigger.run = {inline: "./tools/vagrant/create_user_config.sh"}
108 m.vm.provision 'Configuring ICN prerequisites', type: 'shell', privileged: true, inline: <<-SHELL
109 ssh-keygen -f "${HOME}/.ssh/id_rsa" -P "" <<<y
110 DEBIAN_FRONTEND=noninteractive apt-get install -y make
112 m.vm.post_up_message = $post_up_message
115 # Look for any HelmReleases in the site directory with machineName in
116 # the values dictionary. This will provide the values needed to
117 # create the machine pool.
118 legacy_machine_args = ""
119 Dir.glob("deploy/site/#{site}/*.yaml") do |file|
120 YAML.load_stream(File.read(file)) do |document|
121 values = document.fetch('spec', {}).fetch('values', {})
122 next if values['machineName'].nil? || values['bootMACAddress'].nil?
123 machine_name = values['machineName']
124 boot_mac_address = values['bootMACAddress']
125 bmc_port = URI.parse(values['bmcAddress']).port
126 config.vm.define machine_name do |m|
127 m.vm.hostname = machine_name
128 m.vm.provider :libvirt do |libvirt|
129 libvirt.graphics_ip = '0.0.0.0'
130 libvirt.default_prefix = "#{site}-"
131 libvirt.cpu_mode = 'host-passthrough'
133 libvirt.memory = 16384
134 libvirt.nested = true
135 # The image will be provisioned by ICN so just create an empty
136 # disk for the machine
137 libvirt.storage :file, :size => 50, :type => 'raw', :cache => 'none'
138 # Management attach is false so that vagrant will not interfere
139 # with these machines: the jump server will manage them
141 libvirt.mgmt_attach = false
143 # The provisioning network must be listed first for PXE boot to
144 # the metal3/ironic provided image
145 m.vm.network :private_network,
146 :libvirt__network_name => "#{site}-provisioning",
147 :mac => boot_mac_address,
149 m.vm.network :private_network,
150 :libvirt__network_name => "#{site}-baremetal",
154 m.trigger.after [:up] do |trigger|
155 trigger.name = 'Adding machine to IPMI network'
156 trigger.run = {inline: "./tools/vagrant/add_machine_to_vbmc.sh #{site} #{machine_name} #{bmc_port}"}
158 m.trigger.after [:destroy] do |trigger|
159 trigger.name = 'Removing machine from IPMI network'
160 trigger.run = {inline: "./tools/vagrant/remove_machine_from_vbmc.sh #{site} #{machine_name} #{bmc_port}"}
163 # Create configuration for ICN provisioning
164 legacy_machine_args = "#{legacy_machine_args} #{machine_name} #{bmc_port}"
165 m.trigger.after [:up] do |trigger|
166 trigger.info = 'Creating nodes.json.sample describing the machines'
167 trigger.run = {inline: "./tools/vagrant/create_nodes_json_sample.sh #{site} #{legacy_machine_args}"}
169 m.trigger.after [:up] do |trigger|
170 trigger.info = 'Creating Provisioning resource describing the cluster'
171 trigger.run = {inline: "./tools/vagrant/create_provisioning_cr.sh #{site} #{legacy_machine_args}"}