Class: Actions::ForemanChef::Node::Update

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

Instance Method Summary collapse

Instance Method Details

#humanized_inputObject



37
38
39
# File 'app/lib/actions/foreman_chef/node/update.rb', line 37

def humanized_input
  input[:name]
end

#humanized_nameObject



33
34
35
# File 'app/lib/actions/foreman_chef/node/update.rb', line 33

def humanized_name
  _("Update node")
end

#plan(host, proxy) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/lib/actions/foreman_chef/node/update.rb', line 6

def plan(host, proxy)
  name = host.name
  raise ::ForemanChef::HostDoesNotHaveChefProxy.new(N_('Host with name %s does not have chef proxy specified but asked to update the node') % name) if proxy.nil?

  node_exists_in_chef = proxy.show_node(name)
  if node_exists_in_chef
    # we can't use host.run_list.list_changed? or similar since it's after_save already
    if host.differs?
      plan_self :chef_proxy_id => proxy.id, :host_id => host.id
    else
      Rails.logger.debug "Host data do not differ from corresponding Chef server Node, skipping update"
    end
  else
    raise ::ForemanChef::ObjectDoesNotExistException.new(N_('Node with name %s does not exist on this Chef proxy' % name))
  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

#runObject



26
27
28
29
30
31
# File 'app/lib/actions/foreman_chef/node/update.rb', line 26

def run
  proxy = ::SmartProxy.unscoped.find_by_id(input[:chef_proxy_id])
  host = ::Host.unscoped.find(input[:host_id])
  action_logger.debug "Updating node #{input[:name]} on proxy #{proxy.name} at #{proxy.url}"
  proxy.update_node(host.name, host.run_list.as_chef_json.merge(:chef_environment => host.chef_environment.name))
end