3 # SPDX-license-identifier: Apache-2.0
4 ##############################################################################
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
13 :virtualbox => { :name => 'elastic/ubuntu-18.04-x86_64', :version => '20191013.0.0'},
14 :libvirt => { :name => 'intergratedcloudnative/ubuntu1804', :version => '1.0.0'}
18 pdf = File.dirname(__FILE__) + '/config/default.yml'
19 nodes = YAML.load_file(pdf)
21 provider = (ENV['VAGRANT_DEFAULT_PROVIDER'] || :libvirt).to_sym
22 puts "[INFO] Provider: #{provider} "
24 if ENV['no_proxy'] != nil or ENV['NO_PROXY']
25 $no_proxy = ENV['NO_PROXY'] || ENV['no_proxy'] || "127.0.0.1,localhost"
27 $no_proxy += "," + node['ip']
29 $subnet = "192.168.121"
30 if provider == :virtualbox
33 # NOTE: This range is based on vagrant-libvirt network definition CIDR 192.168.121.0/27
35 $no_proxy += ",#{$subnet}.#{i}"
39 Vagrant.configure("2") do |config|
40 config.vm.box = box[provider][:name]
41 config.vm.box_version = box[provider][:version]
42 config.ssh.insert_key = false
44 if ENV['http_proxy'] != nil and ENV['https_proxy'] != nil
45 if Vagrant.has_plugin?('vagrant-proxyconf')
46 config.proxy.http = ENV['http_proxy'] || ENV['HTTP_PROXY'] || ""
47 config.proxy.https = ENV['https_proxy'] || ENV['HTTPS_PROXY'] || ""
48 config.proxy.no_proxy = $no_proxy
49 config.proxy.enabled = { docker: false }
52 config.vm.provider 'libvirt' do |v|
54 v.cpu_mode = 'host-passthrough'
55 v.management_network_address = "192.168.121.0/27"
56 v.random_hostname = true
59 sync_type = "virtualbox"
60 if provider == :libvirt
65 config.vm.define node['name'] do |nodeconfig|
66 nodeconfig.vm.hostname = node['name']
67 nodeconfig.vm.network :private_network, :ip => node['ip'], :type => :static
68 nodeconfig.vm.provider 'virtualbox' do |v|
69 v.customize ["modifyvm", :id, "--memory", node['memory']]
70 v.customize ["modifyvm", :id, "--cpus", node['cpus']]
71 if node.has_key? "volumes"
72 node['volumes'].each do |volume|
73 $volume_file = "#{node['name']}-#{volume['name']}.vdi"
74 unless File.exist?($volume_file)
75 v.customize ['createmedium', 'disk', '--filename', $volume_file, '--size', volume['size']]
77 v.customize ['storageattach', :id, '--storagectl', 'IDE Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', $volume_file]
81 nodeconfig.vm.provider 'libvirt' do |v|
82 v.memory = node['memory']
84 nodeconfig.vm.provision 'shell' do |sh|
86 if node.has_key? "volumes"
87 $volume_mounts_dict = ''
88 node['volumes'].each do |volume|
89 $volume_mounts_dict += "#{volume['name']}=#{volume['mount']},"
90 $volume_file = "./#{node['name']}-#{volume['name']}.qcow2"
91 v.storage :file, :bus => 'sata', :device => volume['name'], :size => volume['size']
93 sh.args = ['-v', $volume_mounts_dict[0...-1]]