Class: Actions::ForemanChef::Host::Destroy

Inherits:
EntryAction
  • Object
show all
Defined in:
app/lib/actions/foreman_chef/host/destroy.rb

Instance Method Summary collapse

Instance Method Details

#cli_exampleObject



41
42
43
44
45
46
# File 'app/lib/actions/foreman_chef/host/destroy.rb', line 41

def cli_example
  return unless input[:host]
  <<-EXAMPLE
hammer host delete --id '#{task_input[:host][:id]}'
  EXAMPLE
end

#humanized_inputObject



37
38
39
# File 'app/lib/actions/foreman_chef/host/destroy.rb', line 37

def humanized_input
  input[:host] && input[:host][:name]
end

#humanized_nameObject



33
34
35
# File 'app/lib/actions/foreman_chef/host/destroy.rb', line 33

def humanized_name
  _("Delete host")
end

#plan(host) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/lib/actions/foreman_chef/host/destroy.rb', line 12

def plan(host)
  action_subject(host)
  if (::Setting[:auto_deletion] && proxy = host.chef_proxy)
    node_exists_in_chef = proxy.show_node(host.name)
    if node_exists_in_chef
      plan_self :chef_proxy_id => host.chef_proxy_id
    end

    plan_action Actions::ForemanChef::Client::Destroy, host.name, proxy
  end
rescue => e
  ::Foreman::Logging.exception('Unable to communicate with Chef proxy', e)
  raise ::ForemanChef::ProxyException.new(N_('Unable to communicate with Chef proxy, %s' % e.message))
end

#resource_locksObject



8
9
10
# File 'app/lib/actions/foreman_chef/host/destroy.rb', line 8

def resource_locks
  :link
end

#runObject



27
28
29
30
31
# File 'app/lib/actions/foreman_chef/host/destroy.rb', line 27

def run
  proxy = ::SmartProxy.unscoped.find_by_id(input[:chef_proxy_id])
  action_logger.debug "Deleting #{input[:host][:name]} on proxy #{proxy.name} at #{proxy.url}"
  self.output = proxy.delete_node(input[:host][:name])
end