Class: Actions::ForemanChef::Client::Create

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

Instance Method Summary collapse

Instance Method Details

#humanized_inputObject



30
31
32
# File 'app/lib/actions/foreman_chef/client/create.rb', line 30

def humanized_input
  input[:name]
end

#humanized_nameObject



26
27
28
# File 'app/lib/actions/foreman_chef/client/create.rb', line 26

def humanized_name
  _("Create client")
end

#plan(name, proxy) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/lib/actions/foreman_chef/client/create.rb', line 6

def plan(name, proxy)
  return if proxy.nil?

  client_exists_in_chef = proxy.show_client(name)
  if client_exists_in_chef
    raise ::ForemanChef::ObjectExistsException.new(N_('Client with name %s already exist on this Chef proxy' % name))
  else
    plan_self :chef_proxy_id => proxy.id, :name => name
  end
rescue => e
  ::Foreman::Logging.exception("Unable to communicate with Chef proxy", e)
  raise ::ForemanChef::ProxyException.new(N_('CLIENT Unable to communicate with Chef proxy, %s' % e.message))
end

#runObject



20
21
22
23
24
# File 'app/lib/actions/foreman_chef/client/create.rb', line 20

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