X-Git-Url: https://gerrit.akraino.org/r/gitweb?a=blobdiff_plain;f=Vagrantfile;h=ea8593d244c71adc6fad7cb0ff4aea8444f75e1c;hb=41776ab3743c491e4ff4c31e7a2ea48abe6451a2;hp=6cde8dfb0dc6ced17fdda5a069f00b30883983fe;hpb=d97c464fe4c7ae16385bf101405a1f1f6a2dcb09;p=icn.git diff --git a/Vagrantfile b/Vagrantfile index 6cde8df..ea8593d 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,14 +1,174 @@ # -*- 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' +with_jenkins = ENV['WITH_JENKINS'] || false + +# 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}/deployment/*.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 +baremetal_gw = IPAddr.new(baremetal_cidr).succ + +$post_up_message = < "#{site}-provisioning", + :type => 'dhcp' + + # BMC control of machines is provided by sushy-emulator on the host + m.trigger.after [:up] do |trigger| + trigger.name = 'Starting sushy for BMC network' + trigger.run = {inline: "./tools/vagrant/start_sushy.sh #{baremetal_gw}"} + end + m.trigger.after [:destroy] do |trigger| + trigger.name = 'Stopping sushy for BMC network' + trigger.run = {inline: "./tools/vagrant/stop_sushy.sh #{baremetal_gw}"} + 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' + end + end end end