Revision c06f1783
Added by Thomas McKay over 6 years ago
lib/hammer_cli_csv/provisioning_templates.rb | ||
---|---|---|
14 | 14 |
KIND = 'Kind' |
15 | 15 |
TEMPLATE = 'Template' |
16 | 16 |
|
17 |
def export |
|
18 |
CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => true}) do |csv| |
|
19 |
csv << [NAME, ORGANIZATIONS, LOCATIONS, OPERATINGSYSTEMS, ASSOCIATIONS, KIND, TEMPLATE] |
|
20 |
params = { |
|
21 |
:per_page => 999999 |
|
22 |
} |
|
23 |
params['search'] = "organization = \"#{option_organization}\"" if option_organization |
|
24 |
@api.resource(:config_templates).call(:index, params)['results'].each do |template_id| |
|
25 |
template = @api.resource(:config_templates).call(:show, {:id => template_id['id']}) |
|
26 |
next if template['locked'] && !option_include_locked? |
|
27 |
name = template['name'] |
|
28 |
kind = template['snippet'] ? 'snippet' : template['template_kind_name'] |
|
29 |
organizations = export_column(template, 'organizations', 'name') |
|
30 |
locations = export_column(template, 'locations', 'name') |
|
31 |
operatingsystems = export_column(template, 'operatingsystems', 'fullname') |
|
32 |
# TODO: puppet environments for content views are not present in api |
|
33 |
# http://projects.theforeman.org/issues/10293 |
|
34 |
associations = export_associations(template) |
|
35 |
unless name == 'Boot disk iPXE - generic host' || name == 'Boot disk iPXE - host' |
|
36 |
csv << [name, organizations, locations, operatingsystems, associations, kind, template['template']] |
|
37 |
end |
|
17 |
def export(csv) |
|
18 |
csv << [NAME, ORGANIZATIONS, LOCATIONS, OPERATINGSYSTEMS, ASSOCIATIONS, KIND, TEMPLATE] |
|
19 |
params = { |
|
20 |
:per_page => 999999 |
|
21 |
} |
|
22 |
params['search'] = "organization = \"#{option_organization}\"" if option_organization |
|
23 |
@api.resource(:config_templates).call(:index, params)['results'].each do |template_id| |
|
24 |
template = @api.resource(:config_templates).call(:show, {:id => template_id['id']}) |
|
25 |
next if template['locked'] && !option_include_locked? |
|
26 |
name = template['name'] |
|
27 |
kind = template['snippet'] ? 'snippet' : template['template_kind_name'] |
|
28 |
organizations = export_column(template, 'organizations', 'name') |
|
29 |
locations = export_column(template, 'locations', 'name') |
|
30 |
operatingsystems = export_column(template, 'operatingsystems', 'fullname') |
|
31 |
# TODO: puppet environments for content views are not present in api |
|
32 |
# http://projects.theforeman.org/issues/10293 |
|
33 |
associations = export_associations(template) |
|
34 |
unless name == 'Boot disk iPXE - generic host' || name == 'Boot disk iPXE - host' |
|
35 |
csv << [name, organizations, locations, operatingsystems, associations, kind, template['template']] |
|
38 | 36 |
end |
39 | 37 |
end |
40 | 38 |
end |
Also available in: Unified diff
fixes #15743 - import and export of subscriptions one-per-line