Class: VagrantPlugins::Pcc::Action::Cleanup

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-pcc/action/cleanup.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ Cleanup

Returns a new instance of Cleanup.



9
10
11
# File 'lib/vagrant-pcc/action/cleanup.rb', line 9

def initialize(app,env)
  @app = app
end

Instance Attribute Details

#guestpathObject

Returns the value of attribute guestpath.



7
8
9
# File 'lib/vagrant-pcc/action/cleanup.rb', line 7

def guestpath
  @guestpath
end

Instance Method Details

#call(env) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/vagrant-pcc/action/cleanup.rb', line 45

def call(env)
  if puppet_apply?(env) or puppet_agent?(env)
    setup(env)
    command = "#{@guestpath}/puppet-cert-clean"
    if env[:machine].state.id != :running
      env[:ui].info("#{ machine.name} is not running.") 
    end 
    env[:machine].communicate.sudo(command) do | type, data | 
      env[:ui].info(data) 
    end
  end
    
  @app.call(env)
end

#provisioners(name, env) ⇒ Object



13
14
15
16
17
# File 'lib/vagrant-pcc/action/cleanup.rb', line 13

def provisioners(name, env)
  env[:machine].config.vm.provisioners.select do |prov|
    prov.name == name 
  end
end

#puppet_agent?(env) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/vagrant-pcc/action/cleanup.rb', line 23

def puppet_agent?(env)
  provisioners(:puppet_server, env).any?
end

#puppet_apply?(env) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/vagrant-pcc/action/cleanup.rb', line 19

def puppet_apply?(env)
  provisioners(:puppet, env).any?
end

#setup(env) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/vagrant-pcc/action/cleanup.rb', line 27

def setup(env)
  clean_script = 'puppet-cert-clean'
  script_dir = File.join(Pcc.source_root, 'bin')
  dst = "#{env[:machine].env.root_path}/puppet-cert-clean"
  src = "#{script_dir}/#{clean_script}"

  unless File.exists?(dst)
    FileUtils.cp(src, dst)
    FileUtils.chmod(0755, dst)
  end

  env[:machine].config.vm.synced_folders.each do |id, data|
      @guestpath = data[:guestpath] if data[:hostpath] == "."
  end

  @guestpath ||= '/vagrant'
end