Revision c06f1783
Added by Thomas McKay over 6 years ago
lib/hammer_cli_csv/job_templates.rb | ||
---|---|---|
17 | 17 |
INPUT_TYPE = 'Input:Type' |
18 | 18 |
INPUT_PARAMETERS = 'Input:Parameters' |
19 | 19 |
|
20 |
def export |
|
21 |
CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => true}) do |csv| |
|
22 |
csv << [NAME, ORGANIZATIONS, LOCATIONS, DESCRIPTION, JOB, PROVIDER, SNIPPET, TEMPLATE, |
|
23 |
INPUT_NAME, INPUT_DESCRIPTION, INPUT_REQUIRED, INPUT_TYPE, INPUT_PARAMETERS] |
|
24 |
@api.resource(:job_templates).call(:index, { |
|
25 |
:per_page => 999999 |
|
26 |
})['results'].each do |template_id| |
|
27 |
template = @api.resource(:job_templates).call(:show, {:id => template_id['id']}) |
|
28 |
next if template['locked'] |
|
29 |
next unless option_organization.nil? || template['organizations'].detect { |org| org['name'] == option_organization } |
|
30 |
name = template['name'] |
|
31 |
description = template['description_format'] |
|
32 |
job = template['job_category'] |
|
33 |
snippet = template['snippet'] ? 'Yes' : 'No' |
|
34 |
provider = template['provider_type'] |
|
35 |
organizations = export_column(template, 'organizations', 'name') |
|
36 |
locations = export_column(template, 'locations', 'name') |
|
37 |
csv << [name, organizations, locations, description, job, provider, snippet, template['template']] |
|
20 |
def export(csv) |
|
21 |
csv << [NAME, ORGANIZATIONS, LOCATIONS, DESCRIPTION, JOB, PROVIDER, SNIPPET, TEMPLATE, |
|
22 |
INPUT_NAME, INPUT_DESCRIPTION, INPUT_REQUIRED, INPUT_TYPE, INPUT_PARAMETERS] |
|
23 |
@api.resource(:job_templates).call(:index, { |
|
24 |
:per_page => 999999 |
|
25 |
})['results'].each do |template_id| |
|
26 |
template = @api.resource(:job_templates).call(:show, {:id => template_id['id']}) |
|
27 |
next if template['locked'] |
|
28 |
next unless option_organization.nil? || template['organizations'].detect { |org| org['name'] == option_organization } |
|
29 |
name = template['name'] |
|
30 |
description = template['description_format'] |
|
31 |
job = template['job_category'] |
|
32 |
snippet = template['snippet'] ? 'Yes' : 'No' |
|
33 |
provider = template['provider_type'] |
|
34 |
organizations = export_column(template, 'organizations', 'name') |
|
35 |
locations = export_column(template, 'locations', 'name') |
|
36 |
csv << [name, organizations, locations, description, job, provider, snippet, template['template']] |
|
38 | 37 |
|
39 |
template_columns = [name] + Array.new(7) |
|
40 |
@api.resource(:template_inputs).call(:index, { |
|
41 |
:template_id => template['id'] |
|
42 |
})['results'].each do|input| |
|
43 |
input_field = nil |
|
44 |
input_options = nil |
|
45 |
case input['input_type'] |
|
46 |
when /user/ |
|
47 |
input_name = export_column(input, 'options') do |value| |
|
48 |
value |
|
49 |
end |
|
50 |
when /fact/ |
|
51 |
input_name = input['fact_name'] |
|
52 |
when /variable/ |
|
53 |
input_name = input['variable_name'] |
|
54 |
when /puppet_parameter/ |
|
55 |
input_name = "#{input['puppet_class_name']}|#{input['puppet_parameter_name']}" |
|
56 |
else |
|
57 |
raise _("Unknown job template input type '%{type}'") % {:type => input['input_type']} |
|
38 |
template_columns = [name] + Array.new(7) |
|
39 |
@api.resource(:template_inputs).call(:index, { |
|
40 |
:template_id => template['id'] |
|
41 |
})['results'].each do|input| |
|
42 |
input_field = nil |
|
43 |
input_options = nil |
|
44 |
case input['input_type'] |
|
45 |
when /user/ |
|
46 |
input_name = export_column(input, 'options') do |value| |
|
47 |
value |
|
58 | 48 |
end |
59 |
required = input['required'] ? 'Yes' : 'No' |
|
60 |
csv << template_columns + [input['name'], input['description'], required, input['input_type'], input_name] |
|
49 |
when /fact/ |
|
50 |
input_name = input['fact_name'] |
|
51 |
when /variable/ |
|
52 |
input_name = input['variable_name'] |
|
53 |
when /puppet_parameter/ |
|
54 |
input_name = "#{input['puppet_class_name']}|#{input['puppet_parameter_name']}" |
|
55 |
else |
|
56 |
raise _("Unknown job template input type '%{type}'") % {:type => input['input_type']} |
|
61 | 57 |
end |
58 |
required = input['required'] ? 'Yes' : 'No' |
|
59 |
csv << template_columns + [input['name'], input['description'], required, input['input_type'], input_name] |
|
62 | 60 |
end |
63 | 61 |
end |
64 | 62 |
end |
Also available in: Unified diff
fixes #15743 - import and export of subscriptions one-per-line