summaryrefslogtreecommitdiffstats
path: root/Rakefile
diff options
context:
space:
mode:
authorTails developers <amnesia@boum.org>2012-05-16 08:32:02 +0200
committerTails developers <amnesia@boum.org>2012-05-16 13:30:42 +0200
commit3c41c91187940dba63609b60c014ba23c1e88f5d (patch)
treeac122d3bdd15c6bf5cc95e0d2c1abc1ea54d91d7 /Rakefile
parente379dfc4baea607c089569d0ad327ec039360fc2 (diff)
vagrant: Add support for virtual CPUs build settings
Diffstat (limited to 'Rakefile')
-rw-r--r--Rakefile21
1 files changed, 21 insertions, 0 deletions
diff --git a/Rakefile b/Rakefile
index ea42ade..f6ad2c5 100644
--- a/Rakefile
+++ b/Rakefile
@@ -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