Commit 3c41c911 authored by Tails developers's avatar Tails developers
Browse files

vagrant: Add support for virtual CPUs build settings

parent e379dfc4
......@@ -41,6 +41,13 @@ def current_vm_memory
$1.to_i if info =~ /^memory=(\d+)/
end
def current_vm_cpus
env = Vagrant::Environment.new(:cwd => VAGRANT_PATH, :ui_class => Vagrant::UI::Basic)
uuid = env.primary_vm.uuid
info = env.primary_vm.driver.execute 'showvminfo', uuid, '--machinereadable'
$1.to_i if info =~ /^cpus=(\d+)/
end
def enough_free_memory?
return false unless RbConfig::CONFIG['host_os'] =~ /linux/i
......@@ -86,6 +93,9 @@ task :parse_build_options do
# Clean-up settings
when 'cleanall'
ENV['TAILS_CLEAN_BUILD'] = '1'
# Virtual CPUs settings
when /cpus=(\d+)/
ENV['TAILS_BUILD_CPUS'] = $1
end
end
end
......@@ -162,6 +172,17 @@ namespace :vm do
END_OF_MESSAGE
abort 'Not enough memory for the virtual machine to run an in-memory build. Aborting.'
end
if ENV['TAILS_BUILD_CPUS'] && current_vm_cpus != ENV['TAILS_BUILD_CPUS'].to_i
$stderr.puts <<-END_OF_MESSAGE.gsub(/^ /, '')
The virtual machine is currently running with #{current_vm_cpus}
virtual CPU(s). In order to change that number, you need to
stop the VM first, using `rake vm:halt`. Otherwise, please
adjust the `cpus` options accordingly.
END_OF_MESSAGE
abort 'The virtual machine needs to be reloaded to change the number of CPUs. Aborting.'
end
end
result = env.cli('up')
abort "'vagrant up' failed" unless result
......
......@@ -28,6 +28,8 @@ else
mem_size = VM_MEMORY_FOR_DISK_BUILDS
end
cpus = ENV['TAILS_BUILD_CPUS']
Vagrant::Config.run do |config|
config.vm.box = 'tails'
......@@ -39,4 +41,5 @@ Vagrant::Config.run do |config|
config.vm.share_folder 'amnesia', '/amnesia.git', '../.git'
config.vm.customize ['modifyvm', :id, '--memory', mem_size]
config.vm.customize ['modifyvm', :id, '--cpus', cpus] unless cpus.nil?
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment