hammer_cli_csv 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +5 -13
  2. data/config/cli_config.yml +9 -24
  3. data/lib/hammer_cli_csv/activation_keys.rb +220 -95
  4. data/lib/hammer_cli_csv/architectures.rb +7 -11
  5. data/lib/hammer_cli_csv/base.rb +67 -41
  6. data/lib/hammer_cli_csv/compute_profiles.rb +11 -15
  7. data/lib/hammer_cli_csv/compute_resources.rb +11 -15
  8. data/lib/hammer_cli_csv/containers.rb +10 -12
  9. data/lib/hammer_cli_csv/content_hosts.rb +285 -203
  10. data/lib/hammer_cli_csv/content_view_filters.rb +32 -36
  11. data/lib/hammer_cli_csv/content_views.rb +33 -37
  12. data/lib/hammer_cli_csv/csv.rb +17 -1
  13. data/lib/hammer_cli_csv/domains.rb +15 -19
  14. data/lib/hammer_cli_csv/export.rb +13 -5
  15. data/lib/hammer_cli_csv/host_collections.rb +20 -22
  16. data/lib/hammer_cli_csv/host_groups.rb +73 -65
  17. data/lib/hammer_cli_csv/hosts.rb +30 -34
  18. data/lib/hammer_cli_csv/import.rb +24 -10
  19. data/lib/hammer_cli_csv/installation_media.rb +74 -0
  20. data/lib/hammer_cli_csv/job_templates.rb +37 -41
  21. data/lib/hammer_cli_csv/lifecycle_environments.rb +15 -19
  22. data/lib/hammer_cli_csv/locations.rb +4 -6
  23. data/lib/hammer_cli_csv/operating_systems.rb +17 -21
  24. data/lib/hammer_cli_csv/organizations.rb +11 -13
  25. data/lib/hammer_cli_csv/partition_tables.rb +17 -21
  26. data/lib/hammer_cli_csv/products.rb +200 -92
  27. data/lib/hammer_cli_csv/provisioning_templates.rb +19 -23
  28. data/lib/hammer_cli_csv/puppet_environments.rb +8 -12
  29. data/lib/hammer_cli_csv/puppet_facts.rb +20 -24
  30. data/lib/hammer_cli_csv/puppet_reports.rb +47 -51
  31. data/lib/hammer_cli_csv/reports.rb +6 -10
  32. data/lib/hammer_cli_csv/roles.rb +12 -16
  33. data/lib/hammer_cli_csv/settings.rb +8 -6
  34. data/lib/hammer_cli_csv/smart_proxies.rb +9 -13
  35. data/lib/hammer_cli_csv/splice.rb +1 -3
  36. data/lib/hammer_cli_csv/subnets.rb +24 -28
  37. data/lib/hammer_cli_csv/subscriptions.rb +39 -91
  38. data/lib/hammer_cli_csv/sync_plans.rb +20 -24
  39. data/lib/hammer_cli_csv/users.rb +25 -29
  40. data/lib/hammer_cli_csv/utils/subscriptions.rb +130 -0
  41. data/lib/hammer_cli_csv/version.rb +1 -1
  42. data/lib/hammer_cli_csv.rb +2 -2
  43. data/test/csv_test.rb +32 -0
  44. data/test/csv_test_helper.rb +17 -2
  45. data/test/data/content-hosts.csv +3 -2
  46. data/test/data/hosts.csv +0 -11
  47. data/test/data/settings.csv +1 -0
  48. data/test/data/setup/content-hosts.csv +1 -0
  49. data/test/data/setup/content-views.csv +2 -0
  50. data/test/data/setup/lifecycle-environments.csv +5 -0
  51. data/test/data/setup/locations.csv +6 -0
  52. data/test/data/setup/organizations.csv +2 -0
  53. data/test/data/setup/subscriptions.csv +5 -0
  54. data/test/data/subscriptions.csv +15 -17
  55. data/test/export_test.rb +27 -0
  56. data/test/fixtures/vcr_cassettes/apipie.yml +18528 -0
  57. data/test/fixtures/vcr_cassettes/resources/activation_keys_import/create_and_update.yml +38033 -0
  58. data/test/fixtures/vcr_cassettes/resources/content_hosts_export/export.yml +18846 -0
  59. data/test/fixtures/vcr_cassettes/resources/content_hosts_export/export_subscriptions.yml +323 -0
  60. data/test/fixtures/vcr_cassettes/resources/content_hosts_import/create_and_update.yml +41884 -0
  61. data/test/fixtures/vcr_cassettes/resources/content_hosts_import/import_single_line.yml +38248 -0
  62. data/test/fixtures/vcr_cassettes/resources/settings_import/update_settings.yml +18832 -0
  63. data/test/fixtures/vcr_cassettes/resources/settings_import/update_settings_continue.yml +316 -0
  64. data/test/fixtures/vcr_cassettes/resources/subscriptions_import/manifest_does_not_exist.yml +18785 -0
  65. data/test/fixtures/vcr_cassettes/setup/setup_content_views/setup.yml +19090 -0
  66. data/test/fixtures/vcr_cassettes/setup/setup_lifecycle_environments/setup.yml +924 -0
  67. data/test/fixtures/vcr_cassettes/setup/setup_locations/setup.yml +21102 -0
  68. data/test/fixtures/vcr_cassettes/setup/setup_organizations/setup.yml +19278 -0
  69. data/test/fixtures/vcr_cassettes/setup/setup_subscriptions/setup.yml +419 -0
  70. data/test/import_test.rb +20 -25
  71. data/test/resources/activation_keys_test.rb +72 -0
  72. data/test/resources/content_hosts_test.rb +132 -0
  73. data/test/resources/settings_test.rb +81 -0
  74. data/test/resources/subscriptions_test.rb +56 -0
  75. data/test/setup/setup_content_views.rb +17 -0
  76. data/test/setup/setup_lifecycle_environments.rb +17 -0
  77. data/test/setup/setup_locations.rb +17 -0
  78. data/test/setup/setup_organizations.rb +17 -0
  79. data/test/setup/setup_subscriptions.rb +20 -0
  80. data/test/setup/setup_test.rb +10 -0
  81. data/test/test_runner.rb +175 -0
  82. data/test/vcr_setup.rb +54 -0
  83. metadata +77 -13
  84. data/lib/hammer_cli_csv/exception_handler.rb +0 -42
  85. data/lib/hammer_cli_csv/installation_medias.rb +0 -77
  86. data/test/content_hosts_test.rb +0 -61
  87. data/test/settings_test.rb +0 -30
@@ -6,21 +6,32 @@ module HammerCLICsv
6
6
  command_name 'import'
7
7
  desc 'import by directory'
8
8
 
9
+ def self.supported?
10
+ true
11
+ end
12
+
9
13
  option %w(-v --verbose), :flag, _('be verbose')
10
14
  option %w(--threads), 'THREAD_COUNT', _('Number of threads to hammer with'),
11
15
  :default => 1, :hidden => true
12
16
  option '--dir', 'DIRECTORY', _('directory to import from')
13
17
  option %w(--organization), 'ORGANIZATION', _('Only process organization matching this name')
14
- option %w(--prefix), 'PREFIX', _('Prefix for all name columns')
18
+ option %w(--prefix), 'PREFIX', _('Prefix for all name columns'),
19
+ :hidden => true
15
20
 
16
- RESOURCES = %w( settings organizations locations puppet_environments operating_systems
17
- domains architectures partition_tables lifecycle_environments host_collections
18
- provisioning_templates
19
- subscriptions products content_views content_view_filters activation_keys
20
- hosts content_hosts smart_proxies compute_resources reports roles users )
21
+ RESOURCES = %w(
22
+ settings organizations locations puppet_environments operating_systems
23
+ domains architectures partition_tables lifecycle_environments host_collections
24
+ provisioning_templates
25
+ subscriptions products content_views content_view_filters activation_keys
26
+ hosts content_hosts smart_proxies compute_resources reports roles users
27
+ )
28
+ SUPPORTED_RESOURCES = %w(
29
+ settings
30
+ )
21
31
  RESOURCES.each do |resource|
22
32
  dashed = resource.gsub('_', '-')
23
- option "--#{dashed}", 'FILE', "csv file for #{dashed}"
33
+ option "--#{dashed}", 'FILE', "csv file for #{dashed}",
34
+ :hidden => !SUPPORTED_RESOURCES.include?(resource)
24
35
  end
25
36
 
26
37
  def execute
@@ -67,15 +78,18 @@ module HammerCLICsv
67
78
 
68
79
  def hammer_resource(resource)
69
80
  return if !self.send("option_#{resource}") && !option_dir
70
- options_file = "#{option_dir}/#{resource.gsub('_', '-')}.csv" || self.send("option_#{resource}")
81
+ options_file = option_dir ? "#{option_dir}/#{resource.gsub('_', '-')}.csv" : self.send("option_#{resource}")
71
82
  unless options_file_exists? options_file
72
83
  if option_dir
73
- puts _("Skipping #{resource} because '#{options_file}' does not exist") if option_verbose?
84
+ return unless SUPPORTED_RESOURCES.include?(resource)
85
+ puts _("Skipping %{resource} because '%{options_file}' does not exist") %
86
+ {:resource => resource, :options_file => options_file} if option_verbose?
74
87
  return
75
88
  end
76
89
  raise "File for #{resource} '#{options_file}' does not exist"
77
90
  end
78
- puts _("Importing #{resource} from '#{options_file}'") if option_verbose?
91
+ puts _("Importing %{resource} from '%{options_file}'") %
92
+ {:resource => resource, :options_file => options_file} if option_verbose?
79
93
 
80
94
  args = %W( csv #{resource.gsub('_', '-')} --file #{options_file} )
81
95
  args << '-v' if option_verbose?
@@ -0,0 +1,74 @@
1
+ module HammerCLICsv
2
+ class CsvCommand
3
+ class InstallationMediaCommand < BaseCommand
4
+ command_name 'installation-media'
5
+ desc 'import or export media'
6
+
7
+ ORGANIZATIONS = 'Organizations'
8
+ LOCATIONS = 'Locations'
9
+ PATH = 'Path'
10
+ OSFAMILY = 'OS Family'
11
+ OPERATING_SYSTEMS = 'Operating Systems'
12
+
13
+ def export(csv)
14
+ csv << [NAME, ORGANIZATIONS, LOCATIONS, PATH, OSFAMILY, OPERATING_SYSTEMS]
15
+ @api.resource(:media).call(:index, {:per_page => 999999})['results'].each do |medium|
16
+ medium = @api.resource(:media).call(:show, :id => medium['id'])
17
+ name = medium['name']
18
+ organizations = export_column(medium, 'organizations', 'name')
19
+ locations = export_column(medium, 'locations', 'name')
20
+ count = 1
21
+ path = medium['path']
22
+ os_family = medium['os_family']
23
+ operating_systems = export_column(medium, 'operatingsystems', 'title')
24
+ csv << [name, organizations, locations, path, os_family, operating_systems]
25
+ end
26
+ end
27
+
28
+ def import
29
+ @existing = {}
30
+ @api.resource(:media).call(:index, {:per_page => 999999})['results'].each do |medium|
31
+ @existing[medium['name']] = medium['id'] if medium
32
+ end
33
+
34
+ thread_import do |line|
35
+ create_from_csv(line)
36
+ end
37
+ end
38
+
39
+ def create_from_csv(line)
40
+ params = {
41
+ 'medium' => {
42
+ 'organization_ids' => collect_column(line[ORGANIZATIONS]) do |organization|
43
+ foreman_organization(:name => organization)
44
+ end,
45
+ 'location_ids' => collect_column(line[LOCATIONS]) do |location|
46
+ foreman_location(:name => location)
47
+ end,
48
+ 'path' => line[PATH],
49
+ 'os_family' => line[OSFAMILY],
50
+ 'operatingsystem_ids' => collect_column(line[OPERATING_SYSTEMS]) do |os|
51
+ foreman_operatingsystem(:name => os)
52
+ end
53
+ }
54
+ }
55
+
56
+ count(line[COUNT]).times do |number|
57
+ name = namify(line[NAME], number)
58
+ params['medium']['name'] = name
59
+
60
+ if !@existing.include? name
61
+ print _("Creating installation medium '%{name}'... ") % {:name => name} if option_verbose?
62
+ medium = @api.resource(:media).call(:create, params)
63
+ @existing[name] = medium['id']
64
+ else
65
+ print _("Updating installation medium '%{name}'... ") % {:name => name} if option_verbose?
66
+ params['id'] = @existing[name]
67
+ medium = @api.resource(:media).call(:update, params)
68
+ end
69
+ puts _('done') if option_verbose?
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -17,48 +17,46 @@ module HammerCLICsv
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
@@ -138,8 +136,6 @@ module HammerCLICsv
138
136
  # end
139
137
 
140
138
  end
141
- rescue RuntimeError => e
142
- raise "#{e}\n #{line[NAME]}"
143
139
  end
144
140
 
145
141
  def create_template(line, number)
@@ -8,24 +8,22 @@ module HammerCLICsv
8
8
  PRIORENVIRONMENT = 'Prior Environment'
9
9
  DESCRIPTION = 'Description'
10
10
 
11
- def export
12
- CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => true}) do |csv|
13
- csv << [NAME, ORGANIZATION, PRIORENVIRONMENT, DESCRIPTION]
14
- @api.resource(:organizations).call(:index, {
15
- 'per_page' => 999999
16
- })['results'].each do |organization|
17
- next if option_organization && organization['name'] != option_organization
11
+ def export(csv)
12
+ csv << [NAME, ORGANIZATION, PRIORENVIRONMENT, DESCRIPTION]
13
+ @api.resource(:organizations).call(:index, {
14
+ 'per_page' => 999999
15
+ })['results'].each do |organization|
16
+ next if option_organization && organization['name'] != option_organization
18
17
 
19
- @api.resource(:lifecycle_environments).call(:index, {
20
- 'per_page' => 999999,
21
- 'organization_id' => organization['id']
22
- })['results'].sort { |a, b| a['created_at'] <=> b['created_at'] }.each do |environment|
23
- if environment['name'] != 'Library'
24
- name = environment['name']
25
- prior = environment['prior']['name']
26
- description = environment['description']
27
- csv << [name, organization['name'], prior, description]
28
- end
18
+ @api.resource(:lifecycle_environments).call(:index, {
19
+ 'per_page' => 999999,
20
+ 'organization_id' => organization['id']
21
+ })['results'].sort { |a, b| a['created_at'] <=> b['created_at'] }.each do |environment|
22
+ if environment['name'] != 'Library'
23
+ name = environment['name']
24
+ prior = environment['prior']['name']
25
+ description = environment['description']
26
+ csv << [name, organization['name'], prior, description]
29
27
  end
30
28
  end
31
29
  end
@@ -76,8 +74,6 @@ module HammerCLICsv
76
74
  end
77
75
  print "done\n" if option_verbose?
78
76
  end
79
- rescue RuntimeError => e
80
- raise "#{e}\n #{line}"
81
77
  end
82
78
  end
83
79
  end
@@ -6,12 +6,10 @@ module HammerCLICsv
6
6
 
7
7
  PARENT = 'Parent Location'
8
8
 
9
- def export
10
- CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => true}) do |csv|
11
- csv << [NAME, PARENT]
12
- @api.resource(:locations).call(:index, {:per_page => 999999})['results'].each do |location|
13
- csv << [location['name'], '']
14
- end
9
+ def export(csv)
10
+ csv << [NAME, PARENT]
11
+ @api.resource(:locations).call(:index, {:per_page => 999999})['results'].each do |location|
12
+ csv << [location['name'], '']
15
13
  end
16
14
  end
17
15
 
@@ -13,26 +13,24 @@ module HammerCLICsv
13
13
  PROVISIONING_TEMPLATES = 'Provisioning Templates'
14
14
  PARAMETERS = 'Parameters'
15
15
 
16
- def export
17
- CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => true}) do |csv|
18
- csv << [NAME, DESCRIPTION, FAMILY, PASSWORD_HASH, PARTITION_TABLES, ARCHITECTURES, MEDIA,
19
- PROVISIONING_TEMPLATES, PARAMETERS]
20
- @api.resource(:operatingsystems).call(:index, {:per_page => 999999})['results'].each do |operatingsystem_id|
21
- operatingsystem = @api.resource(:operatingsystems).call(:show, {:id => operatingsystem_id['id']})
22
- name = build_os_name(operatingsystem['name'], operatingsystem['major'], operatingsystem['minor'])
23
- description = operatingsystem['description']
24
- family = operatingsystem['family']
25
- password_hash = operatingsystem['password_hash']
26
- partition_tables = export_column(operatingsystem, 'ptables', 'name')
27
- architectures = export_column(operatingsystem, 'architectures', 'name')
28
- media = export_column(operatingsystem, 'media', 'name')
29
- partition_tables = export_column(operatingsystem, 'ptables', 'name')
30
- parameters = export_column(operatingsystem, 'parameters') do |parameter|
31
- "#{parameter['name']}|#{parameter['value']}"
32
- end
33
- csv << [name, description, family, password_hash, partition_tables, architectures,
34
- media, partition_tables, parameters]
16
+ def export(csv)
17
+ csv << [NAME, DESCRIPTION, FAMILY, PASSWORD_HASH, PARTITION_TABLES, ARCHITECTURES, MEDIA,
18
+ PROVISIONING_TEMPLATES, PARAMETERS]
19
+ @api.resource(:operatingsystems).call(:index, {:per_page => 999999})['results'].each do |operatingsystem_id|
20
+ operatingsystem = @api.resource(:operatingsystems).call(:show, {:id => operatingsystem_id['id']})
21
+ name = build_os_name(operatingsystem['name'], operatingsystem['major'], operatingsystem['minor'])
22
+ description = operatingsystem['description']
23
+ family = operatingsystem['family']
24
+ password_hash = operatingsystem['password_hash']
25
+ partition_tables = export_column(operatingsystem, 'ptables', 'name')
26
+ architectures = export_column(operatingsystem, 'architectures', 'name')
27
+ media = export_column(operatingsystem, 'media', 'name')
28
+ partition_tables = export_column(operatingsystem, 'ptables', 'name')
29
+ parameters = export_column(operatingsystem, 'parameters') do |parameter|
30
+ "#{parameter['name']}|#{parameter['value']}"
35
31
  end
32
+ csv << [name, description, family, password_hash, partition_tables, architectures,
33
+ media, partition_tables, parameters]
36
34
  end
37
35
  end
38
36
 
@@ -82,8 +80,6 @@ module HammerCLICsv
82
80
  end
83
81
  print "done\n" if option_verbose?
84
82
  end
85
- rescue RuntimeError => e
86
- raise "#{e}\n #{line}"
87
83
  end
88
84
  end
89
85
  end
@@ -7,20 +7,18 @@ module HammerCLICsv
7
7
  LABEL = 'Label'
8
8
  DESCRIPTION = 'Description'
9
9
 
10
- def export
11
- CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => true}) do |csv|
12
- csv << [NAME, LABEL, DESCRIPTION]
10
+ def export(csv)
11
+ csv << [NAME, LABEL, DESCRIPTION]
13
12
 
14
- if @server_status['release'] == 'Headpin'
15
- @headpin.get(:organizations).each do |organization|
16
- next if option_organization && organization['name'] != option_organization
17
- csv << [organization['name'], organization['label'], organization['description']]
18
- end
19
- else
20
- @api.resource(:organizations).call(:index, {:per_page => 999999})['results'].each do |organization|
21
- next if option_organization && organization['name'] != option_organization
22
- csv << [organization['name'], organization['label'], organization['description']]
23
- end
13
+ if @server_status['release'] == 'Headpin'
14
+ @headpin.get(:organizations).each do |organization|
15
+ next if option_organization && organization['name'] != option_organization
16
+ csv << [organization['name'], organization['label'], organization['description']]
17
+ end
18
+ else
19
+ @api.resource(:organizations).call(:index, {:per_page => 999999})['results'].each do |organization|
20
+ next if option_organization && organization['name'] != option_organization
21
+ csv << [organization['name'], organization['label'], organization['description']]
24
22
  end
25
23
  end
26
24
  end
@@ -10,7 +10,7 @@ module HammerCLICsv
10
10
  OPERATINGSYSTEMS = 'Operating Systems'
11
11
  LAYOUT = 'Layout'
12
12
 
13
- def export
13
+ def export(csv)
14
14
  # TODO: partition-tables do not return their organizations or locations
15
15
  # http://projects.theforeman.org/issues/11175
16
16
  organizations_map = {}
@@ -28,26 +28,24 @@ module HammerCLICsv
28
28
  end
29
29
  end
30
30
 
31
- CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => true}) do |csv|
32
- csv << [NAME, ORGANIZATIONS, LOCATIONS, OSFAMILY, OPERATINGSYSTEMS, LAYOUT]
33
- @api.resource(:ptables).call(:index, {:per_page => 999999})['results'].each do |ptable|
34
- ptable = @api.resource(:ptables).call(:show, {'id' => ptable['id']})
35
- name = ptable['name']
36
- osfamily = ptable['os_family']
37
- layout = ptable['layout']
38
- operatingsystems = export_column(ptable, 'operatingsystems', 'title')
39
-
40
- organizations = CSV.generate do |column|
41
- column << organizations_map[name] if organizations_map[name]
42
- end
43
- organizations.delete!("\n")
44
- locations = CSV.generate do |column|
45
- column << locations_map[name] if locations_map[name]
46
- end
47
- locations.delete!("\n")
31
+ csv << [NAME, ORGANIZATIONS, LOCATIONS, OSFAMILY, OPERATINGSYSTEMS, LAYOUT]
32
+ @api.resource(:ptables).call(:index, {:per_page => 999999})['results'].each do |ptable|
33
+ ptable = @api.resource(:ptables).call(:show, {'id' => ptable['id']})
34
+ name = ptable['name']
35
+ osfamily = ptable['os_family']
36
+ layout = ptable['layout']
37
+ operatingsystems = export_column(ptable, 'operatingsystems', 'title')
48
38
 
49
- csv << [name, organizations, locations, osfamily, operatingsystems, layout]
39
+ organizations = CSV.generate do |column|
40
+ column << organizations_map[name] if organizations_map[name]
50
41
  end
42
+ organizations.delete!("\n")
43
+ locations = CSV.generate do |column|
44
+ column << locations_map[name] if locations_map[name]
45
+ end
46
+ locations.delete!("\n")
47
+
48
+ csv << [name, organizations, locations, osfamily, operatingsystems, layout]
51
49
  end
52
50
  end
53
51
 
@@ -102,8 +100,6 @@ module HammerCLICsv
102
100
  end
103
101
  print "done\n" if option_verbose?
104
102
  end
105
- rescue RuntimeError => e
106
- raise "#{e}\n #{line}"
107
103
  end
108
104
  end
109
105
  end