hammer_cli_csv 1.0.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NTEwYmI3Y2E5OTYxMGNhYzYwYzg2YjI2YzYyOGQ4MGJkYjkxNWNjNA==
4
+ N2ExODdkOTg4YzFhYmNhZjIyNDdkNTZjMjFjOGVjYjliOWM0OTA0Mw==
5
5
  data.tar.gz: !binary |-
6
- NzM5ODc4MzE5YmE1NThkMjgyYWY2N2YwMDhjY2ZhN2YyMjE5MWRhZA==
6
+ Njg1YmE0ZTMzMzE0NjlkM2E2NWMxMDI2N2QwM2Q5NDdmODViYzU2YQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZDQyZTliM2I3N2JkYmJmYjc4ZjExYjE4MTQ2M2JkODU1NGVkZGMzODQwMTBk
10
- Y2Y3MmJlYzRmYzY2NGVmNWZjMGNiYmJhNTViZmFhY2M0ODA2ZTRlN2FmMmMy
11
- NjdlZjIzYjJhMmVhNGIyMTNiNTA3ODVkYmYzZTBiMjI0MjhhZDY=
9
+ NzZlYzM4NWMxZGMzYzNlNzljYWZmNWQyZmE3NzQ2OWJjMWY0MjNjMGEzMzdi
10
+ NTVlM2NhZmM1ZjE4M2YzZWMxYzQ5M2E1OTZjMWRlNDE2MGUyYmE5YWU0NjYy
11
+ ODJmNDMyMWNiYzk4NTEzODk4MjkzMjZlNjE1MDNiOThhNDRkZGM=
12
12
  data.tar.gz: !binary |-
13
- MmE3N2Y1MDNmZmM4ZGE0Y2FkYTgwMDhiZWY0ZjNiYWNlZDUwZmMyZDBkNjc1
14
- YTMyZTUzMzIxZjRlMzkzYmFlZjAzYWM0MDViYzhmNDI0MzNiYzRhMWU2MGY4
15
- MGE2NGU5YmMyOGU3NGY3MDZlNzM1ZmM4NDViMDYxOGZjM2Y3MTg=
13
+ ZDNhNzIwOWU1N2Y0NWVhYjI5Y2Y1MTgzMzY0NDM2MzZiNjVkNDY3MDk1YzQ1
14
+ OWE4MDY2YjkzOGJjYTZlOWNlM2U3ZTE5MzdlMWU2ZTY4YTk2ZWEwNWNjY2Y2
15
+ Mzc3MTMzZTEwNWU4NjcxMzBmOGJiMjA5M2VhYWYyNWRmY2RkNjA=
@@ -29,4 +29,10 @@
29
29
  :products_sync: false
30
30
 
31
31
  :gutterball:
32
- :enable_module: true
32
+ :enable_module: true
33
+
34
+ :foreman_remote_execution:
35
+ :enable_module: true
36
+
37
+ :import:
38
+ :enable_module: true
@@ -9,68 +9,48 @@ module HammerCLICsv
9
9
  LIMIT = 'Limit'
10
10
  ENVIRONMENT = 'Environment'
11
11
  CONTENTVIEW = 'Content View'
12
- HOSTCOLLECTIONS = 'System Groups'
12
+ HOSTCOLLECTIONS = 'Host Collections'
13
+ SERVICELEVEL = "Service Level"
14
+ RELEASEVER = "Release Version"
15
+ AUTOATTACH = "Auto-Attach"
13
16
  SUBSCRIPTIONS = 'Subscriptions'
14
17
 
15
18
  def export
16
19
  CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => false}) do |csv|
17
20
  csv << [NAME, ORGANIZATION, DESCRIPTION, LIMIT, ENVIRONMENT, CONTENTVIEW,
18
- HOSTCOLLECTIONS, SUBSCRIPTIONS]
19
- if @server_status['release'] == 'Headpin'
20
- @headpin.get(:organizations).each do |organization|
21
- next if option_organization && organization['name'] != option_organization
22
-
23
- @headpin.get("organizations/#{organization['label']}/activation_keys").each do |activationkey|
24
- name = namify(activationkey['name'])
25
- description = activationkey['description']
26
- limit = activationkey['usage_limit'].to_i < 0 ? 'Unlimited' : activationkey['usage_limit']
27
- environment = @headpin.environment(activationkey['environment_id'])['name']
28
- contentview = @headpin.content_view(activationkey['content_view_id'])['name']
29
- # TODO: https://bugzilla.redhat.com/show_bug.cgi?id=1160888
30
- # Act keys in SAM-1 do not include system groups
31
- hostcollections = nil #???? export_column(activationkey, 'systemGroups', 'name')
32
- subscriptions = CSV.generate do |column|
33
- column << activationkey['pools'].collect do |subscription|
34
- amount = subscription['calculatedAttributes']['compliance_type'] == 'Stackable' ? 1 : 'Automatic'
35
- "#{amount}|#{subscription['productId']}|#{subscription['productName']}"
36
- end
21
+ HOSTCOLLECTIONS, AUTOATTACH, SERVICELEVEL, RELEASEVER, SUBSCRIPTIONS]
22
+ @api.resource(:organizations).call(:index, {
23
+ :per_page => 999999
24
+ })['results'].each do |organization|
25
+ next if option_organization && organization['name'] != option_organization
26
+
27
+ @api.resource(:activation_keys).call(:index, {
28
+ 'per_page' => 999999,
29
+ 'organization_id' => organization['id']
30
+ })['results'].each do |activationkey|
31
+ name = namify(activationkey['name'])
32
+ count = 1
33
+ description = activationkey['description']
34
+ limit = activationkey['unlimited_content_hosts'] ? 'Unlimited' : activationkey['max_content_hosts']
35
+ environment = activationkey['environment']['label']
36
+ contentview = activationkey['content_view']['name']
37
+ hostcollections = export_column(activationkey, 'host_collections', 'name')
38
+ autoattach = activationkey['auto_attach'] ? 'Yes' : 'No'
39
+ servicelevel = activationkey['service_level']
40
+ releasever = activationkey['release_version']
41
+ subscriptions = CSV.generate do |column|
42
+ column << @api.resource(:subscriptions).call(:index, {
43
+ 'organization_id' => organization['id'],
44
+ 'activation_key_id' => activationkey['id']
45
+ })['results'].collect do |subscription|
46
+ amount = subscription['amount'] == 0 ? 'Automatic' : subscription['amount']
47
+ sku = subscription['product_id'].match(/\A[0-9]/) ? 'Custom' : subscription['product_id']
48
+ "#{amount}|#{sku}|#{subscription['product_name']}"
37
49
  end
38
- subscriptions.delete!("\n")
39
- csv << [name, organization['label'], description, limit, environment, contentview,
40
- hostcollections, subscriptions]
41
- end
42
- end
43
- else
44
- @api.resource(:organizations).call(:index, {
45
- :per_page => 999999
46
- })['results'].each do |organization|
47
- next if option_organization && organization['name'] != option_organization
48
-
49
- @api.resource(:activation_keys).call(:index, {
50
- 'per_page' => 999999,
51
- 'organization_id' => organization['id']
52
- })['results'].each do |activationkey|
53
- name = namify(activationkey['name'])
54
- count = 1
55
- description = activationkey['description']
56
- limit = activationkey['unlimited_content_hosts'] ? 'Unlimited' : activationkey['max_content_hosts']
57
- environment = activationkey['environment']['label']
58
- contentview = activationkey['content_view']['name']
59
- hostcollections = export_column(activationkey, 'systemGroups', 'name')
60
- subscriptions = CSV.generate do |column|
61
- column << @api.resource(:subscriptions).call(:index, {
62
- 'organization_id' => organization['id'],
63
- 'activation_key_id' => activationkey['id']
64
- })['results'].collect do |subscription|
65
- amount = subscription['amount'] == 0 ? 'Automatic' : subscription['amount']
66
- sku = subscription['product_id'].match(/\A[0-9]/) ? 'Custom' : subscription['product_id']
67
- "#{amount}|#{sku}|#{subscription['product_name']}"
68
- end
69
- end
70
- subscriptions.delete!("\n")
71
- csv << [name, count, organization['name'], description, limit, environment, contentview,
72
- hostcollections, subscriptions]
73
50
  end
51
+ subscriptions.delete!("\n")
52
+ csv << [name, count, organization['name'], description, limit, environment, contentview,
53
+ hostcollections, servicelevel, releasever, autoattach, subscriptions]
74
54
  end
75
55
  end
76
56
  end
@@ -111,6 +91,9 @@ module HammerCLICsv
111
91
  'unlimited_content_hosts' => (line[LIMIT] == 'Unlimited') ? true : false,
112
92
  'max_content_hosts' => (line[LIMIT] == 'Unlimited') ? nil : line[LIMIT].to_i
113
93
  }
94
+ params['auto_attach'] = (line[AUTOATTACH] == 'Yes' ? true : false) if params['auto_attach']
95
+ params['service_level'] = line[SERVICELEVEL].nil? || line[SERVICELEVEL].empty? ? nil : line[SERVICELEVEL]
96
+ params['release_version'] = line[RELEASEVER].nil? || line[RELEASEVER].empty? ? nil : line[RELEASEVER]
114
97
  if !@existing[line[ORGANIZATION]].include? name
115
98
  print _("Creating activation key '%{name}'...") % {:name => name} if option_verbose?
116
99
  activationkey = @api.resource(:activation_keys).call(:create, params)
@@ -546,6 +546,37 @@ module HammerCLICsv
546
546
  result
547
547
  end
548
548
 
549
+ def foreman_provisioning_template(options = {})
550
+ @query_config_templates ||= {}
551
+
552
+ if options[:name]
553
+ return nil if options[:name].nil? || options[:name].empty?
554
+ options[:id] = @query_config_templates[options[:name]]
555
+ if !options[:id]
556
+ config_template = @api.resource(:config_templates).call(:index, {
557
+ :per_page => 999999,
558
+ 'search' => "name=\"#{options[:name]}\""
559
+ })['results']
560
+ raise "Provisioning template '#{options[:name]}' not found" if !config_template || config_template.empty?
561
+ options[:id] = config_template[0]['id']
562
+ @query_config_templates[options[:name]] = options[:id]
563
+ end
564
+ result = options[:id]
565
+ else
566
+ return nil if options[:id].nil?
567
+ options[:name] = @query_config_templates.key(options[:id])
568
+ if !options[:name]
569
+ config_template = @api.resource(:config_templates).call(:show, {'id' => options[:id]})
570
+ raise "Provisioning template 'id=#{options[:id]}' not found" if !config_template || config_template.empty?
571
+ options[:name] = config_template['name']
572
+ @query_config_templates[options[:name]] = options[:id]
573
+ end
574
+ result = options[:name]
575
+ end
576
+
577
+ result
578
+ end
579
+
549
580
  def foreman_smart_proxy(options = {})
550
581
  @query_smart_proxies ||= {}
551
582
 
@@ -717,7 +748,7 @@ module HammerCLICsv
717
748
  results = @api.resource(:subscriptions).call(:index, {
718
749
  :per_page => 999999,
719
750
  'organization_id' => foreman_organization(:name => organization),
720
- 'search' => "name:\"#{options[:name]}\""
751
+ 'search' => "name = \"#{options[:name]}\""
721
752
  })
722
753
  raise "No subscriptions match '#{options[:name]}'" if results['subtotal'] == 0
723
754
  raise "Too many subscriptions match '#{options[:name]}'" if results['subtotal'] > 1
@@ -864,11 +895,11 @@ module HammerCLICsv
864
895
  [name, major || '', minor || '']
865
896
  end
866
897
 
867
- def export_column(object, name, field)
898
+ def export_column(object, name, field=nil)
868
899
  return '' unless object[name]
869
900
  values = CSV.generate do |column|
870
901
  column << object[name].collect do |fields|
871
- fields[field]
902
+ field.nil? ? yield(fields) : fields[field]
872
903
  end
873
904
  end
874
905
  values.delete!("\n")
@@ -45,28 +45,27 @@ module HammerCLICsv
45
45
  def create_compute_resources_from_csv(line)
46
46
  count(line[COUNT]).times do |number|
47
47
  name = namify(line[NAME], number)
48
+ params = {
49
+ 'compute_resource' => {
50
+ 'name' => name,
51
+ 'url' => line[URL],
52
+ 'provider' => line[PROVIDER]
53
+ }
54
+ }
48
55
  if !@existing.include? name
49
56
  print "Creating compute resource '#{name}'..." if option_verbose?
50
- id = @api.resource(:compute_resources).call(:create, {
51
- 'compute_resource' => {
52
- 'name' => name,
53
- 'url' => line[URL]
54
- }
55
- })['id']
57
+ id = @api.resource(:compute_resources).call(:create, params)['id']
56
58
  else
57
59
  print "Updating compute resource '#{name}'..." if option_verbose?
58
- id = @api.resource(:compute_resources).call(:update, {
59
- 'id' => @existing[name],
60
- 'compute_resource' => {
61
- 'name' => name,
62
- 'url' => line[URL]
63
- }
64
- })['compute_resource']['id']
60
+ id = @existing[name]
61
+ params['id'] = id
62
+ @api.resource(:compute_resources).call(:update, params)
65
63
  end
66
64
 
67
65
  # Update associated resources
68
- associate_organizations(id, line[ORGANIZATIONS], 'compute_resource')
69
- associate_locations(id, line[LOCATIONS], 'compute_resource')
66
+ # TODO: this doesn't work "Environments you cannot remove environments that are used by hosts or inherited."
67
+ #associate_organizations(id, line[ORGANIZATIONS], 'compute_resource')
68
+ #associate_locations(id, line[LOCATIONS], 'compute_resource')
70
69
 
71
70
  print "done\n" if option_verbose?
72
71
  end
@@ -165,9 +165,11 @@ module HammerCLICsv
165
165
  if !@hypervisor_guests.empty?
166
166
  print(_('Updating hypervisor and guest associations...')) if option_verbose?
167
167
  @hypervisor_guests.each do |host_id, guest_ids|
168
- @api.resource(:systems).call(:update, {
168
+ @api.resource(:hosts).call(:update, {
169
169
  'id' => host_id,
170
- 'guest_ids' => guest_ids
170
+ 'host' => {
171
+ 'guest_ids' => guest_ids
172
+ }
171
173
  })
172
174
  end
173
175
  puts _('done') if option_verbose?
@@ -178,21 +180,25 @@ module HammerCLICsv
178
180
  return if option_organization && line[ORGANIZATION] != option_organization
179
181
 
180
182
  if !@existing[line[ORGANIZATION]]
181
- @existing[line[ORGANIZATION]] = {}
183
+ @existing[line[ORGANIZATION]] = true
182
184
  # Fetching all content hosts is too slow and times out due to the complexity of the data
183
185
  # rendered in the json.
184
186
  # http://projects.theforeman.org/issues/6307
185
- total = @api.resource(:systems).call(:index, {
187
+ total = @api.resource(:hosts).call(:index, {
186
188
  'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
187
189
  'per_page' => 1
188
190
  })['total'].to_i
189
191
  (total / 20 + 2).to_i.times do |page|
190
- @api.resource(:systems).call(:index, {
192
+ @api.resource(:hosts).call(:index, {
191
193
  'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
192
194
  'page' => page + 1,
193
195
  'per_page' => 20
194
196
  })['results'].each do |host|
195
- @existing[line[ORGANIZATION]][host['name']] = host['uuid'] if host
197
+ @existing[host['name']] = {
198
+ :host => host['id'],
199
+ :subscription => host['subscription']['id'],
200
+ :content => host['content']['id']
201
+ }
196
202
  end
197
203
  end
198
204
  end
@@ -200,42 +206,52 @@ module HammerCLICsv
200
206
  count(line[COUNT]).times do |number|
201
207
  name = namify(line[NAME], number)
202
208
 
203
- if !@existing[line[ORGANIZATION]].include? name
209
+ if !@existing.include? name
204
210
  print(_("Creating content host '%{name}'...") % {:name => name}) if option_verbose?
205
- host_id = @api.resource(:systems).call(:create, {
211
+ host_id = @api.resource(:host_subscriptions).call(:register, {
206
212
  'name' => name,
207
213
  'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
208
- 'environment_id' => lifecycle_environment(line[ORGANIZATION], :name => line[ENVIRONMENT]),
214
+ 'lifecycle_environment_id' => lifecycle_environment(line[ORGANIZATION], :name => line[ENVIRONMENT]),
209
215
  'content_view_id' => katello_contentview(line[ORGANIZATION], :name => line[CONTENTVIEW]),
210
216
  'facts' => facts(name, line),
211
217
  'installed_products' => products(line),
212
218
  'service_level' => line[SLA],
213
219
  'type' => 'system'
214
- })['uuid']
215
- @existing[line[ORGANIZATION]][name] = host_id
220
+ })['id']
221
+ @existing[name] = host_id
216
222
  else
223
+ # TODO: remove passing facet IDs to update
224
+ # Bug #13849 - updating a host's facet should not require the facet id to be included in facet params
225
+ # http://projects.theforeman.org/issues/13849
217
226
  print(_("Updating content host '%{name}'...") % {:name => name}) if option_verbose?
218
- host_id = @api.resource(:systems).call(:update, {
219
- 'id' => @existing[line[ORGANIZATION]][name],
220
- 'system' => {
227
+ host_id = @api.resource(:hosts).call(:update, {
228
+ 'id' => @existing[name][:host],
229
+ 'host' => {
221
230
  'name' => name,
222
- 'environment_id' => lifecycle_environment(line[ORGANIZATION], :name => line[ENVIRONMENT]),
223
- 'content_view_id' => katello_contentview(line[ORGANIZATION], :name => line[CONTENTVIEW]),
224
- 'facts' => facts(name, line),
225
- 'installed_products' => products(line)
226
- },
227
- 'facts' => facts(name, line),
228
- 'installed_products' => products(line), # TODO: http://projects.theforeman.org/issues/9191,
229
- 'service_level' => line[SLA]
230
- })['uuid']
231
+ 'content_facet_attributes' => {
232
+ 'id' => @existing[name][:content],
233
+ 'lifecycle_environment_id' => lifecycle_environment(line[ORGANIZATION], :name => line[ENVIRONMENT]),
234
+ 'content_view_id' => katello_contentview(line[ORGANIZATION], :name => line[CONTENTVIEW])
235
+ },
236
+ 'subscription_facet_attributes' => {
237
+ 'id' => @existing[name][:subscription],
238
+ 'facts' => facts(name, line),
239
+ # TODO: PUT /hosts subscription_facet_attributes missing "installed_products"
240
+ # http://projects.theforeman.org/issues/13854
241
+ #'installed_products' => products(line),
242
+ 'service_level' => line[SLA]
243
+ }
244
+ }
245
+ })['host_id']
231
246
  end
232
247
 
233
248
  if line[VIRTUAL] == 'Yes' && line[HOST]
234
- raise "Content host '#{line[HOST]}' not found" if !@existing[line[ORGANIZATION]][line[HOST]]
235
- @hypervisor_guests[@existing[line[ORGANIZATION]][line[HOST]]] ||= []
236
- @hypervisor_guests[@existing[line[ORGANIZATION]][line[HOST]]] << "#{line[ORGANIZATION]}/#{name}"
249
+ raise "Content host '#{line[HOST]}' not found" if !@existing[line[HOST]]
250
+ @hypervisor_guests[@existing[line[HOST]]] ||= []
251
+ @hypervisor_guests[@existing[line[HOST]]] << @existing[name]
237
252
  end
238
253
 
254
+ update_host_facts(host_id, line)
239
255
  update_host_collections(host_id, line)
240
256
  update_subscriptions(host_id, line)
241
257
 
@@ -262,12 +278,15 @@ module HammerCLICsv
262
278
  facts
263
279
  end
264
280
 
281
+ def update_host_facts(host_id, line)
282
+ end
283
+
265
284
  def update_host_collections(host_id, line)
266
285
  return nil if !line[HOSTCOLLECTIONS]
267
286
  CSV.parse_line(line[HOSTCOLLECTIONS]).each do |hostcollection_name|
268
- @api.resource(:host_collections).call(:add_systems, {
287
+ @api.resource(:host_collections).call(:add_hosts, {
269
288
  'id' => katello_hostcollection(line[ORGANIZATION], :name => hostcollection_name),
270
- 'system_ids' => [host_id]
289
+ 'hosts_ids' => [host_id]
271
290
  })
272
291
  end
273
292
  end
@@ -299,29 +318,16 @@ module HammerCLICsv
299
318
  end
300
319
 
301
320
  def update_subscriptions(host_id, line)
302
- existing_subscriptions = @api.resource(:systems).call(:subscriptions, {
303
- 'per_page' => 999999,
304
- 'id' => host_id
321
+ existing_subscriptions = @api.resource(:host_subscriptions).call(:index, {
322
+ 'host_id' => host_id
305
323
  })['results']
306
- if existing_subscriptions.length > 0
307
- @api.resource(:subscriptions).call(:destroy, {
308
- 'system_id' => host_id,
309
- 'id' => existing_subscriptions[0]['id']
324
+ if existing_subscriptions.length != 0
325
+ @api.resource(:host_subscriptions).call(:remove_subscriptions, {
326
+ 'host_id' => host_id,
327
+ 'subscriptions' => existing_subscriptions
310
328
  })
311
329
  end
312
330
 
313
- # existing_subscriptions = @api.resource(:subscriptions).call(:index, {
314
- # 'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
315
- # 'per_page' => 999999,
316
- # 'system_id' => host_id
317
- # })['results']
318
- # if existing_subscriptions.length > 0
319
- # @api.resource(:subscriptions).call(:destroy, {
320
- # 'system_id' => host_id,
321
- # 'id' => existing_subscriptions[0]['id']
322
- # })
323
- # end
324
-
325
331
  return if line[SUBSCRIPTIONS].nil? || line[SUBSCRIPTIONS].empty?
326
332
 
327
333
  subscriptions = CSV.parse_line(line[SUBSCRIPTIONS], {:skip_blanks => true}).collect do |details|
@@ -332,8 +338,8 @@ module HammerCLICsv
332
338
  }
333
339
  end
334
340
 
335
- @api.resource(:subscriptions).call(:create, {
336
- 'system_id' => host_id,
341
+ @api.resource(:host_subscriptions).call(:add_subscriptions, {
342
+ 'host_id' => host_id,
337
343
  'subscriptions' => subscriptions
338
344
  })
339
345
  end
@@ -96,7 +96,7 @@ module HammerCLICsv
96
96
  'inclusion' => filter_inclusion?(line[TYPE]),
97
97
  'repository_ids' => repository_ids
98
98
  })['id']
99
- @existing_filters[line[ORGANIZATION]][filter_name] = filter_id
99
+ @existing_filters[line[ORGANIZATION]][line[CONTENTVIEW]][filter_name] = filter_id
100
100
  else
101
101
  print "Updating filter '#{filter_name}' for content view filter '#{line[CONTENTVIEW]}'..." if option_verbose?
102
102
  @api.resource(:content_view_filters).call(:update, {
@@ -173,7 +173,7 @@ module HammerCLICsv
173
173
  end
174
174
 
175
175
  def export_filter_type(type)
176
- case type.split[1]
176
+ case type
177
177
  when /rpm/i
178
178
  'Packages'
179
179
  when /package_group/i
@@ -106,32 +106,26 @@ module HammerCLICsv
106
106
  'description' => line[DESCRIPTION],
107
107
  'composite' => is_composite
108
108
  }
109
- if is_composite
110
- options['component_ids'] = composite_ids
111
- else
112
- options['repository_ids'] = repository_ids
113
- end
114
109
  contentview_id = @api.resource(:content_views).call(:create, options)['id']
115
110
  @existing_contentviews[line[ORGANIZATION]][name] = contentview_id
116
- publish = true
117
111
  else
118
112
  print _("Updating content view '%{name}'...") % {:name => name} if option_verbose?
119
- options = {
120
- 'id' => contentview_id,
121
- 'description' => line[DESCRIPTION]
122
- }
123
- if is_composite
124
- options['component_ids'] = composite_ids
125
- else
126
- options['repository_ids'] = repository_ids
127
- end
128
- contentview = @api.resource(:content_views).call(:update, options)
129
- contentview_id = contentview['id']
130
- publish = contentview['versions'].empty?
131
113
  end
132
114
 
115
+ options = {
116
+ 'id' => contentview_id,
117
+ 'description' => line[DESCRIPTION]
118
+ }
119
+ if is_composite
120
+ options['component_ids'] = composite_ids
121
+ else
122
+ options['repository_ids'] = repository_ids
123
+ end
124
+ contentview = @api.resource(:content_views).call(:update, options)
125
+ contentview_id = contentview['id']
126
+
133
127
  # Content views cannot be used in composites unless a publish has occurred
134
- publish_content_view(contentview_id, line) if publish
128
+ publish_content_view(contentview_id, line) if contentview['versions'].empty?
135
129
  promote_content_view(contentview_id, line)
136
130
 
137
131
  puts _('done') if option_verbose?
@@ -6,16 +6,27 @@ module HammerCLICsv
6
6
 
7
7
  ORGANIZATION = 'Organization'
8
8
  LOCATION = 'Location'
9
- ENVIRONMENT = 'Environment'
9
+ ENVIRONMENT = 'Puppet Environment'
10
10
  OPERATINGSYSTEM = 'Operating System'
11
11
  ARCHITECTURE = 'Architecture'
12
12
  MACADDRESS = 'MAC Address'
13
13
  DOMAIN = 'Domain'
14
14
  PARTITIONTABLE = 'Partition Table'
15
+ SUBNET = 'Subnet'
16
+ REALM = 'Realm'
17
+ MEDIUM = 'Medium'
18
+ HOSTGROUP = 'Hostgroup'
19
+ COMPUTERESOURCE = 'Compute Resource'
20
+ COMPUTEPROFILE = 'Compute Profile'
21
+ IMAGE = 'Image'
22
+ ENABLED = 'Enabled'
23
+ MANAGED = 'Managed'
15
24
 
16
25
  def export
17
26
  CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => true}) do |csv|
18
- csv << [NAME, ORGANIZATION, LOCATION, ENVIRONMENT, OPERATINGSYSTEM, ARCHITECTURE, MACADDRESS, DOMAIN, PARTITIONTABLE]
27
+ csv << [NAME, ORGANIZATION, LOCATION, ENVIRONMENT, OPERATINGSYSTEM, ARCHITECTURE,
28
+ MACADDRESS, DOMAIN, PARTITIONTABLE, SUBNET, REALM, MEDIUM, HOSTGROUP,
29
+ COMPUTERESOURCE, COMPUTEPROFILE, IMAGE, ENABLED, MANAGED]
19
30
  search_options = {:per_page => 999999}
20
31
  search_options['search'] = "organization=\"#{option_organization}\"" if option_organization
21
32
  @api.resource(:hosts).call(:index, search_options)['results'].each do |host|
@@ -23,15 +34,28 @@ module HammerCLICsv
23
34
  raise "Host 'id=#{host['id']}' not found" if !host || host.empty?
24
35
 
25
36
  name = host['name']
26
- organization = foreman_organization(:id => host['organization_id'])
27
- environment = foreman_environment(:id => host['environment_id'])
28
- operatingsystem = foreman_operatingsystem(:id => host['operatingsystem_id'])
29
- architecture = foreman_architecture(:id => host['architecture_id'])
37
+ organization = host['organization_name']
38
+ location = host['location_name']
39
+ environment = host['environment_name']
40
+ operatingsystem = host['operatingsystem_name']
41
+ architecture = host['architecture_name']
30
42
  mac = host['mac']
31
- domain = foreman_domain(:id => host['domain_id'])
32
- ptable = foreman_partitiontable(:id => host['ptable_id'])
43
+ domain = host['domain_name']
44
+ ptable = host['ptable_name']
45
+ subnet = host['subnet_name']
46
+ realm = host['realm_name']
47
+ medium = host['medium_name']
48
+ hostgroup = host['hostgroup_name']
49
+ compute_resource = host['compute_resource_name']
50
+ compute_profile = host['compute_profile_name']
51
+ image = host['image_name']
33
52
 
34
- csv << [name, organization, environment, operatingsystem, architecture, mac, domain, ptable]
53
+ enabled = host['enabled'] ? 'Yes' : 'No'
54
+ managed = host['managed'] ? 'Yes' : 'No'
55
+
56
+ csv << [name, organization, location, environment, operatingsystem, architecture,
57
+ mac, domain, ptable, subnet, realm, medium, hostgroup, compute_resource,
58
+ compute_profile, image, enabled, managed]
35
59
  end
36
60
  end
37
61
  end
@@ -17,7 +17,7 @@ module HammerCLICsv
17
17
  domains architectures partition_tables lifecycle_environments host_collections
18
18
  provisioning_templates
19
19
  subscriptions products content_views content_view_filters activation_keys
20
- hosts content_hosts smart_proxies reports roles users )
20
+ hosts content_hosts smart_proxies compute_resources reports roles users )
21
21
  RESOURCES.each do |resource|
22
22
  dashed = resource.gsub('_', '-')
23
23
  option "--#{dashed}", 'FILE', "csv file for #{dashed}"
@@ -42,9 +42,14 @@ module HammerCLICsv
42
42
  @api = ApipieBindings::API.new({:uri => @server, :username => @username,
43
43
  :password => @password, :api_version => 2})
44
44
 
45
- # Swing the hammers
45
+ resources_specified = RESOURCES.collect do |resource|
46
+ resource if self.send("option_#{resource}") || ARGV.include?('--' + resource.gsub('_', '-'))
47
+ end
48
+ resources_specified.compact!
46
49
  RESOURCES.each do |resource|
47
- hammer_resource(resource)
50
+ if resources_specified.include?(resource) || (resources_specified == [] && option_dir)
51
+ hammer_resource(resource)
52
+ end
48
53
  end
49
54
 
50
55
  HammerCLI::EX_OK
@@ -62,7 +67,7 @@ module HammerCLICsv
62
67
 
63
68
  def hammer_resource(resource)
64
69
  return if !self.send("option_#{resource}") && !option_dir
65
- options_file = self.send("option_#{resource}") || "#{option_dir}/#{resource.gsub('_', '-')}.csv"
70
+ options_file = "#{option_dir}/#{resource.gsub('_', '-')}.csv" || self.send("option_#{resource}")
66
71
  unless options_file_exists? options_file
67
72
  if option_dir
68
73
  puts _("Skipping #{resource} because '#{options_file}' does not exist") if option_verbose?
@@ -6,14 +6,21 @@ module HammerCLICsv
6
6
 
7
7
  ORGANIZATIONS = 'Organizations'
8
8
  LOCATIONS = 'Locations'
9
+ DESCRIPTION = 'Description'
9
10
  JOB = 'Job Category'
10
11
  PROVIDER = 'Provider'
11
12
  SNIPPET = 'Snippet'
12
13
  TEMPLATE = 'Template'
14
+ INPUT_NAME = 'Input:Name'
15
+ INPUT_DESCRIPTION = 'Input:Description'
16
+ INPUT_REQUIRED = 'Input:Required'
17
+ INPUT_TYPE = 'Input:Type'
18
+ INPUT_PARAMETERS = 'Input:Parameters'
13
19
 
14
20
  def export
15
21
  CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => true}) do |csv|
16
- csv << [NAME, ORGANIZATIONS, LOCATIONS, JOB, PROVIDER, SNIPPET, TEMPLATE]
22
+ csv << [NAME, ORGANIZATIONS, LOCATIONS, DESCRIPTION, JOB, PROVIDER, SNIPPET, TEMPLATE,
23
+ INPUT_NAME, INPUT_DESCRIPTION, INPUT_REQUIRED, INPUT_TYPE, INPUT_PARAMETERS]
17
24
  @api.resource(:job_templates).call(:index, {
18
25
  :per_page => 999999
19
26
  })['results'].each do |template_id|
@@ -21,12 +28,37 @@ module HammerCLICsv
21
28
  next if template['locked']
22
29
  next unless option_organization.nil? || template['organizations'].detect { |org| org['name'] == option_organization }
23
30
  name = template['name']
24
- job = template['job_name']
31
+ description = template['description_format']
32
+ job = template['job_category']
25
33
  snippet = template['snippet'] ? 'Yes' : 'No'
26
34
  provider = template['provider_type']
27
35
  organizations = export_column(template, 'organizations', 'name')
28
36
  locations = export_column(template, 'locations', 'name')
29
- csv << [name, organizations, locations, job, provider, snippet, template['template']]
37
+ csv << [name, organizations, locations, description, job, provider, snippet, template['template']]
38
+
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']}
58
+ end
59
+ required = input['required'] ? 'Yes' : 'No'
60
+ csv << template_columns + [input['name'], input['description'], required, input['input_type'], input_name]
61
+ end
30
62
  end
31
63
  end
32
64
  end
@@ -58,30 +90,13 @@ module HammerCLICsv
58
90
  end
59
91
 
60
92
  count(line[COUNT]).times do |number|
61
- name = namify(line[NAME], number)
62
- job_name = namify(line[JOB], number)
63
- options = {
64
- 'job_template' => {
65
- 'name' => name,
66
- 'job_name' => job_name,
67
- 'snippet' => line[SNIPPET] == 'Yes' ? true : false,
68
- 'provider_type' => line[PROVIDER],
69
- 'organization_ids' => organizations,
70
- 'location_ids' => locations,
71
- 'template' => line[TEMPLATE]
72
- }
73
- }
74
- template_id = @existing[name]
75
- if !template_id
76
- print _("Creating job template '%{name}'...") % {:name => name } if option_verbose?
77
- template_id = @api.resource(:job_templates).call(:create, options)['id']
78
- @existing[name] = template_id
93
+ if line[INPUT_NAME].nil? || line[INPUT_NAME].empty?
94
+ create_template(line, number)
79
95
  else
80
- print _("Updating job template '%{name}'...") % {:name => name} if option_verbose?
81
- options['id'] = template_id
82
- template_id = @api.resource(:job_templates).call(:update, options)['id']
96
+ create_template_input(line, number)
83
97
  end
84
98
 
99
+ # ????
85
100
  # Update associated resources
86
101
  # @template_organizations ||= {}
87
102
  # organizations.each do |organization_id|
@@ -122,12 +137,81 @@ module HammerCLICsv
122
137
  # end
123
138
  # end
124
139
 
125
- puts _('done') if option_verbose?
126
140
  end
127
141
  rescue RuntimeError => e
128
142
  raise "#{e}\n #{line[NAME]}"
129
143
  end
130
144
 
145
+ def create_template(line, number)
146
+ name = namify(line[NAME], number)
147
+ job_category = namify(line[JOB], number)
148
+ options = {
149
+ 'job_template' => {
150
+ 'name' => name,
151
+ 'description_format' => line[DESCRIPTION],
152
+ 'job_category' => job_category,
153
+ 'snippet' => line[SNIPPET] == 'Yes' ? true : false,
154
+ 'provider_type' => line[PROVIDER],
155
+ #'organization_ids' => organizations,
156
+ #'location_ids' => locations,
157
+ 'template' => line[TEMPLATE]
158
+ }
159
+ }
160
+ template_id = @existing[name]
161
+ if !template_id
162
+ print _("Creating job template '%{name}'...") % {:name => name } if option_verbose?
163
+ template_id = @api.resource(:job_templates).call(:create, options)['id']
164
+ @existing[name] = template_id
165
+ else
166
+ print _("Updating job template '%{name}'...") % {:name => name} if option_verbose?
167
+ options['id'] = template_id
168
+ template_id = @api.resource(:job_templates).call(:update, options)['id']
169
+ end
170
+ puts _('done') if option_verbose?
171
+ end
172
+
173
+ def create_template_input(line, number)
174
+ name = namify(line[NAME], number)
175
+ template_id = @existing[name]
176
+ raise "Job template '#{name}' must exist before setting inputs" unless template_id
177
+
178
+ options = {
179
+ 'template_id' => template_id,
180
+ 'template_input' => {
181
+ 'name' => line[INPUT_NAME],
182
+ 'description' => line[INPUT_DESCRIPTION],
183
+ 'input_type' => line[INPUT_TYPE],
184
+ 'required' => line[INPUT_REQUIRED] == 'Yes' ? true : false
185
+ }
186
+ }
187
+ case line[INPUT_TYPE]
188
+ when /user/
189
+ options['template_input']['options'] = line[INPUT_PARAMETERS]
190
+ when /fact/
191
+ options['template_input']['fact_name'] = line[INPUT_PARAMETERS]
192
+ when /variable/
193
+ options['template_input']['variable_name'] = line[INPUT_PARAMETERS]
194
+ when /puppet_parameter/
195
+ options['template_input']['puppet_class_name'], options['template_input']['puppet_parameter_name'] = line[INPUT_PARAMETERS].split('|')
196
+ else
197
+ raise _("Unknown job template input type '%{type}'") % {:type => line[INPUT_TYPE]}
198
+ end
199
+
200
+ template_input = @api.resource(:template_inputs).call(:index, {
201
+ :template_id => template_id,
202
+ :search => "name = \"#{line[INPUT_NAME]}\""
203
+ })['results']
204
+ if template_input.empty?
205
+ print _("Creating job template input '%{input_name}' on '%{name}'...") % {:input_name => line[INPUT_NAME], :name => name}
206
+ @api.resource(:template_inputs).call(:create, options)
207
+ else
208
+ print _("Updating job template input '%{input_name}' on '%{name}'...") % {:input_name => line[INPUT_NAME], :name => name}
209
+ options['id'] = template_input[0]['id']
210
+ @api.resource(:template_inputs).call(:update, options)
211
+ end
212
+ puts _('done') if option_verbose?
213
+ end
214
+
131
215
  def export_associations(template)
132
216
  return '' unless template['template_combinations']
133
217
  values = CSV.generate do |column|
@@ -55,7 +55,8 @@ module HammerCLICsv
55
55
 
56
56
  count(line[COUNT]).times do |number|
57
57
  name = namify(line[NAME], number)
58
- prior = namify(line[PRIORENVIRONMENT], number)
58
+ prior = line[PRIORENVIRONMENT] == 'Library' ? 'Library' :
59
+ namify(line[PRIORENVIRONMENT], number)
59
60
  raise "Organization '#{line[ORGANIZATION]}' does not exist" if !@existing.include? line[ORGANIZATION]
60
61
  if !@existing[line[ORGANIZATION]].include? name
61
62
  print "Creating environment '#{name}'..." if option_verbose?
@@ -6,15 +6,32 @@ module HammerCLICsv
6
6
 
7
7
  FAMILY = 'Family'
8
8
  DESCRIPTION = 'Description'
9
+ PASSWORD_HASH = 'Password Hash'
10
+ PARTITION_TABLES = 'Partition Tables'
11
+ ARCHITECTURES = 'Architectures'
12
+ MEDIA = 'Media'
13
+ PROVISIONING_TEMPLATES = 'Provisioning Templates'
14
+ PARAMETERS = 'Parameters'
9
15
 
10
16
  def export
11
17
  CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => true}) do |csv|
12
- csv << [NAME, DESCRIPTION, FAMILY]
13
- @api.resource(:operatingsystems).call(:index, {:per_page => 999999})['results'].each do |operatingsystem|
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']})
14
22
  name = build_os_name(operatingsystem['name'], operatingsystem['major'], operatingsystem['minor'])
15
23
  description = operatingsystem['description']
16
24
  family = operatingsystem['family']
17
- csv << [name, description, 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]
18
35
  end
19
36
  end
20
37
  end
@@ -34,9 +51,21 @@ module HammerCLICsv
34
51
  params = {
35
52
  'operatingsystem' => {
36
53
  'family' => line[FAMILY],
37
- 'description' => line[DESCRIPTION]
54
+ 'description' => line[DESCRIPTION],
55
+ 'password_hash' => line[PASSWORD_HASH]
38
56
  }
39
57
  }
58
+ params['operatingsystem']['architecture_ids'] = collect_column(line[ARCHITECTURES]) do |name|
59
+ foreman_architecture(:name => name)
60
+ end
61
+ # TODO: http://projects.theforeman.org/issues/12919
62
+ #params['operatingsystem']['provisioning_template_ids'] = collect_column(line[PROVISIONING_TEMPLATES]) do |name|
63
+ # foreman_provisioning_template(:name => name)
64
+ #end
65
+ # TODO: http://projects.theforeman.org/issues/12920
66
+ #params['operatingsystem']['os_parameters?'] = collect_column(line[PARAMETERS]) do |name_value|
67
+ # ????
68
+ #end
40
69
  count(line[COUNT]).times do |number|
41
70
  name = namify(line[NAME], number)
42
71
  (osname, major, minor) = split_os_name(name)
@@ -14,7 +14,8 @@ module HammerCLICsv
14
14
 
15
15
  def export
16
16
  CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => false}) do |csv|
17
- csv << [NAME, LABEL, ORGANIZATION, REPOSITORY, REPOSITORY_TYPE, REPOSITORY_URL]
17
+ csv << [NAME, LABEL, ORGANIZATION, DESCRIPTION, REPOSITORY, REPOSITORY_TYPE,
18
+ REPOSITORY_URL]
18
19
  @api.resource(:organizations).call(:index, {
19
20
  :per_page => 999999
20
21
  })['results'].each do |organization|
@@ -32,7 +33,8 @@ module HammerCLICsv
32
33
  repository_type = repository['product_type'] == 'custom' ? 'Custom' : 'Red Hat'
33
34
  repository_type += " #{repository['content_type'].capitalize}"
34
35
  csv << [product['name'], product['label'], organization['name'],
35
- repository['name'], repository_type, repository['url']]
36
+ product['description'], repository['name'], repository_type,
37
+ repository['url']]
36
38
  end
37
39
  end
38
40
  end
@@ -77,6 +79,12 @@ module HammerCLICsv
77
79
 
78
80
  count(line[COUNT]).times do |number|
79
81
  name = namify(line[NAME], number)
82
+ params = {
83
+ :name => name,
84
+ 'organization_id' => foreman_organization(:name => line[ORGANIZATION])
85
+ }
86
+ params[:description] = line[DESCRIPTION] if !line[DESCRIPTION].nil? &&
87
+ !line[DESCRIPTION].empty?
80
88
  product_id = @existing_products[line[ORGANIZATION]][name]
81
89
  if product_id.nil?
82
90
  print _("Creating product '%{name}'...") % {:name => name} if option_verbose?
@@ -85,14 +93,12 @@ module HammerCLICsv
85
93
  {:name => name, :organization => line[ORGANIZATION]}
86
94
  end
87
95
 
88
- product_id = @api.resource(:products).call(:create, {
89
- 'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
90
- 'name' => name
91
- })['id']
96
+ product_id = @api.resource(:products).call(:create, params)['id']
92
97
  @existing_products[line[ORGANIZATION]][name] = product_id
93
98
  else
94
- # Nothing to update for products
95
99
  print _("Updating product '%{name}'...") % {:name => name} if option_verbose?
100
+ params[:id] = product_id
101
+ @api.resource(:products).call(:update, params)
96
102
  end
97
103
  @existing_repositories[line[ORGANIZATION] + name] = {}
98
104
 
@@ -4,6 +4,9 @@ module HammerCLICsv
4
4
  command_name 'provisioning-templates'
5
5
  desc 'import or export provisioning templates'
6
6
 
7
+ option %w(--include-locked), :flag, 'Include locked templates (will fail if re-imported)',
8
+ :attribute_name => :option_include_locked
9
+
7
10
  ORGANIZATIONS = 'Organizations'
8
11
  LOCATIONS = 'Locations'
9
12
  OPERATINGSYSTEMS = 'Operating Systems'
@@ -14,12 +17,13 @@ module HammerCLICsv
14
17
  def export
15
18
  CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => true}) do |csv|
16
19
  csv << [NAME, ORGANIZATIONS, LOCATIONS, OPERATINGSYSTEMS, ASSOCIATIONS, KIND, TEMPLATE]
17
- @api.resource(:config_templates).call(:index, {
20
+ params = {
18
21
  :per_page => 999999
19
- })['results'].each do |template_id|
22
+ }
23
+ params['search'] = "organization = \"#{option_organization}\"" if option_organization
24
+ @api.resource(:config_templates).call(:index, params)['results'].each do |template_id|
20
25
  template = @api.resource(:config_templates).call(:show, {:id => template_id['id']})
21
- next if template['locked']
22
- next unless option_organization.nil? || template['organizations'].detect { |org| org['name'] == option_organization }
26
+ next if template['locked'] && !option_include_locked?
23
27
  name = template['name']
24
28
  kind = template['snippet'] ? 'snippet' : template['template_kind_name']
25
29
  organizations = export_column(template, 'organizations', 'name')
@@ -108,6 +108,7 @@ module HammerCLICsv
108
108
  end
109
109
 
110
110
  def import_manifest_from_csv(line)
111
+ return if option_organization && line[ORGANIZATION] != option_organization
111
112
  args = %W{
112
113
  --server #{ @server } --username #{ @username } --password #{ @password }
113
114
  subscription upload --file #{ line[MANIFEST] }
@@ -1,5 +1,5 @@
1
1
  module HammerCLICsv
2
2
  def self.version
3
- @version ||= Gem::Version.new('1.0.2')
3
+ @version ||= Gem::Version.new('2.0.0')
4
4
  end
5
5
  end
@@ -1,4 +1,4 @@
1
- Name,Count,Organization,Location,Environment,Operating System,Architecture,MAC Address,Domain,Partition Table
1
+ Name,Count,Organization,Location,Puppet Environment,Operating System,Architecture,MAC Address,Domain,Partition Table
2
2
  dhcp130-%03d.megacorp.com,255,Mega Corporation,Asia Pacific,Development,RHEL 6.4,x86_64,"02:FE:B5:E0:70:%02x",megacorp.com,RedHat default
3
3
  dhcp129-%03d.megacorp.com,255,Mega Corporation,Development,RHEL 6.4,x86_64,"01:FE:B5:E0:70:%02x",megacorp.com,RedHat default
4
4
  # dhcp129-1%02d.megacorp.com,255,Mega Corporation,Development,RHEL 6.4,x86_64,"01:FE:B5:E1:70:%02x",megacorp.com,RedHat default
@@ -1,19 +1,20 @@
1
1
  Name,Count,Label,Organization,Repository,Repository Type,Repository Url
2
- katello-client-1.4,1,katello-client-1_4,Mega Corporation,katello-1.4-client,Custom Yum,http://fedorapeople.org/groups/katello/releases/yum/1.4-client/RHEL/6Server/x86_64/
3
- katello-1.4,1,katello-1_4,Mega Corporation,katello-1.4,Custom Yum,http://fedorapeople.org/groups/katello/releases/yum/1.4/RHEL/6Server/x86_64/
4
- Red Hat Enterprise Linux Server,1,Red_Hat_Enterprise_Linux_Server,Mega Corporation,Red Hat Enterprise Linux 6 Server Kickstart x86_64 6.1,Red Hat Yum,https://cdn.redhat.com/content/dist/rhel/server/6/6.1/x86_64/kickstart
5
- Red Hat Enterprise Linux Server,1,Red_Hat_Enterprise_Linux_Server,Mega Corporation,Red Hat Enterprise Linux 6 Server Kickstart x86_64 6.2,Red Hat Yum,https://cdn.redhat.com/content/dist/rhel/server/6/6.2/x86_64/kickstart
6
- Red Hat Enterprise Linux Server,1,Red_Hat_Enterprise_Linux_Server,Mega Corporation,Red Hat Enterprise Linux 6 Server Kickstart x86_64 6.3,Red Hat Yum,https://cdn.redhat.com/content/dist/rhel/server/6/6.3/x86_64/kickstart
7
- Red Hat Enterprise Linux Server,1,Red_Hat_Enterprise_Linux_Server,Mega Corporation,Red Hat Enterprise Linux 6 Server Kickstart x86_64 6.4,Red Hat Yum,https://cdn.redhat.com/content/dist/rhel/server/6/6.4/x86_64/kickstart
8
- Red Hat Enterprise Linux Server,1,Red_Hat_Enterprise_Linux_Server,Mega Corporation,Red Hat Enterprise Linux 6 Server Kickstart x86_64 6.5,Red Hat Yum,https://cdn.redhat.com/content/dist/rhel/server/6/6.5/x86_64/kickstart
9
- Red Hat Enterprise Linux Server,1,Red_Hat_Enterprise_Linux_Server,Mega Corporation,Red Hat Enterprise Linux 6 Server Kickstart x86_64 6Server,Red Hat Yum,https://cdn.redhat.com/content/dist/rhel/server/6/6Server/x86_64/kickstart
10
- Red Hat Enterprise Linux Server,1,Red_Hat_Enterprise_Linux_Server,Mega Corporation,Red Hat Enterprise Linux 6 Server RPMs x86_64 6.1,Red Hat Yum,https://cdn.redhat.com/content/dist/rhel/server/6/6.1/x86_64/os
11
- Red Hat Enterprise Linux Server,1,Red_Hat_Enterprise_Linux_Server,Mega Corporation,Red Hat Enterprise Linux 6 Server RPMs x86_64 6.2,Red Hat Yum,https://cdn.redhat.com/content/dist/rhel/server/6/6.2/x86_64/os
12
- Red Hat Enterprise Linux Server,1,Red_Hat_Enterprise_Linux_Server,Mega Corporation,Red Hat Enterprise Linux 6 Server RPMs x86_64 6.3,Red Hat Yum,https://cdn.redhat.com/content/dist/rhel/server/6/6.3/x86_64/os
13
- Red Hat Enterprise Linux Server,1,Red_Hat_Enterprise_Linux_Server,Mega Corporation,Red Hat Enterprise Linux 6 Server RPMs x86_64 6.4,Red Hat Yum,https://cdn.redhat.com/content/dist/rhel/server/6/6.4/x86_64/os
14
- Red Hat Enterprise Linux Server,1,Red_Hat_Enterprise_Linux_Server,Mega Corporation,Red Hat Enterprise Linux 6 Server RPMs x86_64 6.5,Red Hat Yum,https://cdn.redhat.com/content/dist/rhel/server/6/6.5/x86_64/os
15
- Red Hat Enterprise Linux Server,1,Red_Hat_Enterprise_Linux_Server,Mega Corporation,Red Hat Enterprise Linux 6 Server RPMs x86_64 6Server,Red Hat Yum,https://cdn.redhat.com/content/dist/rhel/server/6/6Server/x86_64/os
16
- Red Hat Enterprise Linux Server,1,Red_Hat_Enterprise_Linux_Server,Mega Corporation,Red Hat Enterprise Linux 7 Server Kickstart x86_64 7.0,Red Hat Yum,https://cdn.redhat.com/content/dist/rhel/server/7/7.0/x86_64/kickstart
17
- Red Hat Enterprise Linux Server,1,Red_Hat_Enterprise_Linux_Server,Mega Corporation,Red Hat Enterprise Linux 7 Server Kickstart) x86_64 7Server,Red Hat Yum,https://cdn.redhat.com/content/dist/rhel/server/7/7Server/x86_64/kickstart
18
- Red Hat Enterprise Linux Server,1,Red_Hat_Enterprise_Linux_Server,Mega Corporation,Red Hat Enterprise Linux 7 Server RPMs x86_64 7.0,Red Hat Yum,https://cdn.redhat.com/content/dist/rhel/server/7/7.0/x86_64/os
19
- Red Hat Enterprise Linux Server,1,Red_Hat_Enterprise_Linux_Server,Mega Corporation,Red Hat Enterprise Linux 7 Server RPMs x86_64 7Server,Red Hat Yum,https://cdn.redhat.com/content/dist/rhel/server/7/7Server/x86_64/os
2
+ Puppet Labs,1,puppetlabs,Mega Corporation,puppet-forge,Custom Puppet,https://forge.puppetlabs.com/
3
+ # katello-client-1.4,1,katello-client-1_4,Mega Corporation,katello-1.4-client,Custom Yum,http://fedorapeople.org/groups/katello/releases/yum/1.4-client/RHEL/6Server/x86_64/
4
+ # katello-1.4,1,katello-1_4,Mega Corporation,katello-1.4,Custom Yum,http://fedorapeople.org/groups/katello/releases/yum/1.4/RHEL/6Server/x86_64/
5
+ # Red Hat Enterprise Linux Server,1,Red_Hat_Enterprise_Linux_Server,Mega Corporation,Red Hat Enterprise Linux 6 Server Kickstart x86_64 6.1,Red Hat Yum,https://cdn.redhat.com/content/dist/rhel/server/6/6.1/x86_64/kickstart
6
+ # Red Hat Enterprise Linux Server,1,Red_Hat_Enterprise_Linux_Server,Mega Corporation,Red Hat Enterprise Linux 6 Server Kickstart x86_64 6.2,Red Hat Yum,https://cdn.redhat.com/content/dist/rhel/server/6/6.2/x86_64/kickstart
7
+ # Red Hat Enterprise Linux Server,1,Red_Hat_Enterprise_Linux_Server,Mega Corporation,Red Hat Enterprise Linux 6 Server Kickstart x86_64 6.3,Red Hat Yum,https://cdn.redhat.com/content/dist/rhel/server/6/6.3/x86_64/kickstart
8
+ # Red Hat Enterprise Linux Server,1,Red_Hat_Enterprise_Linux_Server,Mega Corporation,Red Hat Enterprise Linux 6 Server Kickstart x86_64 6.4,Red Hat Yum,https://cdn.redhat.com/content/dist/rhel/server/6/6.4/x86_64/kickstart
9
+ # Red Hat Enterprise Linux Server,1,Red_Hat_Enterprise_Linux_Server,Mega Corporation,Red Hat Enterprise Linux 6 Server Kickstart x86_64 6.5,Red Hat Yum,https://cdn.redhat.com/content/dist/rhel/server/6/6.5/x86_64/kickstart
10
+ # Red Hat Enterprise Linux Server,1,Red_Hat_Enterprise_Linux_Server,Mega Corporation,Red Hat Enterprise Linux 6 Server Kickstart x86_64 6Server,Red Hat Yum,https://cdn.redhat.com/content/dist/rhel/server/6/6Server/x86_64/kickstart
11
+ # Red Hat Enterprise Linux Server,1,Red_Hat_Enterprise_Linux_Server,Mega Corporation,Red Hat Enterprise Linux 6 Server RPMs x86_64 6.1,Red Hat Yum,https://cdn.redhat.com/content/dist/rhel/server/6/6.1/x86_64/os
12
+ # Red Hat Enterprise Linux Server,1,Red_Hat_Enterprise_Linux_Server,Mega Corporation,Red Hat Enterprise Linux 6 Server RPMs x86_64 6.2,Red Hat Yum,https://cdn.redhat.com/content/dist/rhel/server/6/6.2/x86_64/os
13
+ # Red Hat Enterprise Linux Server,1,Red_Hat_Enterprise_Linux_Server,Mega Corporation,Red Hat Enterprise Linux 6 Server RPMs x86_64 6.3,Red Hat Yum,https://cdn.redhat.com/content/dist/rhel/server/6/6.3/x86_64/os
14
+ # Red Hat Enterprise Linux Server,1,Red_Hat_Enterprise_Linux_Server,Mega Corporation,Red Hat Enterprise Linux 6 Server RPMs x86_64 6.4,Red Hat Yum,https://cdn.redhat.com/content/dist/rhel/server/6/6.4/x86_64/os
15
+ # Red Hat Enterprise Linux Server,1,Red_Hat_Enterprise_Linux_Server,Mega Corporation,Red Hat Enterprise Linux 6 Server RPMs x86_64 6.5,Red Hat Yum,https://cdn.redhat.com/content/dist/rhel/server/6/6.5/x86_64/os
16
+ # Red Hat Enterprise Linux Server,1,Red_Hat_Enterprise_Linux_Server,Mega Corporation,Red Hat Enterprise Linux 6 Server RPMs x86_64 6Server,Red Hat Yum,https://cdn.redhat.com/content/dist/rhel/server/6/6Server/x86_64/os
17
+ # Red Hat Enterprise Linux Server,1,Red_Hat_Enterprise_Linux_Server,Mega Corporation,Red Hat Enterprise Linux 7 Server Kickstart x86_64 7.0,Red Hat Yum,https://cdn.redhat.com/content/dist/rhel/server/7/7.0/x86_64/kickstart
18
+ # Red Hat Enterprise Linux Server,1,Red_Hat_Enterprise_Linux_Server,Mega Corporation,Red Hat Enterprise Linux 7 Server Kickstart) x86_64 7Server,Red Hat Yum,https://cdn.redhat.com/content/dist/rhel/server/7/7Server/x86_64/kickstart
19
+ # Red Hat Enterprise Linux Server,1,Red_Hat_Enterprise_Linux_Server,Mega Corporation,Red Hat Enterprise Linux 7 Server RPMs x86_64 7.0,Red Hat Yum,https://cdn.redhat.com/content/dist/rhel/server/7/7.0/x86_64/os
20
+ # Red Hat Enterprise Linux Server,1,Red_Hat_Enterprise_Linux_Server,Mega Corporation,Red Hat Enterprise Linux 7 Server RPMs x86_64 7Server,Red Hat Yum,https://cdn.redhat.com/content/dist/rhel/server/7/7Server/x86_64/os
@@ -1,5 +1,2 @@
1
1
  Name,Count,Value
2
- administrator,1,root@example.com
3
2
  idle_timeout,1,60000
4
- remote_execution_global_proxy,1,true
5
- require_ssl_smart_proxies,1,false
@@ -0,0 +1,32 @@
1
+ require File.join(File.dirname(__FILE__), 'csv_test_helper')
2
+
3
+ describe 'job-templates' do
4
+
5
+ extend CommandTestHelper
6
+
7
+ context "import" do
8
+ it "create job template with input" do
9
+ set_user 'admin'
10
+
11
+ name = "jobtemplate#{rand(10000)}"
12
+
13
+ file = Tempfile.new('job_templates_test')
14
+ # rubocop:disable LineLength
15
+ file.write <<-FILE
16
+ "Name","Organizations","Locations","Description","Job Category","Provider","Snippet","Template","Input:Name","Input:Description","Input:Required","Input:Type","Input:Parameters"
17
+ "#{name}","","","","TEST","SSH","No","<%= input(""command"") %>"
18
+ "#{name}","","","","","","","","command","command to run","Yes","user",""
19
+ FILE
20
+ # rubocop:enable LineLength
21
+ file.rewind
22
+ stdout,stderr = capture {
23
+ hammer.run(%W{csv job-templates --verbose --file #{file.path}})
24
+ }
25
+ stderr.must_equal ''
26
+ lines = stdout.split("\n")
27
+ lines[0].must_equal "Creating job template '#{name}'...done"
28
+ lines[1].must_equal "Creating job template input 'command' on '#{name}'...done"
29
+ file.unlink
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,30 @@
1
+ require File.join(File.dirname(__FILE__), 'csv_test_helper')
2
+
3
+ describe 'job-templates' do
4
+
5
+ extend CommandTestHelper
6
+
7
+ context "import" do
8
+ it "update settings w/ Count column" do
9
+ set_user 'admin'
10
+
11
+ name = "settings#{rand(10000)}"
12
+
13
+ file = Tempfile.new('settings_test')
14
+ # rubocop:disable LineLength
15
+ file.write <<-FILE
16
+ Name,Count,Value
17
+ idle_timeout,1,60000
18
+ FILE
19
+ file.rewind
20
+
21
+ stdout,stderr = capture {
22
+ hammer.run(%W{csv settings --verbose --file #{file.path}})
23
+ }
24
+ stderr.must_equal ''
25
+ lines = stdout.split("\n")
26
+ lines[0].must_equal "Updating setting 'idle_timeout'...done"
27
+ file.unlink
28
+ end
29
+ end
30
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hammer_cli_csv
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas McKay
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-04 00:00:00.000000000 Z
11
+ date: 2016-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hammer_cli_katello
@@ -123,8 +123,10 @@ files:
123
123
  - test/helpers/resource_disabled.rb
124
124
  - test/hosts_test.rb
125
125
  - test/import_test.rb
126
+ - test/job_templates_test.rb
126
127
  - test/organizations_test.rb
127
128
  - test/roles_test.rb
129
+ - test/settings_test.rb
128
130
  - test/setup_test.rb
129
131
  - test/users_test.rb
130
132
  homepage: http://github.com/Katello/hammer-cli-csv
@@ -185,7 +187,9 @@ test_files:
185
187
  - test/helpers/resource_disabled.rb
186
188
  - test/hosts_test.rb
187
189
  - test/import_test.rb
190
+ - test/job_templates_test.rb
188
191
  - test/organizations_test.rb
189
192
  - test/roles_test.rb
193
+ - test/settings_test.rb
190
194
  - test/setup_test.rb
191
195
  - test/users_test.rb