Class: Kitchen::Driver::VagrantSandbox

Inherits:
SSHBase
  • Object
show all
Defined in:
lib/kitchen/driver/vagrant_sandbox.rb

Overview

TODO:

Vagrant installation check and version will be placed into any dependency hook checks when feature is released

Vagrant driver for Kitchen. It communicates to Vagrant via the CLI.

Author:

Instance Method Summary collapse

Instance Method Details

#converge(state) ⇒ Object



69
70
71
72
73
74
75
76
# File 'lib/kitchen/driver/vagrant_sandbox.rb', line 69

def converge(state)
  create_vagrantfile
  if config[:use_vagrant_provision] && !config[:do_not_vagrant_provision_in_converge]
    run "vagrant provision"
  else
    super
  end
end

#create(state) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/kitchen/driver/vagrant_sandbox.rb', line 52

def create(state)
  create_vagrantfile
  if sandbox_on?
    sandbox_rollback
    set_ssh_state(state)
    info("Vagrant instance #{instance.to_str} created (by rollback).")
  else
    cmd = "vagrant up"
    cmd += " --no-provision" unless config[:use_vagrant_provision]
    cmd += " --provider=#{@config[:provider]}" if @config[:provider]
    run cmd
    set_ssh_state(state)
    sandbox_on
    info("Vagrant instance #{instance.to_str} created.")
  end
end

#default_values(value) ⇒ Object



111
112
113
# File 'lib/kitchen/driver/vagrant_sandbox.rb', line 111

def default_values(value)
  (default_boxes[instance.platform.name] || Hash.new)[value]
end

#destroy(state) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/kitchen/driver/vagrant_sandbox.rb', line 88

def destroy(state)
  if ENV['KITCHEN_DESTROY_VM']
    create_vagrantfile
    @vagrantfile_created = false
    run "vagrant destroy -f"
    FileUtils.rm_rf(vagrant_root)
    info("Vagrant instance #{instance.to_str} destroyed.")
    state.delete(:hostname)
  else
    info "If you would like to destroy vagrant VM, run `KITCHEN_DESTROY_VM=1 kitchen destroy <REGEX>`"
#          return if state[:hostname].nil?
#
#          sandbox_rollback
#          info("Vagrant instance #{instance.to_str} rollbacked.")
#          state.delete(:hostname)
  end
end

#setup(state) ⇒ Object



78
79
80
81
# File 'lib/kitchen/driver/vagrant_sandbox.rb', line 78

def setup(state)
  create_vagrantfile
  super
end

#verify(state) ⇒ Object



83
84
85
86
# File 'lib/kitchen/driver/vagrant_sandbox.rb', line 83

def verify(state)
  create_vagrantfile
  super
end

#verify_dependenciesObject



106
107
108
109
# File 'lib/kitchen/driver/vagrant_sandbox.rb', line 106

def verify_dependencies
  check_vagrant_version
  check_berkshelf_plugin if config[:use_vagrant_berkshelf_plugin]
end