def create_hostcollections_from_csv(line)
if !@existing[line[ORGANIZATION]]
@existing[line[ORGANIZATION]] = {}
@api.resource(:host_collections)\
.call(:index, {
'per_page' => 999999,
'organization_id' => foreman_organization(:name => line[ORGANIZATION])
})['results'].each do |hostcollection|
@existing[line[ORGANIZATION]][hostcollection['name']] = hostcollection['id']
end
end
line[COUNT].to_i.times do |number|
name = namify(line[NAME], number)
if !@existing[line[ORGANIZATION]].include? name
print "Creating system group '#{name}'..." if option_verbose?
@api.resource(:host_collections)\
.call(:create, {
'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
'name' => name,
'max_systems' => (line[LIMIT] == 'Unlimited') ? -1 : line[LIMIT],
'description' => line[DESCRIPTION]
})
else
print "Updating system group '#{name}'..." if option_verbose?
@api.resource(:host_collections)\
.call(:update, {
'organization_id' => line[ORGANIZATION],
'id' => @existing[line[ORGANIZATION]][name],
'name' => name,
'max_systems' => (line[LIMIT] == 'Unlimited') ? -1 : line[LIMIT],
'description' => line[DESCRIPTION]
})
end
print "done\n" if option_verbose?
end
end