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-16.04-x86_64', :version => '20180708.0.0' },
14 :libvirt => { :name => 'elastic/ubuntu-16.04-x86_64', :version=> '20180210.0.0'}
18 pdf = File.dirname(__FILE__) + '/config/default.yml'
19 if File.exist?(File.dirname(__FILE__) + '/config/pdf.yml')
20 pdf = File.dirname(__FILE__) + '/config/pdf.yml'
22 nodes = YAML.load_file(pdf)
24 # Inventory file creation
25 File.open(File.dirname(__FILE__) + "/inventory/hosts.ini", "w") do |inventory_file|
26 inventory_file.puts("[all]")
28 inventory_file.puts("#{node['name']}\tansible_ssh_host=#{node['ip']} ansible_ssh_port=22")
30 ['kube-master', 'kube-node', 'etcd', 'ovn-central', 'ovn-controller', 'virtlet'].each do|group|
31 inventory_file.puts("\n[#{group}]")
33 if node['roles'].include?("#{group}")
34 inventory_file.puts(node['name'])
38 inventory_file.puts("\n[k8s-cluster:children]\nkube-node\nkube-master")
41 provider = (ENV['VAGRANT_DEFAULT_PROVIDER'] || :libvirt).to_sym
42 puts "[INFO] Provider: #{provider} "
44 if ENV['no_proxy'] != nil or ENV['NO_PROXY']
45 $no_proxy = ENV['NO_PROXY'] || ENV['no_proxy'] || "127.0.0.1,localhost"
47 $no_proxy += "," + node['ip']
49 $subnet = "192.168.121"
50 if provider == :virtualbox
53 # NOTE: This range is based on vagrant-libvirt network definition CIDR 192.168.121.0/27
55 $no_proxy += ",#{$subnet}.#{i}"
59 Vagrant.configure("2") do |config|
60 config.vm.box = box[provider][:name]
61 config.vm.box_version = box[provider][:version]
62 config.ssh.insert_key = false
64 if ENV['http_proxy'] != nil and ENV['https_proxy'] != nil
65 if Vagrant.has_plugin?('vagrant-proxyconf')
66 config.proxy.http = ENV['http_proxy'] || ENV['HTTP_PROXY'] || ""
67 config.proxy.https = ENV['https_proxy'] || ENV['HTTPS_PROXY'] || ""
68 config.proxy.no_proxy = $no_proxy
69 config.proxy.enabled = { docker: false }
74 config.vm.define node['name'] do |nodeconfig|
75 nodeconfig.vm.hostname = node['name']
76 nodeconfig.vm.network :private_network, :ip => node['ip'], :type => :static
77 nodeconfig.vm.provider 'virtualbox' do |v|
78 v.customize ["modifyvm", :id, "--memory", node['memory']]
79 v.customize ["modifyvm", :id, "--cpus", node['cpus']]
80 if node.has_key? "volumes"
81 node['volumes'].each do |volume|
82 $volume_file = "#{node['name']}-#{volume['name']}.vdi"
83 unless File.exist?($volume_file)
84 v.customize ['createmedium', 'disk', '--filename', $volume_file, '--size', volume['size']]
86 v.customize ['storageattach', :id, '--storagectl', 'IDE Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', $volume_file]
90 nodeconfig.vm.provider 'libvirt' do |v|
91 v.memory = node['memory']
94 v.cpu_mode = 'host-passthrough'
95 v.management_network_address = "192.168.121.0/27"
96 nodeconfig.vm.provision 'shell' do |sh|
98 if node.has_key? "volumes"
99 $volume_mounts_dict = ''
100 node['volumes'].each do |volume|
101 $volume_mounts_dict += "#{volume['name']}=#{volume['mount']},"
102 $volume_file = "./#{node['name']}-#{volume['name']}.qcow2"
103 v.storage :file, :bus => 'sata', :device => volume['name'], :size => volume['size']
105 sh.args = ['-v', $volume_mounts_dict[0...-1]]
111 sync_type = "virtualbox"
112 if provider == :libvirt
115 config.vm.define :installer, primary: true, autostart: false do |installer|
116 installer.vm.hostname = "multicloud"
117 installer.vm.network :private_network, :ip => "10.10.10.2", :type => :static
118 installer.vm.synced_folder '../', '/home/vagrant/multicloud-k8s/', type: sync_type
119 installer.vm.provision 'shell', privileged: false do |sh|
120 sh.env = {'KRD_PLUGIN_ENABLED': 'true'}
122 cp /vagrant/insecure_keys/key.pub /home/vagrant/.ssh/id_rsa.pub
123 cp /vagrant/insecure_keys/key /home/vagrant/.ssh/id_rsa
124 chown vagrant /home/vagrant/.ssh/id_rsa
125 chmod 400 /home/vagrant/.ssh/id_rsa
126 cd /home/vagrant/multicloud-k8s/vagrant/ && ./installer.sh | tee krd_installer.log