Class: DaptivChefCI::VagrantDriver

Inherits:
Object
  • Object
show all
Defined in:
lib/daptiv-chef-ci/vagrant_driver.rb

Instance Method Summary collapse

Constructor Details

#initialize(provider = :virtualbox, shell = nil, basebox_builder_factory = nil) ⇒ VagrantDriver

Constructs a new Vagrant management instance

defaults to :virtualbox

Parameters:

  • The (String)

    name of the Vagrant virtualization provider: virtualbox, vmware_fusion

  • The (Shell)

    CLI, optional

  • The (BaseBoxBuilderFactory)

    base box builder factory instance, optional



15
16
17
18
19
20
# File 'lib/daptiv-chef-ci/vagrant_driver.rb', line 15

def initialize(provider = :virtualbox, shell = nil, basebox_builder_factory = nil)
  @logger = Log4r::Logger.new("daptiv_chef_ci::vagrant")
  @shell = shell || DaptivChefCI::Shell.new()
  @basebox_builder_factory = basebox_builder_factory || DaptivChefCI::BaseBoxBuilderFactory.new()
  @provider = provider
end

Instance Method Details

#destroy(opts = {}) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/daptiv-chef-ci/vagrant_driver.rb', line 22

def destroy(opts={})
  opts = {
    :cmd_timeout_in_seconds => 180,
    :retry_attempts => 2,
    :retry_wait_in_seconds => 20
  }.merge(opts)
  exec_cmd_with_retry('vagrant destroy -f', opts)
end

#halt(opts = {}) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/daptiv-chef-ci/vagrant_driver.rb', line 31

def halt(opts={})
  opts = {
    :cmd_timeout_in_seconds => 180,
    :retry_attempts => 2,
    :retry_wait_in_seconds => 20
  }.merge(opts)
  exec_cmd_with_retry('vagrant halt', opts)
end

#package(opts = {}) ⇒ Object



66
67
68
69
70
71
72
73
# File 'lib/daptiv-chef-ci/vagrant_driver.rb', line 66

def package(opts={})
  base_dir = opts[:base_dir] || Dir.pwd
  box_name = opts[:box_name] || File.basename(base_dir)
  box_name += '.box' unless box_name.end_with?('.box')
  
  builder = @basebox_builder_factory.create(@shell, @provider, base_dir)
  builder.build(box_name)
end

#provision(opts = {}) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/daptiv-chef-ci/vagrant_driver.rb', line 50

def provision(opts={})
  opts = {
    :cmd_timeout_in_seconds => 7200,
    :retry_attempts => 0
  }.merge(opts)
  exec_cmd_with_retry('vagrant provision', opts)
end

#reload(opts = {}) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/daptiv-chef-ci/vagrant_driver.rb', line 58

def reload(opts={})
  opts = {
    :cmd_timeout_in_seconds => 180,
    :retry_attempts => 0
  }.merge(opts)
  exec_cmd_with_retry('vagrant reload', opts)
end

#up(opts = {}) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/daptiv-chef-ci/vagrant_driver.rb', line 40

def up(opts={})
  opts = {
    :cmd_timeout_in_seconds => 7200,
    :retry_attempts => 0
  }.merge(opts)
  cmd = 'vagrant up'
  cmd += ' --provider=' + @provider.to_s if @provider != :virtualbox
  exec_cmd_with_retry(cmd, opts)
end