Class: Kitchen::Driver::Vagrant
- Inherits:
-
Base
- Object
- Base
- Kitchen::Driver::Vagrant
- Includes:
- ShellOut
- Defined in:
- lib/kitchen/driver/vagrant.rb
Overview
Vagrant driver for Kitchen. It communicates to Vagrant via the CLI.
Class Attribute Summary collapse
-
.vagrant_version ⇒ String
private
The version of Vagrant installed on the workstation.
-
.winrm_plugin_passed ⇒ true, false
private
Whether or not the vagrant-winrm plugin is installed.
Instance Method Summary collapse
-
#create(state) ⇒ Object
Creates a Vagrant VM instance.
-
#default_box ⇒ String?
The Vagrant box for this Instance.
-
#default_box_url ⇒ String?
The Vagrant box URL for this Instance.
-
#destroy(state) ⇒ Object
Destroys an instance.
-
#finalize_config!(instance) ⇒ self
A lifecycle method that should be invoked when the object is about ready to be used.
-
#verify_dependencies ⇒ Object
Performs whatever tests that may be required to ensure that this driver will be able to function in the current environment.
-
#winrm_transport? ⇒ TrueClass, FalseClass
private
Whether or not the transport’s name implies a WinRM-based transport.
Class Attribute Details
.vagrant_version ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the version of Vagrant installed on the workstation.
186 187 188 |
# File 'lib/kitchen/driver/vagrant.rb', line 186 def vagrant_version @vagrant_version end |
.winrm_plugin_passed ⇒ true, false
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns whether or not the vagrant-winrm plugin is installed.
182 183 184 |
# File 'lib/kitchen/driver/vagrant.rb', line 182 def winrm_plugin_passed @winrm_plugin_passed end |
Instance Method Details
#create(state) ⇒ Object
Creates a Vagrant VM instance.
85 86 87 88 89 90 91 92 |
# File 'lib/kitchen/driver/vagrant.rb', line 85 def create(state) create_vagrantfile run_pre_create_command run_vagrant_up update_state(state) instance.transport.connection(state).wait_until_ready info("Vagrant instance #{instance.to_str} created.") end |
#default_box ⇒ String?
Returns the Vagrant box for this Instance.
95 96 97 98 99 100 101 |
# File 'lib/kitchen/driver/vagrant.rb', line 95 def default_box if bento_boxes.include?(instance.platform.name) "opscode-#{instance.platform.name}" else instance.platform.name end end |
#default_box_url ⇒ String?
Returns the Vagrant box URL for this Instance.
104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/kitchen/driver/vagrant.rb', line 104 def default_box_url return unless bento_boxes.include?(instance.platform.name) provider = config[:provider] provider = "vmware" if config[:provider] =~ /^vmware_(.+)$/ if %w[virtualbox vmware].include?(provider) "https://opscode-vm-bento.s3.amazonaws.com/vagrant/#{provider}/" \ "opscode_#{instance.platform.name}_chef-provisionerless.box" end end |
#destroy(state) ⇒ Object
Destroys an instance.
120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/kitchen/driver/vagrant.rb', line 120 def destroy(state) return if state[:hostname].nil? create_vagrantfile @vagrantfile_created = false instance.transport.connection(state).close run("vagrant destroy -f") FileUtils.rm_rf(vagrant_root) info("Vagrant instance #{instance.to_str} destroyed.") state.delete(:hostname) end |
#finalize_config!(instance) ⇒ self
A lifecycle method that should be invoked when the object is about ready to be used. A reference to an Instance is required as configuration dependant data may be access through an Instance. This also acts as a hook point where the object may wish to perform other last minute checks, validations, or configuration expansions.
141 142 143 144 145 146 147 |
# File 'lib/kitchen/driver/vagrant.rb', line 141 def finalize_config!(instance) super finalize_vm_hostname! finalize_pre_create_command! finalize_synced_folders! self end |
#verify_dependencies ⇒ Object
Performs whatever tests that may be required to ensure that this driver will be able to function in the current environment. This may involve checking for the presence of certain directories, software installed, etc.
156 157 158 159 160 161 162 163 |
# File 'lib/kitchen/driver/vagrant.rb', line 156 def verify_dependencies super if Gem::Version.new(vagrant_version) < Gem::Version.new(MIN_VER.dup) raise UserError, "Detected an old version of Vagrant " \ "(#{vagrant_version})." \ " Please upgrade to version #{MIN_VER} or higher from #{WEBSITE}." end end |
#winrm_transport? ⇒ TrueClass, FalseClass
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns whether or not the transport’s name implies a WinRM-based transport.
168 169 170 |
# File 'lib/kitchen/driver/vagrant.rb', line 168 def winrm_transport? instance.transport.name.downcase =~ /win_?rm/ end |