Skip to content

Commit

Permalink
Issue geerlingguy#1370: Add VirtualBox version requirement check
Browse files Browse the repository at this point in the history
  • Loading branch information
oxyc committed Jun 2, 2017
1 parent 8586df6 commit e391fdd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ end
# Verify version requirements.
require_ansible_version ">= #{vconfig['drupalvm_ansible_version_min']}"
Vagrant.require_version ">= #{vconfig['drupalvm_vagrant_version_min']}"
require_virtualbox_version ">= #{vconfig['drupalvm_virtualbox_version_min']}"

Vagrant.configure('2') do |config|
# Set the name of the VM. See: http://stackoverflow.com/a/17864388/100134
Expand Down
1 change: 1 addition & 0 deletions default.config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ vagrant_cpus: 1
# Minimum required versions.
drupalvm_vagrant_version_min: '1.8.6'
drupalvm_ansible_version_min: '2.2'
drupalvm_virtualbox_version_min: '5.1.10'

# Force use of ansible_local provisioner, even if Ansible is installed on host.
force_ansible_local: false
Expand Down
17 changes: 17 additions & 0 deletions lib/drupalvm/vagrant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ def ansible_version
/^[^\s]+ (.+)$/.match(`#{ansible_bin} --version`) { |match| return match[1] }
end

def virtualbox_version
begin
virtualbox = VagrantPlugins::ProviderVirtualBox::Driver::Meta.new
virtualbox.version
rescue Vagrant::Errors::VirtualBoxNotDetected
nil
end
end

# Require that if installed, the ansible version meets the requirements.
def require_ansible_version(requirement)
return unless ansible_bin
Expand All @@ -63,6 +72,14 @@ def require_ansible_version(requirement)
raise_message "You must install an Ansible version #{requirement} to use this version of Drupal VM."
end

# Require that if installed, the VirtualBox version meets the requirements.
def require_virtualbox_version(requirement)
return unless virtualbox_version
req = Gem::Requirement.new(requirement)
return if req.satisfied_by?(Gem::Version.new(virtualbox_version))
raise_message "You must install a VirtualBox version #{requirement} to use this version of Drupal VM."
end

def raise_message(msg)
raise Vagrant::Errors::VagrantError.new, msg
end
Expand Down

0 comments on commit e391fdd

Please sign in to comment.