def katello_hostcollection(organization, options = {})
@hostcollections ||= {}
@hostcollections[organization] ||= {}
if options[:name]
return nil if options[:name].nil? || options[:name].empty?
options[:id] = @hostcollections[organization][options[:name]]
if !options[:id]
@api.resource(:host_collections).call(:index,
{
:per_page => 999999,
'organization_id' => foreman_organization(:name => organization),
'search' => "name:\"#{options[:name]}\""
})['results'].each do |hostcollection|
@hostcollections[organization][hostcollection['name']] = hostcollection['id'] if hostcollection
end
options[:id] = @hostcollections[organization][options[:name]]
raise "System group '#{options[:name]}' not found" if !options[:id]
end
result = options[:id]
else
return nil if options[:id].nil?
options[:name] = @hostcollections.key(options[:id])
if !options[:name]
hostcollection = @api.resource(:host_collections).call(:show, {'id' => options[:id]})
raise "System group '#{options[:name]}' not found" if !hostcollection || hostcollection.empty?
options[:name] = hostcollection['name']
@hostcollections[options[:name]] = options[:id]
end
result = options[:name]
end
result
end