Class: VagrantPlugins::Berkshelf::Action::Load

Inherits:
Base
  • Object
show all
Defined in:
lib/vagrant-berkshelf/action/load.rb

Instance Method Summary collapse

Methods inherited from Base

clean, #initialize, provision, setup

Methods included from Helpers

#berks, #berks_bin, #berkshelf_enabled?, #chef_client?, #chef_solo?, #chef_zero?, #datafile_path, #provision_enabled?, #provisioners, #with_clean_env

Constructor Details

This class inherits a constructor from VagrantPlugins::Berkshelf::Action::Base

Instance Method Details

#call(env) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/vagrant-berkshelf/action/load.rb', line 7

def call(env)
  if !berkshelf_enabled?(env)
    @logger.info "Berkshelf disabled, skipping"
    return @app.call(env)
  end

  if File.exist?(datafile_path(env))
    env[:machine].ui.info "Loading Berkshelf datafile..."
    shelf = File.read(datafile_path(env)).chomp

    @logger.debug "Shelf: #{shelf.inspect}"

    env[:berkshelf].shelf = shelf
  end

  if !env[:berkshelf].shelf
    shelf = mkshelf(env)
    env[:machine].ui.detail "The Berkshelf shelf is at #{shelf.inspect}"

    @logger.debug "Persisting datafile share to memory"
    env[:berkshelf].shelf = shelf
  end

  @app.call(env)
end

#mkshelf(env) ⇒ String

Create a new Berkshelf shelf for the current machine.

Returns:

  • (String)

    the path to the temporary directory



36
37
38
39
40
41
42
43
44
# File 'lib/vagrant-berkshelf/action/load.rb', line 36

def mkshelf(env)
  shelves = Berkshelf.shelves_path

  if !File.exist?(shelves)
    FileUtils.mkdir_p(shelves)
  end

  Dir.mktmpdir(['berkshelf', "-#{env[:machine].name}"], shelves)
end