Browse Source

Print warning if host OS cannot run our VM

Hamilton Turner 11 years ago
parent
commit
138dc24844
1 changed files with 64 additions and 0 deletions
  1. 64 0
      toolset/deployment/vagrant/Vagrantfile

+ 64 - 0
toolset/deployment/vagrant/Vagrantfile

@@ -17,6 +17,70 @@ if provider == :"aws" \
   TFB_AWS_KEY_NAME   : The name of the keypair you are using
   TFB_AWS_KEY_NAME   : The name of the keypair you are using
   TFB_AWS_KEY_PATH   : Path to the *.pem file for the keypair you are using'
   TFB_AWS_KEY_PATH   : Path to the *.pem file for the keypair you are using'
 end
 end
+
+# Helps with finding current OS
+module OS
+  def OS.windows?
+    (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
+  end
+
+  def OS.mac?
+   (/darwin/ =~ RUBY_PLATFORM) != nil
+  end
+
+  def OS.unix?
+    !OS.windows?
+  end
+
+  def OS.linux?
+    OS.unix? and not OS.mac?
+  end
+end
+
+# Helps with finding current OS
+module ARCH
+  def ARCH.is64?
+    (/x86_64/ =~ RUBY_PLATFORM) != nil
+  end
+
+  def ARCH.is32?
+    !ARCH.is64?
+  end
+end
+
+# Check if this computer can run a 64-bit OS
+if provider == :"virtualbox"
+  warning = "\033[31m\
+WARNING: FrameworkBenchmarks only officially supports a 64-bit 
+virtual machine, which your current system may not be able to 
+support. Use `TFB_SHOW_VM=true vagrant up` to watch the VM launch -
+if you just see a black window you likely cannot run a 64-bit VM. 
+
+To workaround, consider using the Amazon (e.g. AWS) provider
+   $ vagrant up --provider=aws
+
+Or forcing FrameworkBenchmarks to attempt a 32-bit VM
+   $ TFB_VM_ARCH=32 vagrant up
+  
+  See http://askubuntu.com/questions/41550 for more info\033[0m"
+
+  # AMD-based needs svm feature, Intel-based needs vmx feature
+  if OS.linux? and %x(egrep '(vmx|svm)' /proc/cpuinfo).empty?
+    puts warning
+  end
+
+  # Ignore PowerPC, check for intel features
+  if OS.mac? and %x(sysctl -n machdep.cpu.features | grep -i vmx).empty?
+    puts warning
+  end
+
+  # Don't really know how to check CPU features, so I'll just check 
+  # the arch
+  if OS.windows? and ARCH.is32?
+    puts warning
+  end
+end
+
 Vagrant.configure("2") do |config|
 Vagrant.configure("2") do |config|
   config.vm.hostname = "TFB"
   config.vm.hostname = "TFB"
   config.vm.box = "ubuntu/trusty64"
   config.vm.box = "ubuntu/trusty64"