Module: Berkshelf::Vagrant

Defined in:
lib/berkshelf/vagrant.rb,
lib/berkshelf/vagrant/config.rb,
lib/berkshelf/vagrant/middleware.rb,
lib/berkshelf/vagrant/action/clean.rb,
lib/berkshelf/vagrant/action/set_ui.rb,
lib/berkshelf/vagrant/action/upload.rb,
lib/berkshelf/vagrant/action/install.rb,
lib/berkshelf/vagrant/action/validate.rb

Overview

Author:

Defined Under Namespace

Modules: Action, Middleware Classes: Config

Class Method Summary collapse

Class Method Details

.chef_client?(config) ⇒ Boolean

Determine if the given instance of Vagrant::Config::Top contains a chef_client provisioner

Parameters:

  • config (Vagrant::Config::Top)

Returns:

  • (Boolean)


53
54
55
# File 'lib/berkshelf/vagrant.rb', line 53

def chef_client?(config)
  !provisioners(:chef_client, config).empty?
end

.chef_solo?(config) ⇒ Boolean

Determine if the given instance of Vagrant::Config::Top contains a chef_solo provisioner

Parameters:

  • config (Vagrant::Config::Top)

Returns:

  • (Boolean)


43
44
45
# File 'lib/berkshelf/vagrant.rb', line 43

def chef_solo?(config)
  !provisioners(:chef_solo, config).empty?
end

.init!Object

Initialize the Berkshelf Vagrant middleware stack



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/berkshelf/vagrant.rb', line 58

def init!
  ::Vagrant.config_keys.register(:berkshelf) { Berkshelf::Vagrant::Config }

  [ :provision, :start ].each do |action|
    ::Vagrant.actions[action].insert(::Vagrant::Action::General::Validate, Berkshelf::Vagrant::Action::Validate)
    ::Vagrant.actions[action].insert(::Vagrant::Action::VM::Provision, Berkshelf::Vagrant::Middleware.install)
    ::Vagrant.actions[action].insert(::Vagrant::Action::VM::Provision, Berkshelf::Vagrant::Middleware.upload)
  end

  ::Vagrant.actions[:destroy].insert(::Vagrant::Action::VM::ProvisionerCleanup, Berkshelf::Vagrant::Middleware.clean)
end

.provisioners(shortcut, config) ⇒ Array

Parameters:

  • shortcut (Symbol)
  • config (Vagrant::Config::Top)

Returns:

  • (Array)


33
34
35
# File 'lib/berkshelf/vagrant.rb', line 33

def provisioners(shortcut, config)
  config.vm.provisioners.select { |prov| prov.shortcut == shortcut }
end

.shelf_for(env) ⇒ String?

Parameters:

  • env (Vagrant::Action::Environment)

Returns:



23
24
25
26
27
# File 'lib/berkshelf/vagrant.rb', line 23

def shelf_for(env)
  return nil if env[:vm].uuid.nil?

  File.join(Berkshelf.berkshelf_path, "vagrant", env[:vm].uuid)
end