def create_activationkeys_from_csv(line)
if !@existing[line[ORGANIZATION]]
@existing[line[ORGANIZATION]] = {}
@api.resource(:activation_keys)\
.call(:index, {
'per_page' => 999999,
'organization_id' => foreman_organization(:name => line[ORGANIZATION])
})['results'].each do |activationkey|
@existing[line[ORGANIZATION]][activationkey['name']] = activationkey['id'] if activationkey
end
end
line[COUNT].to_i.times do |number|
name = namify(line[NAME], number)
if !@existing[line[ORGANIZATION]].include? name
print "Creating activation key '#{name}'..." if option_verbose?
activationkey = @api.resource(:activation_keys)\
.call(:create, {
'name' => name,
'environment_id' => lifecycle_environment(line[ORGANIZATION],
:name => line[ENVIRONMENT]),
'content_view_id' => katello_contentview(line[ORGANIZATION],
:name => line[CONTENTVIEW]),
'description' => line[DESCRIPTION],
'usage_limit' => usage_limit(line[LIMIT])
})
@existing[line[ORGANIZATION]][activationkey['name']] = activationkey['id']
else
print "Updating activation key '#{name}'..." if option_verbose?
activationkey = @api.resource(:activation_keys)\
.call(:update, {
'id' => @existing[line[ORGANIZATION]][name],
'name' => name,
'environment_id' => lifecycle_environment(line[ORGANIZATION],
:name => line[ENVIRONMENT]),
'content_view_id' => katello_contentview(line[ORGANIZATION],
:name => line[CONTENTVIEW]),
'description' => line[DESCRIPTION],
'usage_limit' => usage_limit(line[LIMIT])
})
end
update_subscriptions(activationkey, line)
update_groups(activationkey, line)
puts 'done' if option_verbose?
end
end