def create_systems_from_csv(line)
if !@existing[line[ORGANIZATION]]
@existing[line[ORGANIZATION]] = {}
@api.resource(:systems)\
.call(:index, {
'organization_id' => line[ORGANIZATION],
'per_page' => 999999
})['results'].each do |system|
@existing[line[ORGANIZATION]][system['name']] = system['uuid'] if system
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' => line[ORGANIZATION],
'environment_id' => lifecycle_environment(line[ORGANIZATION], :name => line[ENVIRONMENT]),
'content_view_id' => lifecycle_contentview(line[ORGANIZATION], :name => line[CONTENTVIEW]),
'facts' => facts(line),
'installed_products' => products(line),
'type' => 'system'
})['uuid']
@existing[line[ORGANIZATION]][name] = system_id
else
print "Updating system '#{name}'..." if option_verbose?
puts line
system_id = @api.resource(:systems)\
.call(:update, {
'id' => @existing[line[ORGANIZATION]][name],
'name' => name,
'environment_id' => katello_environment(line[ORGANIZATION], :name => line[ENVIRONMENT]),
'content_view_id' => katello_contentview(line[ORGANIZATION], :name => line[CONTENTVIEW]),
'facts' => facts(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]]] << system_id
end
set_host_collections(system_id, line)
puts 'done' if option_verbose?
end
rescue RuntimeError => e
raise "#{e}\n #{line}"
end