X-Git-Url: https://gerrit.akraino.org/r/gitweb?a=blobdiff_plain;f=Vagrantfile;h=8ab75edeede568e2460268144f360deff34b7237;hb=8fcb874a6e5ec52b4a6ac80cb7f34c7baccd8c17;hp=bd4ea5c9ba10ae276f3a8a2f8186ed62f8a538a5;hpb=5f7e452a5fd65cf80e0cbc6df5787138ccbeb893;p=icn.git diff --git a/Vagrantfile b/Vagrantfile index bd4ea5c..8ab75ed 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,16 +1,180 @@ # -*- mode: ruby -*- # vi: set ft=ruby : +require 'ipaddr' +require 'uri' +require 'yaml' +# IMPORTANT To bring up the machines, use the "--no-parallel" option +# to vagrant up. This is to workaround dependencies between the jump +# machine and the machine pool machines. Specifically, the pool +# machines will fail to come up until the baremetal network (created +# by vagrant from the jump machine definition) is up. + +site = ENV['ICN_SITE'] || 'vm' + +# Calculate the baremetal network address from the bmcAddress (aka +# IPMI address) specified in the machine pool values. IPMI in the +# virtual environment is emulated by virtualbmc listening on the host. +baremetal_cidr = nil +registry_mirrors = nil +Dir.glob("deploy/site/#{site}/*.yaml") do |file| + YAML.load_stream(File.read(file)) do |document| + values = document.fetch('spec', {}).fetch('values', {}) + unless values['bmcAddress'].nil? + bmc_host = URI.parse(values['bmcAddress']).host + baremetal_cidr = "#{IPAddr.new(bmc_host).mask(24)}/24" + end + unless values['dockerRegistryMirrors'].nil? + registry_mirrors = values['dockerRegistryMirrors'].join(' ') + end + end +end +if baremetal_cidr.nil? + puts "Missing bmcAddress value in site definition, can't determine baremetal network address" + exit 1 +end + +$post_up_message = < "#{site}-provisioning", + :type => 'dhcp' + + # IPMI control of machines is provided by vbmc on the host + m.trigger.after [:up] do |trigger| + trigger.name = 'Starting virtualbmc for IPMI network' + trigger.run = {inline: "./tools/vagrant/start_vbmc.sh"} + end + m.trigger.after [:destroy] do |trigger| + trigger.name = 'Stopping virtualbmc for IPMI network' + trigger.run = {inline: "./tools/vagrant/stop_vbmc.sh"} + end + + m.trigger.after [:up] do |trigger| + trigger.name = 'Creating ICN user_config.sh' + trigger.run = {inline: "bash -c 'DOCKER_REGISTRY_MIRRORS=\"#{registry_mirrors}\" ./tools/vagrant/create_user_config.sh'"} + end + m.vm.provision 'Configuring ICN prerequisites', type: 'shell', privileged: true, inline: <<-SHELL + ssh-keygen -f "${HOME}/.ssh/id_rsa" -P "" << 50, :type => 'raw', :cache => 'none' + # Management attach is false so that vagrant will not interfere + # with these machines: the jump server will manage them + # completely + libvirt.mgmt_attach = false + end + # The provisioning network must be listed first for PXE boot to + # the metal3/ironic provided image + m.vm.network :private_network, + :libvirt__network_name => "#{site}-provisioning", + :mac => boot_mac_address, + :type => 'dhcp' + m.vm.network :private_network, + :libvirt__network_name => "#{site}-baremetal", + :type => 'dhcp' + + # IPMI control + m.trigger.after [:up] do |trigger| + trigger.name = 'Adding machine to IPMI network' + trigger.run = {inline: "./tools/vagrant/add_machine_to_vbmc.sh #{site} #{machine_name} #{bmc_port}"} + end + m.trigger.after [:destroy] do |trigger| + trigger.name = 'Removing machine from IPMI network' + trigger.run = {inline: "./tools/vagrant/remove_machine_from_vbmc.sh #{site} #{machine_name} #{bmc_port}"} + end + + # Create configuration for ICN provisioning + legacy_machine_args = "#{legacy_machine_args} #{machine_name} #{bmc_port}" + m.trigger.after [:up] do |trigger| + trigger.info = 'Creating nodes.json.sample describing the machines' + trigger.run = {inline: "./tools/vagrant/create_nodes_json_sample.sh #{site} #{legacy_machine_args}"} + end + m.trigger.after [:up] do |trigger| + trigger.info = 'Creating Provisioning resource describing the cluster' + trigger.run = {inline: "./tools/vagrant/create_provisioning_cr.sh #{site} #{legacy_machine_args}"} + end + end + end end end