Class: HammerCLICsv::CsvCommand::HostCollectionsCommand
- Inherits:
-
BaseCommand
- Object
- HammerCLI::Apipie::Command
- BaseCommand
- HammerCLICsv::CsvCommand::HostCollectionsCommand
show all
- Defined in:
- lib/hammer_cli_csv/host_collections.rb
Constant Summary
collapse
- ORGANIZATION =
'Organization'
- LIMIT =
'Limit'
- DESCRIPTION =
'Description'
Constants inherited
from BaseCommand
BaseCommand::COUNT, BaseCommand::NAME
Instance Method Summary
collapse
Methods inherited from BaseCommand
#apipie_check_param, #associate_locations, #associate_organizations, #authenticate_request, #build_os_name, #check_server_status, #collect_column, #count, #execute, #export_column, #foreman_architecture, #foreman_container, #foreman_domain, #foreman_environment, #foreman_filter, #foreman_host, #foreman_hostgroup, #foreman_location, #foreman_medium, #foreman_operatingsystem, #foreman_organization, #foreman_partitiontable, #foreman_permission, #foreman_provisioning_template, #foreman_role, #foreman_smart_proxy, #foreman_template_kind, #hammer, #hammer_context, #help, help_columns, #katello_contentview, #katello_contentviewversion, #katello_hostcollection, #katello_product, #katello_repository, #labelize, #lifecycle_environment, #namify, #pluralize, #split_os_name, #supported?, supported?, #thread_import
#api_connection
Instance Method Details
#create_hostcollections_from_csv(line) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/hammer_cli_csv/host_collections.rb', line 35
def create_hostcollections_from_csv(line)
return if option_organization && line[ORGANIZATION] != option_organization
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
count(line[COUNT]).times do |number|
name = namify(line[NAME], number)
params = {
'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
'name' => name,
'unlimited_content_hosts' => (line[LIMIT] == 'Unlimited') ? true : false,
'max_content_hosts' => (line[LIMIT] == 'Unlimited') ? nil : line[LIMIT].to_i,
'description' => line[DESCRIPTION]
}
if !@existing[line[ORGANIZATION]].include? name
print "Creating host collection '#{name}'..." if option_verbose?
@api.resource(:host_collections).call(:create, params)
else
print "Updating host collection '#{name}'..." if option_verbose?
params['id'] = @existing[line[ORGANIZATION]][name]
@api.resource(:host_collections).call(:update, params)
end
print "done\n" if option_verbose?
end
end
|
#export(csv) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/hammer_cli_csv/host_collections.rb', line 11
def export(csv)
csv << [NAME, ORGANIZATION, LIMIT, DESCRIPTION]
@api.resource(:organizations).call(:index, {'per_page' => 999999})['results'].each do |organization|
next if option_organization && organization['name'] != option_organization
@api.resource(:host_collections).call(:index, {
'organization_id' => organization['id'],
'search' => option_search
})['results'].each do |hostcollection|
limit = hostcollection['unlimited_content_hosts'] ? 'Unlimited' : hostcollection['max_content_hosts']
csv << [hostcollection['name'], organization['name'],
limit,
hostcollection['description']]
end
end
end
|
#import ⇒ Object
27
28
29
30
31
32
33
|
# File 'lib/hammer_cli_csv/host_collections.rb', line 27
def import
@existing = {}
thread_import do |line|
create_hostcollections_from_csv(line)
end
end
|