hammer_cli_csv 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -9,33 +9,40 @@ module HammerCLICsv
9
9
  ORGANIZATION = 'Organization'
10
10
  REPOSITORY = 'Repository'
11
11
  REPOSITORY_TYPE = 'Repository Type'
12
+ CONTENT_SET = 'Content Set'
13
+ RELEASE = 'Release'
12
14
  REPOSITORY_URL = 'Repository Url'
13
15
  DESCRIPTION = 'Description'
14
16
 
15
- def export
16
- CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => false}) do |csv|
17
- csv << [NAME, LABEL, ORGANIZATION, DESCRIPTION, REPOSITORY, REPOSITORY_TYPE,
18
- REPOSITORY_URL]
19
- @api.resource(:organizations).call(:index, {
20
- :per_page => 999999
21
- })['results'].each do |organization|
22
- next if option_organization && organization['name'] != option_organization
23
- @api.resource(:products).call(:index, {
24
- 'per_page' => 999999,
25
- 'enabled' => true,
17
+ def export(csv)
18
+ csv << [NAME, LABEL, ORGANIZATION, DESCRIPTION, REPOSITORY, REPOSITORY_TYPE,
19
+ CONTENT_SET, RELEASE, REPOSITORY_URL]
20
+ # TODO: DOWNLOAD_POLICY
21
+ @api.resource(:organizations).call(:index, {
22
+ :per_page => 999999
23
+ })['results'].each do |organization|
24
+ next if option_organization && organization['name'] != option_organization
25
+ @api.resource(:products).call(:index, {
26
+ 'per_page' => 999999,
27
+ 'enabled' => true,
28
+ 'organization_id' => organization['id']
29
+ })['results'].each do |product|
30
+ @api.resource(:repositories).call(:index, {
31
+ 'product_id' => product['id'],
26
32
  'organization_id' => organization['id']
27
- })['results'].each do |product|
28
- @api.resource(:repositories).call(:index, {
29
- 'product_id' => product['id'],
30
- 'organization_id' => organization['id']
31
- })['results'].each do |repository|
32
- repository = @api.resource(:repositories).call(:show, {:id => repository['id']})
33
- repository_type = repository['product_type'] == 'custom' ? 'Custom' : 'Red Hat'
34
- repository_type += " #{repository['content_type'].capitalize}"
35
- csv << [product['name'], product['label'], organization['name'],
36
- product['description'], repository['name'], repository_type,
37
- repository['url']]
33
+ })['results'].each do |repository|
34
+ repository = @api.resource(:repositories).call(:show, {:id => repository['id']})
35
+ if repository['product_type'] == 'custom'
36
+ repository_type = "Custom #{repository['content_type'].capitalize}"
37
+ content_set = nil
38
+ else
39
+ repository_type = "Red Hat #{repository['content_type'].capitalize}"
40
+ content_set = get_content_set(organization, product, repository)
38
41
  end
42
+ release = repository['minor'] #=~ /Server/ ? repository['minor'] : "#{repository['major']}.#{repository['minor']}"
43
+ csv << [product['name'], product['label'], organization['name'],
44
+ product['description'], repository['name'], repository_type,
45
+ content_set, release, repository['url']]
39
46
  end
40
47
  end
41
48
  end
@@ -50,99 +57,177 @@ module HammerCLICsv
50
57
  end
51
58
  end
52
59
 
53
- # FIXME: TODO remove this rubocop
54
- # rubocop:disable CyclomaticComplexity
55
60
  def create_products_from_csv(line)
56
61
  return if option_organization && line[ORGANIZATION] != option_organization
57
62
 
58
- if !@existing_products[line[ORGANIZATION]]
59
- @existing_products[line[ORGANIZATION]] = {}
60
- @api.resource(:products).call(:index, {
61
- 'per_page' => 999999,
62
- 'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
63
- 'enabled' => true
64
- })['results'].each do |product|
65
- @existing_products[line[ORGANIZATION]][product['name']] = product['id']
63
+ count(line[COUNT]).times do |number|
64
+ product = create_or_update_product(line, number)
65
+ create_or_update_repository(line, number, product)
66
+ puts _('done') if option_verbose?
67
+ end
66
68
 
67
- @api.resource(:repositories).call(:index, {
68
- 'page_size' => 999999, 'paged' => true,
69
- 'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
70
- 'product_id' => product['id'],
71
- 'enabled' => true,
72
- 'library' => true
73
- })['results'].each do |repository|
74
- @existing_repositories[line[ORGANIZATION] + product['name']] ||= {}
75
- @existing_repositories[line[ORGANIZATION] + product['name']][repository['label']] = repository['id']
76
- end
77
- end
69
+ end
70
+
71
+ private
72
+
73
+ def create_or_update_product(line, number)
74
+ if !@existing_products[line[ORGANIZATION]]
75
+ get_existing_products(line)
78
76
  end
79
77
 
80
- count(line[COUNT]).times do |number|
81
- name = namify(line[NAME], number)
78
+ product_name = namify(line[NAME], number)
79
+ if line[REPOSITORY_TYPE] =~ /Red Hat/
80
+ product = enable_red_hat_product(line, product_name)
81
+ else
82
+ # TODO: product label? other?
82
83
  params = {
83
- :name => name,
84
+ :name => product_name,
84
85
  'organization_id' => foreman_organization(:name => line[ORGANIZATION])
85
86
  }
86
87
  params[:description] = line[DESCRIPTION] if !line[DESCRIPTION].nil? &&
87
88
  !line[DESCRIPTION].empty?
88
- product_id = @existing_products[line[ORGANIZATION]][name]
89
- if product_id.nil?
90
- print _("Creating product '%{name}'...") % {:name => name} if option_verbose?
91
- if line[REPOSITORY_TYPE] =~ /Red Hat/
92
- raise _("Red Hat product '%{name}' does not exist in '%{organization}'") %
93
- {:name => name, :organization => line[ORGANIZATION]}
94
- end
95
-
96
- product_id = @api.resource(:products).call(:create, params)['id']
97
- @existing_products[line[ORGANIZATION]][name] = product_id
89
+ product = @existing_products[line[ORGANIZATION]][product_name]
90
+ if product.nil?
91
+ print _("Creating product '%{name}'...") % {:name => product_name} if option_verbose?
92
+ product = @api.resource(:products).call(:create, params)
93
+ @existing_products[line[ORGANIZATION]][product_name] = product
98
94
  else
99
- print _("Updating product '%{name}'...") % {:name => name} if option_verbose?
100
- params[:id] = product_id
95
+ print _("Updating product '%{name}'...") % {:name => product_name} if option_verbose?
96
+ params[:id] = product['id']
101
97
  @api.resource(:products).call(:update, params)
102
98
  end
103
- @existing_repositories[line[ORGANIZATION] + name] = {}
99
+ end
104
100
 
105
- repository_name = namify(line[REPOSITORY], number)
101
+ return product
102
+ end
106
103
 
107
- if !@existing_repositories[line[ORGANIZATION] + name][repository_name]
108
- @api.resource(:repositories).call(:index, {
109
- 'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
110
- 'library' => true,
111
- 'all' => false,
112
- 'product_id' => product_id
113
- })['results'].each do |repository|
114
- @existing_repositories[line[ORGANIZATION] + name][repository['name']] = repository
115
- end
104
+ def create_or_update_repository(line, number, product)
105
+ repository_name = namify(line[REPOSITORY], number)
106
+ repository = get_repository(line, product['name'], product['id'], repository_name)
107
+ if !repository
108
+ if line[REPOSITORY_TYPE] =~ /Red Hat/
109
+ raise _("Red Hat product '%{product_name}' does not have repository '%{repository_name}'") %
110
+ {:product_name => product['name'], :repository_name => repository_name}
116
111
  end
117
112
 
118
- repository = @existing_repositories[line[ORGANIZATION] + name][repository_name]
119
- if !repository
120
- raise "Red Hat product '#{name}' does not have repository '#{repository_name}'" if line[REPOSITORY_TYPE] =~ /Red Hat/
113
+ if option_verbose?
114
+ print _("Creating repository '%{repository_name}' in product '%{product_name}'...") %
115
+ {:repository_name => repository_name, :product_name => product['name']}
116
+ end
117
+ # TODO: add repo label column (optional)
118
+ repository = @api.resource(:repositories).call(:create, {
119
+ 'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
120
+ 'name' => repository_name,
121
+ 'label' => labelize(repository_name),
122
+ 'product_id' => product['id'],
123
+ 'url' => line[REPOSITORY_URL],
124
+ 'content_type' => content_type(line[REPOSITORY_TYPE])
125
+ })
126
+ @existing_repositories[line[ORGANIZATION] + product['name']][line[LABEL]] = repository
127
+ else
128
+ # TODO: update url
129
+ end
121
130
 
122
- if option_verbose?
123
- print _("Creating repository '%{repository_name}' in product '%{name}'...") %
124
- {:repository_name => repository_name, :name => name}
125
- end
126
- repository = @api.resource(:repositories).call(:create, {
127
- 'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
128
- 'name' => repository_name,
129
- 'label' => labelize(repository_name),
130
- 'product_id' => product_id,
131
- 'url' => line[REPOSITORY_URL],
132
- 'content_type' => content_type(line[REPOSITORY_TYPE])
133
- })
134
- @existing_repositories[line[ORGANIZATION] + name][line[LABEL]] = repository
131
+ sync_repository(line, product['name'], repository)
132
+ end
133
+
134
+ def get_existing_products(line)
135
+ @existing_products[line[ORGANIZATION]] = {}
136
+ @api.resource(:products).call(:index, {
137
+ 'per_page' => 999999,
138
+ 'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
139
+ 'enabled' => true
140
+ })['results'].each do |product|
141
+ @existing_products[line[ORGANIZATION]][product['name']] = product
142
+
143
+ @api.resource(:repositories).call(:index, {
144
+ 'page_size' => 999999, 'paged' => true,
145
+ 'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
146
+ 'product_id' => product['id'],
147
+ 'enabled' => true,
148
+ 'library' => true
149
+ })['results'].each do |repository|
150
+ @existing_repositories[line[ORGANIZATION] + product['name']] ||= {}
151
+ @existing_repositories[line[ORGANIZATION] + product['name']][repository['label']] = repository['id']
135
152
  end
153
+ end
154
+ end
136
155
 
137
- sync_repository(line, name, repository)
138
- puts _('done') if option_verbose?
156
+ def get_repository(line, product_name, product_id, repository_name)
157
+ @existing_repositories[line[ORGANIZATION] + product_name] ||= {}
158
+ if !@existing_repositories[line[ORGANIZATION] + product_name][repository_name]
159
+ @api.resource(:repositories).call(:index, {
160
+ 'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
161
+ 'library' => true,
162
+ 'all' => false,
163
+ 'product_id' => product_id
164
+ })['results'].each do |repository|
165
+ @existing_repositories[line[ORGANIZATION] + product_name][repository['name']] = repository
166
+ end
139
167
  end
168
+ @existing_repositories[line[ORGANIZATION] + product_name][repository_name]
169
+ end
170
+
171
+ def enable_red_hat_product(line, product_name)
172
+ product = @existing_products[line[ORGANIZATION]][product_name]
173
+ unless product
174
+ product = @api.resource(:products).call(:index, {
175
+ 'per_page' => 999999,
176
+ 'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
177
+ 'name' => product_name
178
+ })['results'][0]
179
+ raise _("Red Hat product '%{product_name}' does not exist") %
180
+ {:product_name => product_name} if product.nil?
181
+ @existing_repositories[line[ORGANIZATION] + product['name']] = {}
182
+ end
183
+ product = @api.resource(:products).call(:show, {:id => product['id']})
140
184
 
141
- rescue RuntimeError => e
142
- raise "#{e}\n #{line}"
185
+ results = @api.resource(:repository_sets).call(:index, {
186
+ 'per_page' => 999999,
187
+ 'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
188
+ 'product_id' => product['id'],
189
+ 'name' => line[CONTENT_SET]
190
+ })['results']
191
+ raise "No match for content set '#{line[CONTENT_SET]}'" if results.length == 0
192
+ raise "Multiple matches for content set '#{line[CONTENT_SET]}'" if results.length != 1
193
+ repository_set = results[0]
194
+
195
+ repository = repository_set['repositories'].find do |repo|
196
+ repo['name'] == line[REPOSITORY]
197
+ end
198
+
199
+ if repository.nil?
200
+ print _('Enabling repository %{name}...') % {:name => line[REPOSITORY]} if option_verbose?
201
+ product_content = product['product_content'].find do |content|
202
+ content['content']['name'] == line[CONTENT_SET]
203
+ end
204
+ raise "No match for content set '#{line[CONTENT_SET]}'" if !product_content
205
+
206
+ basearch,releasever = parse_basearch_releasever(line[REPOSITORY])
207
+ params = {
208
+ 'id' => product_content['content']['id'],
209
+ 'product_id' => product['id'],
210
+ 'basearch' => basearch,
211
+ 'releasever' => releasever
212
+ }
213
+ @api.resource(:repository_sets).call(:enable, params)
214
+ puts _('done') if option_verbose?
215
+ else
216
+ puts _('Repository %{name} already enabled') % {:name => repository['name']} if option_verbose?
217
+ end
218
+ product
143
219
  end
144
220
 
145
- private
221
+ # basearch and releasever are required for repo set enable. The repository ends with, for example,
222
+ # "x86_64 6.1" or "ia64 6 Server"
223
+ def parse_basearch_releasever(content_set)
224
+ pieces = content_set.split
225
+ if pieces[-1] == 'Server'
226
+ return pieces[-3], "#{pieces[-2]}#{pieces[-1]}"
227
+ else
228
+ return pieces[-2], pieces[-1]
229
+ end
230
+ end
146
231
 
147
232
  def content_type(repository_type)
148
233
  case repository_type
@@ -177,8 +262,31 @@ module HammerCLICsv
177
262
  --organization-id #{ foreman_organization(:name => line[ORGANIZATION]) } }
178
263
  hammer.run(args)
179
264
 
180
- rescue RuntimeError => e
181
- raise "#{e}\n #{line}"
265
+ end
266
+
267
+ def get_content_set(organization, product, repository)
268
+ organization_id = organization['id']
269
+ product_id = product['id']
270
+ @content_sets ||={}
271
+ @content_sets[organization_id] ||= {}
272
+ if @content_sets[organization_id][product_id].nil?
273
+ @content_sets[organization_id][product_id] = {}
274
+ @api.resource(:repository_sets).call(:index, {
275
+ 'per_page' => 999999,
276
+ 'organization_id' => organization_id,
277
+ 'product_id' => product_id
278
+ })['results'].each do |repository_set|
279
+ content_set = repository_set['name']
280
+ repository_set['repositories'].each do |repo|
281
+ @content_sets[organization_id][product_id][repo['id']] = content_set
282
+ end
283
+ end
284
+ end
285
+ content_set = @content_sets[organization_id][product_id][repository['id']]
286
+
287
+ raise "Content set for repository '#{repository['name']}' not found in product '#{product['name']}" unless content_set
288
+
289
+ content_set
182
290
  end
183
291
  end
184
292
  end
@@ -14,27 +14,25 @@ module HammerCLICsv
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
@@ -140,8 +138,6 @@ module HammerCLICsv
140
138
 
141
139
  puts _('done') if option_verbose?
142
140
  end
143
- rescue RuntimeError => e
144
- raise "#{e}\n #{line[NAME]}"
145
141
  end
146
142
 
147
143
  def export_associations(template)
@@ -7,16 +7,14 @@ module HammerCLICsv
7
7
  ORGANIZATIONS = 'Organizations'
8
8
  LOCATIONS = 'Locations'
9
9
 
10
- def export
11
- CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => true}) do |csv|
12
- csv << [NAME, ORGANIZATIONS, LOCATIONS]
13
- @api.resource(:environments).call(:index, {:per_page => 999999})['results'].each do |environment|
14
- environment = @api.resource(:environments).call(:show, {:id => environment['id']})
15
- name = environment['name']
16
- organizations = export_column(environment, 'organizations', 'name')
17
- locations = export_column(environment, 'locations', 'name')
18
- csv << [name, organizations, locations]
19
- end
10
+ def export(csv)
11
+ csv << [NAME, ORGANIZATIONS, LOCATIONS]
12
+ @api.resource(:environments).call(:index, {:per_page => 999999})['results'].each do |environment|
13
+ environment = @api.resource(:environments).call(:show, {:id => environment['id']})
14
+ name = environment['name']
15
+ organizations = export_column(environment, 'organizations', 'name')
16
+ locations = export_column(environment, 'locations', 'name')
17
+ csv << [name, organizations, locations]
20
18
  end
21
19
  end
22
20
 
@@ -74,8 +72,6 @@ module HammerCLICsv
74
72
 
75
73
  puts "done" if option_verbose?
76
74
  end
77
- rescue RuntimeError => e
78
- raise "#{e}\n #{line}"
79
75
  end
80
76
  end
81
77
  end
@@ -9,32 +9,30 @@ module HammerCLICsv
9
9
 
10
10
  SEPARATOR = ' = '
11
11
 
12
- def export
13
- CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => true}) do |csv|
14
- csv << [NAME, ORGANIZATION, FACTS]
12
+ def export(csv)
13
+ csv << [NAME, ORGANIZATION, FACTS]
15
14
 
16
- search_options = {:per_page => 999999}
17
- search_options['search'] = "organization=\"#{option_organization}\"" if option_organization
18
- @api.resource(:hosts).call(:index, search_options)['results'].each do |host|
19
- facts = @api.resource(:fact_values).call(:index, {
20
- 'search' => "host = #{host['name']}",
21
- 'per_page' => 999999
22
- })['results']
23
- facts = @api.resource(:fact_values).call(:index, {
24
- 'search' => "host = #{host['name']}",
25
- 'per_page' => 999999
26
- })['results'][host['name']]
27
- facts ||= {}
15
+ search_options = {:per_page => 999999}
16
+ search_options['search'] = "organization=\"#{option_organization}\"" if option_organization
17
+ @api.resource(:hosts).call(:index, search_options)['results'].each do |host|
18
+ facts = @api.resource(:fact_values).call(:index, {
19
+ 'search' => "host = #{host['name']}",
20
+ 'per_page' => 999999
21
+ })['results']
22
+ facts = @api.resource(:fact_values).call(:index, {
23
+ 'search' => "host = #{host['name']}",
24
+ 'per_page' => 999999
25
+ })['results'][host['name']]
26
+ facts ||= {}
28
27
 
29
- values = CSV.generate do |column|
30
- column << facts.collect do |fact_name, fact_value|
31
- "#{fact_name}#{SEPARATOR}#{fact_value}"
32
- end
28
+ values = CSV.generate do |column|
29
+ column << facts.collect do |fact_name, fact_value|
30
+ "#{fact_name}#{SEPARATOR}#{fact_value}"
33
31
  end
34
- values.delete!("\n")
35
-
36
- csv << [host['name'], host['organization_name'], values]
37
32
  end
33
+ values.delete!("\n")
34
+
35
+ csv << [host['name'], host['organization_name'], values]
38
36
  end
39
37
  end
40
38
 
@@ -69,8 +67,6 @@ module HammerCLICsv
69
67
  })
70
68
  print "done\n" if option_verbose?
71
69
  end
72
- rescue RuntimeError => e
73
- raise "#{e}\n #{line}"
74
70
  end
75
71
  end
76
72
  end
@@ -19,58 +19,56 @@ module HammerCLICsv
19
19
  PRODUCTS = 'Products'
20
20
  SUBSCRIPTIONS = 'Subscriptions'
21
21
 
22
- def export
23
- CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => false}) do |csv|
24
- csv << [NAME, ORGANIZATION, ENVIRONMENT, CONTENTVIEW, SYSTEMGROUPS, VIRTUAL, HOST,
25
- OPERATINGSYSTEM, ARCHITECTURE, SOCKETS, RAM, CORES, SLA, PRODUCTS, SUBSCRIPTIONS]
26
- @api.resource(:organizations).call(:index, {
27
- :per_page => 999999
28
- })['results'].each do |organization|
29
- @api.resource(:systems).call(:index, {
30
- 'per_page' => 999999,
31
- 'organization_id' => organization['id']
32
- })['results'].each do |system|
33
- system = @api.resource(:systems).call(:show, {
34
- 'id' => system['uuid'],
35
- 'fields' => 'full'
36
- })
37
-
38
- name = system['name']
39
- organization_label = organization['label']
40
- environment = system['environment']['label']
41
- contentview = system['content_view']['name']
42
- hostcollections = CSV.generate do |column|
43
- column << system['systemGroups'].collect do |hostcollection|
44
- hostcollection['name']
45
- end
22
+ def export(csv)
23
+ csv << [NAME, ORGANIZATION, ENVIRONMENT, CONTENTVIEW, SYSTEMGROUPS, VIRTUAL, HOST,
24
+ OPERATINGSYSTEM, ARCHITECTURE, SOCKETS, RAM, CORES, SLA, PRODUCTS, SUBSCRIPTIONS]
25
+ @api.resource(:organizations).call(:index, {
26
+ :per_page => 999999
27
+ })['results'].each do |organization|
28
+ @api.resource(:systems).call(:index, {
29
+ 'per_page' => 999999,
30
+ 'organization_id' => organization['id']
31
+ })['results'].each do |system|
32
+ system = @api.resource(:systems).call(:show, {
33
+ 'id' => system['uuid'],
34
+ 'fields' => 'full'
35
+ })
36
+
37
+ name = system['name']
38
+ organization_label = organization['label']
39
+ environment = system['environment']['label']
40
+ contentview = system['content_view']['name']
41
+ hostcollections = CSV.generate do |column|
42
+ column << system['systemGroups'].collect do |hostcollection|
43
+ hostcollection['name']
46
44
  end
47
- hostcollections.delete!("\n")
48
- virtual = system['facts']['virt.is_guest'] == 'true' ? 'Yes' : 'No'
49
- host = system['host']
50
- operatingsystem = "#{system['facts']['distribution.name']} " if system['facts']['distribution.name']
51
- operatingsystem += system['facts']['distribution.version'] if system['facts']['distribution.version']
52
- architecture = system['facts']['uname.machine']
53
- sockets = system['facts']['cpu.cpu_socket(s)']
54
- ram = system['facts']['memory.memtotal']
55
- cores = system['facts']['cpu.core(s)_per_socket']
56
- sla = ''
57
- products = CSV.generate do |column|
58
- column << system['installedProducts'].collect do |product|
59
- "#{product['productId']}|#{product['productName']}"
60
- end
45
+ end
46
+ hostcollections.delete!("\n")
47
+ virtual = system['facts']['virt.is_guest'] == 'true' ? 'Yes' : 'No'
48
+ host = system['host']
49
+ operatingsystem = "#{system['facts']['distribution.name']} " if system['facts']['distribution.name']
50
+ operatingsystem += system['facts']['distribution.version'] if system['facts']['distribution.version']
51
+ architecture = system['facts']['uname.machine']
52
+ sockets = system['facts']['cpu.cpu_socket(s)']
53
+ ram = system['facts']['memory.memtotal']
54
+ cores = system['facts']['cpu.core(s)_per_socket']
55
+ sla = ''
56
+ products = CSV.generate do |column|
57
+ column << system['installedProducts'].collect do |product|
58
+ "#{product['productId']}|#{product['productName']}"
61
59
  end
62
- products.delete!("\n")
63
- subscriptions = CSV.generate do |column|
64
- column << @api.resource(:subscriptions).call(:index, {
65
- 'system_id' => system['uuid']
66
- })['results'].collect do |subscription|
67
- "#{subscription['product_id']}|#{subscription['product_name']}"
68
- end
60
+ end
61
+ products.delete!("\n")
62
+ subscriptions = CSV.generate do |column|
63
+ column << @api.resource(:subscriptions).call(:index, {
64
+ 'system_id' => system['uuid']
65
+ })['results'].collect do |subscription|
66
+ "#{subscription['product_id']}|#{subscription['product_name']}"
69
67
  end
70
- subscriptions.delete!("\n")
71
- csv << [name, organization_label, environment, contentview, hostcollections, virtual, host,
72
- operatingsystem, architecture, sockets, ram, cores, sla, products, subscriptions]
73
68
  end
69
+ subscriptions.delete!("\n")
70
+ csv << [name, organization_label, environment, contentview, hostcollections, virtual, host,
71
+ operatingsystem, architecture, sockets, ram, cores, sla, products, subscriptions]
74
72
  end
75
73
  end
76
74
  end
@@ -109,7 +107,7 @@ module HammerCLICsv
109
107
 
110
108
  # TODO: w/ @daviddavis p-r
111
109
  #subscriptions(line).each do |subscription|
112
- # katello_subscription(line[ORGANIZATION], :name => subscription[:number])
110
+ # get_subscription(line[ORGANIZATION], :name => subscription[:number])
113
111
  #end
114
112
 
115
113
  if !@existing[line[ORGANIZATION]].include? name
@@ -147,8 +145,6 @@ module HammerCLICsv
147
145
 
148
146
  puts 'done' if option_verbose?
149
147
  end
150
- rescue RuntimeError => e
151
- raise "#{e}\n #{line}"
152
148
  end
153
149
 
154
150
  private