def create_contentviews_from_csv(line)
if !@existing_contentviews[line[ORGANIZATION]]
@existing_contentviews[line[ORGANIZATION]] ||= {}
@api.resource(:content_views)\
.call(:index, {
'per_page' => 999999,
'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
'nondefault' => true
})['results'].each do |contentview|
@existing_contentviews[line[ORGANIZATION]][contentview['name']] = contentview['id'] if contentview
end
end
repository_ids = collect_column(line[REPOSITORIES]) do |repository|
katello_repository(line[ORGANIZATION], :name => repository)
end
line[COUNT].to_i.times do |number|
name = namify(line[NAME], number)
composite = line[COMPOSITE] == 'Yes' ? true : false
contentview_id = @existing_contentviews[line[ORGANIZATION]][name]
if !contentview_id
print "Creating content view '#{name}'..." if option_verbose?
contentview_id = @api.resource(:content_views)\
.call(:create, {
'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
'name' => name,
'label' => labelize(name),
'description' => line[DESCRIPTION],
'composite' => composite,
'repository_ids' => repository_ids
})['id']
@existing_contentviews[line[ORGANIZATION]][name] = contentview_id
else
print "Updating content view '#{name}'..." if option_verbose?
@api.resource(:content_views)\
.call(:update, {
'id' => contentview_id,
'description' => line[DESCRIPTION],
'repository_ids' => repository_ids
})
end
puts 'done' if option_verbose?
end
rescue RuntimeError => e
raise "#{e}\n #{line}"
end