diff --git a/deploy/vagrant/Vagrantfile b/deploy/vagrant/Vagrantfile index fa4dcaf..61624ff 100644 --- a/deploy/vagrant/Vagrantfile +++ b/deploy/vagrant/Vagrantfile @@ -1,5 +1,7 @@ ENV['VAGRANT_NO_PARALLEL'] = 'yes' +num_workers = ENV['TINKERBELL_NUM_WORKERS'] || '1' + # Returns true if `GUI` environment variable exists, value does not matter. # Defaults to false def worker_gui_enabled? @@ -12,6 +14,14 @@ def worker_display_scale_enabled? ENV.include?('VAGRANT_WORKER_SCALE') end +def configure_nat + return ENV.has_key?('TINKERBELL_CONFIGURE_NAT') ? ENV['TINKERBELL_CONFIGURE_NAT'] : 'true' +end + +def libvirt_forward_mode + return configure_nat == 'false' ? 'nat' : 'none' +end + Vagrant.configure('2') do |config| config.vm.define :provisioner do |provisioner| @@ -19,7 +29,11 @@ Vagrant.configure('2') do |config| provisioner.vm.box_version = "0.1.0" provisioner.vm.hostname = 'provisioner' provisioner.vm.synced_folder './../../', '/vagrant' - provisioner.vm.provision :shell, path: './scripts/tinkerbell.sh' + provisioner.vm.provision :shell, + path: './scripts/tinkerbell.sh', + env: { + 'TINKERBELL_CONFIGURE_NAT': configure_nat, + } provisioner.vm.network :private_network, virtualbox__intnet: "tink_network", @@ -27,7 +41,7 @@ Vagrant.configure('2') do |config| libvirt__host_ip: "192.168.1.6", libvirt__netmask: "255.255.255.248", libvirt__dhcp_enabled: false, - libvirt__forward_mode: 'none', + libvirt__forward_mode: libvirt_forward_mode, libvirt__adapter: 1, auto_config: false @@ -47,43 +61,49 @@ Vagrant.configure('2') do |config| end end - config.vm.define "worker" do |worker| - worker.vm.box = nil - worker.vm.network :private_network, - mac: "080027000001", - virtualbox__intnet: "tink_network", - libvirt__network_name: "tink_network", - libvirt__dhcp_enabled: false, - libvirt__forward_mode: 'none', - auto_config: false - worker.vm.provider :libvirt do |lv| - lv.memory = 4*1024 - lv.cpus = 1 - lv.boot 'network' - lv.mgmt_attach = false - lv.storage :file, :size => '40G' - lv.random :model => 'random' - end + (1..num_workers.to_i).each do |i| + mac_suffix = "%02x" % i + worker_suffix = i==1 ? "" : "i" + config.vm.define "worker#{worker_suffix}" do |worker| + + worker.vm.box = nil + worker.vm.network :private_network, + mac: "0800270000#{mac_suffix}", + virtualbox__intnet: "tink_network", + libvirt__network_name: "tink_network", + libvirt__dhcp_enabled: false, + libvirt__forward_mode: libvirt_forward_mode, + auto_config: false - worker.vm.provider :virtualbox do |vb, worker| - worker.vm.box = 'generic/alpine38' - vb.memory = 4*1024 - vb.cpus = 1 - vb.gui = worker_gui_enabled? - vb.customize [ - 'setextradata', :id, - 'GUI/ScaleFactor', '3.0' - ] if worker_display_scale_enabled? - vb.customize [ - 'modifyvm', :id, - '--nic1', 'none', - '--boot1', 'net', - '--boot2', 'none', - '--boot3', 'none', - '--boot4', 'none', - '--macaddress1', '080027000001' - ] + worker.vm.provider :libvirt do |lv| + lv.memory = 4*1024 + lv.cpus = 1 + lv.boot 'network' + lv.mgmt_attach = false + lv.storage :file, :size => '40G' + lv.random :model => 'random' + end + + worker.vm.provider :virtualbox do |vb, worker| + worker.vm.box = 'generic/alpine38' + vb.memory = 4*1024 + vb.cpus = 1 + vb.gui = worker_gui_enabled? + vb.customize [ + 'setextradata', :id, + 'GUI/ScaleFactor', '3.0' + ] if worker_display_scale_enabled? + vb.customize [ + 'modifyvm', :id, + '--nic1', 'none', + '--boot1', 'net', + '--boot2', 'none', + '--boot3', 'none', + '--boot4', 'none', + '--macaddress1', "0800270000#{mac_suffix}" + ] + end end end end diff --git a/deploy/vagrant/scripts/tinkerbell.sh b/deploy/vagrant/scripts/tinkerbell.sh index b139e89..65c7c3b 100644 --- a/deploy/vagrant/scripts/tinkerbell.sh +++ b/deploy/vagrant/scripts/tinkerbell.sh @@ -45,10 +45,12 @@ main() ( ./setup.sh - setup_nat + if [[ ${TINKERBELL_CONFIGURE_NAT:=true} != "false" ]]; then + setup_nat + fi + secure_certs configure_vagrant_user - ) main