Class: Vagrant::Chefdev::Action::DeleteChefNode

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-chefdev/action/delete_chef_node.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ DeleteChefNode

Returns a new instance of DeleteChefNode.



6
7
8
9
10
11
12
# File 'lib/vagrant-chefdev/action/delete_chef_node.rb', line 6

def initialize(app, env)
  @app = app
  @machine = env[:machine]
  @global_env = @machine.env
  @provider = @machine.provider_name
  @logger = Log4r::Logger.new('vagrant::chefdev::delete_chef_node')
end

Instance Method Details

#call(env) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/vagrant-chefdev/action/delete_chef_node.rb', line 14

def call(env)
  # skip if machine is not active on destroy action
  return @app.call(env) if !@machine.id && env[:machine_action] == :destroy

  # check config to see if the hosts file should be update automatically
  return @app.call(env) if @global_env.config_global.chefdev.chef_server.nil?

  # Delete chef Node
  @logger.info 'Deleting chef node'
       

  if @machine.config.chefdev.nuke_chef_node
    machine = @global_env.machine(@global_env.config_global.chefdev.chef_server, p)
    machine.communicate("knife node delete -y #{@machine.name}")
     
  end
  @app.call(env)
end