mirror of
https://github.com/clearlinux/cloud-native-setup.git
synced 2026-09-06 13:51:33 +00:00
Avoid creating unique names for disks as vagrant-libvirt today does not delete those images when VMs are deleted. Once that is fixed we can move back to using unique names. Until then this should suffice. Signed-off-by: Ganesh Maharaj Mahalingam <ganesh.mahalingam@intel.com>
87 lines
3.2 KiB
Ruby
87 lines
3.2 KiB
Ruby
# -*- mode: ruby -*-
|
|
# vi: set ft=ruby :
|
|
|
|
require 'fileutils'
|
|
require 'ipaddr'
|
|
require 'securerandom'
|
|
|
|
$num_instances = (ENV['NODES'] || 3).to_i
|
|
$cpus = (ENV['CPUS'] || 2).to_i
|
|
$memory = (ENV['MEMORY'] || 4096).to_i
|
|
$disks = 2
|
|
# Using folder prefix instead of uuid until vagrant-libvirt fixes disk cleanup
|
|
disk_prefix = File.basename(File.dirname(__FILE__), "/")
|
|
#DISK_UUID = SecureRandom.urlsafe_base64(9)
|
|
$disk_size = "10G"
|
|
$box = "AntonioMeireles/ClearLinux"
|
|
$loader = File.join(File.dirname(__FILE__), "OVMF.fd")
|
|
$vm_name_prefix = "clr"
|
|
base_ip = IPAddr.new("192.52.100.10")
|
|
hosts = {}
|
|
proxy_ip_list = ""
|
|
#DISK_UUID = Time.now.utc.to_i
|
|
driveletters = ('a'..'z').to_a
|
|
|
|
if not File.exists?($loader)
|
|
system('curl -O https://download.clearlinux.org/image/OVMF.fd')
|
|
end
|
|
|
|
# We need v 1.0.14 or above for this vagrantfile to work.
|
|
unless Vagrant.has_plugin?("vagrant-guests-clearlinux")
|
|
system "vagrant plugin install vagrant-guests-clearlinux"
|
|
end
|
|
|
|
# Install plugins that you might need.
|
|
if ENV['http_proxy'] || ENV['HTTP_PROXY']
|
|
system "vagrant plugin install vagrant-proxyconf" unless Vagrant.has_plugin?("vagrant-proxyconf")
|
|
end
|
|
|
|
# All Vagrant configuration is done below. The "2" in Vagrant.configure
|
|
# configures the configuration version (we support older styles for
|
|
# backwards compatibility). Please don't change it unless you know what
|
|
# you're doing.
|
|
Vagrant.configure("2") do |config|
|
|
# Every Vagrant development environment requires a box. You can search for
|
|
# boxes at https://vagrantcloud.com/search.
|
|
config.vm.box = $box
|
|
|
|
# Mount the current dir at home folder instead of default
|
|
config.vm.synced_folder './', '/vagrant', disabled: true
|
|
config.vm.synced_folder './', '/home/clear/' + File.basename(Dir.getwd), type: 'rsync'
|
|
#Setup proxies for all machines
|
|
(1..$num_instances).each do |i|
|
|
base_ip = base_ip.succ
|
|
hosts["clr-%02d" % i] = base_ip.to_s
|
|
end
|
|
|
|
hosts.each do |vm_name, ip|
|
|
proxy_ip_list = ("#{proxy_ip_list},#{vm_name},#{ip}")
|
|
end
|
|
|
|
hosts.each do |vm_name, ip|
|
|
config.vm.define vm_name do |c|
|
|
c.vm.hostname = vm_name
|
|
c.vm.network :private_network, ip: ip, autostart: true
|
|
c.vm.provider :libvirt do |lv|
|
|
lv.loader = $loader
|
|
lv.cpu_mode = "host-passthrough"
|
|
lv.nested = true
|
|
lv.cpus = $cpus
|
|
lv.memory = $memory
|
|
(1..$disks).each do |d|
|
|
lv.storage :file, :device => "hd#{driveletters[d]}", :path => "disk-#{disk_prefix}-#{vm_name}-#{d}.disk", :size => $disk_size, :type => "raw"
|
|
end
|
|
end
|
|
if Vagrant.has_plugin?("vagrant-proxyconf")
|
|
c.proxy.http = (ENV['http_proxy']||ENV['HTTP_PROXY'])
|
|
c.proxy.https = (ENV['https_proxy']||ENV['HTTPS_PROXY'])
|
|
c.proxy.no_proxy = (ENV['no_proxy']+"#{proxy_ip_list}" || ENV['NO_PROXY']+"#{proxy_ip_list}" || "localhost,127.0.0.1,172.16.10.10#{proxy_ip_list}")
|
|
end
|
|
c.vm.provision "shell", privileged: false, path: "setup_system.sh"
|
|
c.vm.provision "shell", privileged: false, path: "setup_kata_firecracker.sh"
|
|
# Include shells bundle to get bash completion and add kubectl's commands to vagrant's shell
|
|
c.vm.provision "shell", privileged: false, inline: 'sudo -E swupd bundle-add shells; echo "source <(kubectl completion bash)" >> $HOME/.bashrc'
|
|
end
|
|
end
|
|
end
|