def create_systems_from_csv(line)
if !@existing[line[ORGANIZATION]]
@existing[line[ORGANIZATION]] = {}
total = @api.resource(:systems)\
.call(:index, {
'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
'per_page' => 1
})['total'].to_i
(total / 20 + 2).to_i.times do |page|
@api.resource(:systems)\
.call(:index, {
'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
'page' => page,
'per_page' => 20
})['results'].each do |system|
@existing[line[ORGANIZATION]][system['name']] = system['uuid'] if system
end
end
end
line[COUNT].to_i.times do |number|
name = namify(line[NAME], number)
if !@existing[line[ORGANIZATION]].include? name
print "Creating system '#{name}'..." if option_verbose?
system_id = @api.resource(:systems)\
.call(:create, {
'name' => name,
'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
'environment_id' => lifecycle_environment(line[ORGANIZATION], :name => line[ENVIRONMENT]),
'content_view_id' => katello_contentview(line[ORGANIZATION], :name => line[CONTENTVIEW]),
'facts' => facts(name, line),
'installed_products' => products(line)
})['uuid']
@existing[line[ORGANIZATION]][name] = system_id
else
print "Updating system '#{name}'..." if option_verbose?
system_id = @api.resource(:systems)\
.call(:update, {
'id' => @existing[line[ORGANIZATION]][name],
'system' => {
'name' => name,
'environment_id' => lifecycle_environment(line[ORGANIZATION], :name => line[ENVIRONMENT]),
'content_view_id' => katello_contentview(line[ORGANIZATION], :name => line[CONTENTVIEW]),
'facts' => facts(name, line),
'installed_products' => products(line)
}
})['uuid']
end
if line[VIRTUAL] == 'Yes' && line[HOST]
raise "Host system '#{line[HOST]}' not found" if !@existing[line[ORGANIZATION]][line[HOST]]
@host_guests[@existing[line[ORGANIZATION]][line[HOST]]] ||= []
@host_guests[@existing[line[ORGANIZATION]][line[HOST]]] << "#{line[ORGANIZATION]}/#{name}"
end
set_host_collections(system_id, line)
puts 'done' if option_verbose?
end
rescue RuntimeError => e
raise "#{e}\n #{line}"
end