hammer_cli_foreman 2.4.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. checksums.yaml +4 -4
  2. data/doc/release_notes.md +40 -0
  3. data/lib/hammer_cli_foreman/architecture.rb +5 -5
  4. data/lib/hammer_cli_foreman/associating_commands.rb +0 -24
  5. data/lib/hammer_cli_foreman/bookmark.rb +5 -5
  6. data/lib/hammer_cli_foreman/combination.rb +3 -13
  7. data/lib/hammer_cli_foreman/command_extensions/ping.rb +21 -2
  8. data/lib/hammer_cli_foreman/command_extensions/subnet.rb +25 -10
  9. data/lib/hammer_cli_foreman/command_extensions/update_common.rb +14 -0
  10. data/lib/hammer_cli_foreman/command_extensions/user.rb +9 -5
  11. data/lib/hammer_cli_foreman/command_extensions.rb +1 -2
  12. data/lib/hammer_cli_foreman/commands.rb +17 -11
  13. data/lib/hammer_cli_foreman/compute_attribute.rb +1 -1
  14. data/lib/hammer_cli_foreman/compute_profile.rb +5 -5
  15. data/lib/hammer_cli_foreman/compute_resource/ovirt.rb +2 -1
  16. data/lib/hammer_cli_foreman/compute_resource.rb +23 -0
  17. data/lib/hammer_cli_foreman/config_report.rb +2 -0
  18. data/lib/hammer_cli_foreman/filter.rb +2 -2
  19. data/lib/hammer_cli_foreman/host.rb +1 -47
  20. data/lib/hammer_cli_foreman/hostgroup.rb +14 -58
  21. data/lib/hammer_cli_foreman/hosts/common_update_options.rb +10 -31
  22. data/lib/hammer_cli_foreman/id_resolver.rb +7 -68
  23. data/lib/hammer_cli_foreman/location.rb +0 -6
  24. data/lib/hammer_cli_foreman/mail_notification.rb +2 -2
  25. data/lib/hammer_cli_foreman/model.rb +5 -5
  26. data/lib/hammer_cli_foreman/operating_system.rb +10 -10
  27. data/lib/hammer_cli_foreman/option_builders.rb +84 -52
  28. data/lib/hammer_cli_foreman/option_sources/id_params.rb +41 -11
  29. data/lib/hammer_cli_foreman/option_sources/ids_params.rb +39 -7
  30. data/lib/hammer_cli_foreman/option_sources.rb +0 -1
  31. data/lib/hammer_cli_foreman/organization.rb +0 -6
  32. data/lib/hammer_cli_foreman/ping.rb +6 -1
  33. data/lib/hammer_cli_foreman/references.rb +0 -16
  34. data/lib/hammer_cli_foreman/registration.rb +18 -0
  35. data/lib/hammer_cli_foreman/settings.rb +3 -3
  36. data/lib/hammer_cli_foreman/smart_proxy.rb +7 -57
  37. data/lib/hammer_cli_foreman/template.rb +3 -15
  38. data/lib/hammer_cli_foreman/user.rb +4 -4
  39. data/lib/hammer_cli_foreman/usergroup.rb +5 -5
  40. data/lib/hammer_cli_foreman/version.rb +1 -1
  41. data/lib/hammer_cli_foreman.rb +3 -21
  42. data/lib/minitest/coverage_reporter.rb +1 -1
  43. data/locale/ca/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  44. data/locale/de/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  45. data/locale/en/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  46. data/locale/en_GB/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  47. data/locale/es/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  48. data/locale/fr/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  49. data/locale/it/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  50. data/locale/ja/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  51. data/locale/ko/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  52. data/locale/pt_BR/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  53. data/locale/ru/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  54. data/locale/zh_CN/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  55. data/locale/zh_TW/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  56. data/test/data/2.4/foreman_api.json +1 -0
  57. data/test/data/2.5/foreman_api.json +1 -0
  58. data/test/data/3.1/foreman_api.json +1 -0
  59. data/test/functional/architecture_test.rb +37 -5
  60. data/test/functional/bookmark_test.rb +5 -2
  61. data/test/functional/compute_attribute_test.rb +20 -20
  62. data/test/functional/compute_profile_test.rb +14 -1
  63. data/test/functional/compute_resource_test.rb +37 -0
  64. data/test/functional/filter_test.rb +2 -1
  65. data/test/functional/host_test.rb +65 -11
  66. data/test/functional/hostgroup/create_test.rb +11 -117
  67. data/test/functional/hostgroup/update_test.rb +11 -79
  68. data/test/functional/http_proxy_test.rb +12 -0
  69. data/test/functional/location_test.rb +13 -3
  70. data/test/functional/mail_notification_test.rb +3 -1
  71. data/test/functional/media_test.rb +11 -0
  72. data/test/functional/model_test.rb +3 -1
  73. data/test/functional/operating_system_test.rb +3 -1
  74. data/test/functional/personal_access_token_test.rb +4 -4
  75. data/test/functional/ping_test.rb +33 -0
  76. data/test/functional/realm_test.rb +11 -0
  77. data/test/functional/registration_test.rb +8 -0
  78. data/test/functional/report_template_test.rb +11 -0
  79. data/test/functional/settings_test.rb +4 -4
  80. data/test/functional/template_test.rb +87 -48
  81. data/test/functional/user_mail_notification_test.rb +3 -3
  82. data/test/functional/user_test.rb +11 -0
  83. data/test/functional/usergroup_test.rb +3 -1
  84. data/test/test_helper.rb +1 -1
  85. data/test/unit/apipie_resource_mock.rb +1 -39
  86. data/test/unit/architecture_test.rb +10 -10
  87. data/test/unit/bookmark_test.rb +10 -14
  88. data/test/unit/commands_test.rb +1 -2
  89. data/test/unit/compute_profile_test.rb +10 -10
  90. data/test/unit/config_report_test.rb +1 -0
  91. data/test/unit/helpers/command.rb +0 -8
  92. data/test/unit/host_test.rb +14 -61
  93. data/test/unit/hostgroup_test.rb +7 -26
  94. data/test/unit/id_resolver_test.rb +0 -28
  95. data/test/unit/mail_notification_test.rb +4 -4
  96. data/test/unit/model_test.rb +47 -47
  97. data/test/unit/operating_system_test.rb +10 -16
  98. data/test/unit/option_builders_test.rb +88 -83
  99. data/test/unit/settings_test.rb +4 -4
  100. data/test/unit/smart_proxy_test.rb +0 -12
  101. data/test/unit/usergroup_test.rb +10 -10
  102. metadata +115 -128
  103. data/lib/hammer_cli_foreman/command_extensions/puppet_environment.rb +0 -29
  104. data/lib/hammer_cli_foreman/command_extensions/puppet_environments.rb +0 -29
  105. data/lib/hammer_cli_foreman/config_group.rb +0 -45
  106. data/lib/hammer_cli_foreman/option_sources/puppet_environment_params.rb +0 -59
  107. data/lib/hammer_cli_foreman/puppet_class.rb +0 -61
  108. data/lib/hammer_cli_foreman/puppet_environment.rb +0 -65
  109. data/lib/hammer_cli_foreman/smart_class_parameter.rb +0 -189
  110. data/test/functional/config_group_test.rb +0 -50
  111. data/test/functional/proxy_test.rb +0 -86
  112. data/test/functional/smart_class_parameter_test.rb +0 -97
  113. data/test/reports/TEST-Minitest-Result.xml +0 -4344
  114. data/test/unit/config_group_test.rb +0 -82
  115. data/test/unit/puppet_class_test.rb +0 -72
  116. data/test/unit/puppet_environment_test.rb +0 -114
  117. data/test/unit/smart_class_parameter_test.rb +0 -113
@@ -170,15 +170,33 @@ module HammerCLIForeman
170
170
  attr_reader :resource
171
171
 
172
172
  def build(builder_params={})
173
+ resource_name_map = builder_params[:resource_mapping] || {}
173
174
  @searchables.for(@resource).collect do |s|
174
175
  option(
175
176
  optionamize("--#{s.name}"),
176
177
  s.name.upcase,
177
178
  s.description,
178
- :referenced_resource => @resource.singular_name
179
+ referenced_resource: @resource.singular_name,
180
+ aliased_resource: aliased_name(resource_name(s.name), resource_name_map)
179
181
  )
180
182
  end
181
183
  end
184
+
185
+ def aliased_name(name, resource_name_map)
186
+ return if name.nil?
187
+
188
+ resource_name_map[name.to_s] || resource_name_map[name.to_sym] || name
189
+ end
190
+
191
+ def resource_name(param)
192
+ if param =~ /^id[s]?$/
193
+ @resource.singular_name
194
+ elsif param =~ /_id[s]?$/
195
+ param.gsub(/_id[s]?$/, '')
196
+ else
197
+ nil
198
+ end
199
+ end
182
200
  end
183
201
 
184
202
 
@@ -194,23 +212,43 @@ module HammerCLIForeman
194
212
 
195
213
  def build(builder_params={})
196
214
  resource_name_map = builder_params[:resource_mapping] || {}
197
- dependent_options(@resource, resource_name_map)
215
+ command = builder_params[:command]
216
+ dependent_options(@resource, resource_name_map, command)
198
217
  end
199
218
 
200
219
  protected
201
220
 
202
- def dependent_options(resource, resource_name_map)
221
+ def dependent_options(resource, resource_name_map, command)
203
222
  options = []
204
223
  searchables = @searchables.for(resource)
205
224
  resource_name = resource.singular_name
206
225
  aliased_name = aliased(resource_name, resource_name_map)
207
226
  types = searchables.map(&:name).push('id').map(&:capitalize).join('/')
208
- associated_resource = resource.singular_name.to_s.tr('_', ' ')
209
- family = HammerCLI::Options::OptionFamily.new(
210
- referenced_resource: resource_name,
211
- aliased_resource: aliased_name,
212
- description: _('Set the current %{resource} context for the request. %{types} can be used') % { types: types, resource: associated_resource }
213
- )
227
+ associated_resource = aliased_name.to_s.tr('_', ' ')
228
+ family = command.option_families.find do |f|
229
+ f.head.referenced_resource == resource_name
230
+ end
231
+ unless family
232
+ # If there is no family it probably means that we explicitly want to
233
+ # expand options via
234
+ # build_options do |o|
235
+ # o.expand.including(:resource)
236
+ # end
237
+ # instead of generating it from API docs (it may not be even present there)
238
+ family = HammerCLI::Options::OptionFamily.new(
239
+ description: _('%{types} of associated %{resource}') % { types: types, resource: associated_resource },
240
+ creator: command
241
+ )
242
+ options << family.parent(
243
+ optionamize("--#{aliased_name}-id"),
244
+ "#{aliased_name}_id".upcase,
245
+ description("#{aliased_name}_id", @context[:action]),
246
+ attribute_name: HammerCLI.option_accessor_name("#{resource_name}_id"),
247
+ referenced_resource: resource_name,
248
+ aliased_resource: aliased_name,
249
+ format: HammerCLI::Options::Normalizers::Number.new
250
+ )
251
+ end
214
252
 
215
253
  unless searchables.empty?
216
254
  first = searchables[0]
@@ -221,31 +259,25 @@ module HammerCLIForeman
221
259
  options << family.child(
222
260
  optionamize("--#{aliased_name}"),
223
261
  "#{aliased_name}_#{first.name}".upcase,
224
- first.description || " ",
225
- attribute_name: HammerCLI.option_accessor_name("#{resource_name}_#{first.name}")
262
+ first.description || ' ',
263
+ attribute_name: HammerCLI.option_accessor_name("#{resource_name}_#{first.name}"),
264
+ referenced_resource: resource_name,
265
+ aliased_resource: aliased_name
226
266
  )
227
267
  # Other options are named by the resource plus the searchable name
228
268
  # Eg. --organization-label with accessor option_organization_label
229
269
  remaining.each do |s|
230
- options << family.send(s.parent? ? :parent : :child,
270
+ options << family.child(
231
271
  optionamize("--#{aliased_name}-#{s.name}"),
232
272
  "#{aliased_name}_#{s.name}".upcase,
233
- s.description || " ",
273
+ s.description || ' ',
234
274
  attribute_name: HammerCLI.option_accessor_name("#{resource_name}_#{s.name}"),
235
- format: s.format
275
+ referenced_resource: resource_name,
276
+ aliased_resource: aliased_name
236
277
  )
237
278
  end
238
279
  end
239
280
 
240
- unless options.any? { |o| o.handles?("--#{aliased_name}-id") }
241
- options << family.parent(
242
- optionamize("--#{aliased_name}-id"),
243
- "#{aliased_name}_id".upcase,
244
- description("#{aliased_name}_id", @context[:action]),
245
- attribute_name: HammerCLI.option_accessor_name("#{resource_name}_id"),
246
- format: HammerCLI::Options::Normalizers::Number.new
247
- )
248
- end
249
281
  options
250
282
  end
251
283
 
@@ -266,15 +298,25 @@ module HammerCLIForeman
266
298
  class UpdateDependentSearchablesOptionBuilder < DependentSearchablesOptionBuilder
267
299
  protected
268
300
 
269
- def dependent_options(resource, resource_name_map)
301
+ def dependent_options(resource, resource_name_map, command)
270
302
  options = []
271
303
  searchables = @searchables.for(resource)
272
304
  resource_name = resource.singular_name
273
305
  aliased_name = aliased(resource_name, resource_name_map)
306
+ # Those options are not coming from API docs, thus create a new family only
274
307
  family = HammerCLI::Options::OptionFamily.new(
275
308
  prefix: 'new-',
276
309
  aliased_resource: aliased_name,
277
- referenced_resource: resource_name
310
+ referenced_resource: resource_name,
311
+ creator: command
312
+ )
313
+
314
+ options << family.parent(
315
+ optionamize("--new-#{aliased_name}-id"),
316
+ "new_#{aliased_name}_id".upcase,
317
+ _('Use to update associated %s') % aliased_name,
318
+ attribute_name: HammerCLI.option_accessor_name("new_#{resource_name}_id"),
319
+ format: HammerCLI::Options::Normalizers::Number.new
278
320
  )
279
321
  unless searchables.empty?
280
322
  first = searchables[0]
@@ -285,73 +327,63 @@ module HammerCLIForeman
285
327
  options << family.child(
286
328
  optionamize("--new-#{aliased_name}"),
287
329
  "new_#{aliased_name}_#{first.name}".upcase,
288
- _('Use to update'),
330
+ _('Use to update associated %s') % aliased_name,
289
331
  attribute_name: HammerCLI.option_accessor_name("new_#{resource_name}_#{first.name}")
290
332
  )
291
333
  # Other options are named by the resource plus the searchable name
292
334
  # Eg. --new-organization-label with accessor option_new_organization_label
293
335
  remaining.each do |s|
294
- options << family.send(s.parent? ? :parent : :child,
336
+ options << family.child(
295
337
  optionamize("--new-#{aliased_name}-#{s.name}"),
296
338
  "new_#{aliased_name}_#{s.name}".upcase,
297
- _('Use to update'),
339
+ _('Use to update associated %s') % aliased_name,
298
340
  attribute_name: HammerCLI.option_accessor_name("new_#{resource_name}_#{s.name}")
299
341
  )
300
342
  end
301
343
  end
302
344
 
303
- unless options.any? { |o| o.handles?("--new-#{aliased_name}-id") }
304
- options << family.parent(
305
- optionamize("--new-#{aliased_name}-id"),
306
- "new_#{aliased_name}_id".upcase,
307
- _('Use to update'),
308
- attribute_name: HammerCLI.option_accessor_name("new_#{resource_name}_id"),
309
- format: HammerCLI::Options::Normalizers::Number.new
310
- )
311
- end
312
345
  options
313
346
  end
314
347
  end
315
348
 
316
349
  class DependentSearchablesArrayOptionBuilder < DependentSearchablesOptionBuilder
317
-
318
-
319
- def dependent_options(resource, resource_name_map)
350
+ def dependent_options(resource, resource_name_map, command)
320
351
  options = []
321
352
  searchables = @searchables.for(resource)
322
353
  resource_name = resource.singular_name
323
354
 
324
355
  aliased_name = aliased(resource_name, resource_name_map)
325
356
  aliased_plural_name = aliased(resource.name, resource_name_map)
326
-
327
357
  unless searchables.empty?
328
358
  first = searchables[0]
329
359
  remaining = searchables[1..-1] || []
330
- types = searchables.map(&:plural_name).map(&:capitalize).join('/')
331
- associated_resource = resource.name.to_s.tr('_', ' ')
332
- family = HammerCLI::Options::OptionFamily.new(
333
- format: HammerCLI::Options::Normalizers::List.new,
334
- referenced_resource: resource_name,
335
- aliased_resource: aliased_name,
336
- description: _('%{types} of associated %{resource}') % { types: types, resource: associated_resource }
337
- )
360
+ # Find family created by HammerCLI::Apipie::OptionBuilder for *_ids options
361
+ family = command.option_families.find do |f|
362
+ f.head.referenced_resource == resource_name && f.formats.include?(HammerCLI::Options::Normalizers::List)
363
+ end
338
364
  # First option is named by the resource
339
365
  # Eg. --organizations with accessor option_organization_names
340
366
  options << family.child(
341
367
  optionamize("--#{aliased_plural_name}"),
342
368
  "#{aliased_name}_#{first.plural_name}".upcase,
343
369
  ' ',
344
- attribute_name: HammerCLI.option_accessor_name("#{resource_name}_#{first.plural_name}")
370
+ attribute_name: HammerCLI.option_accessor_name("#{resource_name}_#{first.plural_name}"),
371
+ format: HammerCLI::Options::Normalizers::List.new,
372
+ referenced_resource: resource_name,
373
+ aliased_resource: aliased_name
345
374
  )
346
375
 
347
376
  # Other options are named by the resource plus the searchable name
348
377
  # Eg. --organization-labels with accessor option_organization_labels
349
378
  remaining.each do |s|
350
- options << family.send(s.parent? ? :parent : :child,
379
+ options << family.child(
351
380
  optionamize("--#{aliased_name}-#{s.plural_name}"),
352
381
  "#{aliased_name}_#{s.plural_name}".upcase,
353
382
  ' ',
354
- attribute_name: HammerCLI.option_accessor_name("#{resource_name}_#{s.plural_name}")
383
+ attribute_name: HammerCLI.option_accessor_name("#{resource_name}_#{s.plural_name}"),
384
+ format: HammerCLI::Options::Normalizers::List.new,
385
+ referenced_resource: resource_name,
386
+ aliased_resource: aliased_name
355
387
  )
356
388
  end
357
389
  end
@@ -6,29 +6,53 @@ module HammerCLIForeman
6
6
  end
7
7
 
8
8
  def param_updatable?(param_resource)
9
- param_resource && @command.respond_to?(HammerCLI.option_accessor_name("#{param_resource.singular_name}_id"))
9
+ param_resource && @command.respond_to?(cli_option_resource_id(param_resource))
10
10
  end
11
11
 
12
12
  def available_id_params
13
13
  IdParamsFilter.new(:only_required => false).for_action(@command.resource.action(@command.action))
14
14
  end
15
15
 
16
- def get_options(defined_options, result)
16
+ def needs_resolving?(param_option, param_resource, all_opts)
17
+ return false unless param_updatable?(param_resource)
18
+
19
+ cli_searchables_set = @command.searchables.for(param_resource).any? do |s|
20
+ option = HammerCLI.option_accessor_name("#{param_resource.singular_name}_#{s.name}")
21
+ next false unless @command.respond_to?(option)
22
+
23
+ !@command.send(option).nil?
24
+ end
25
+ if cli_searchables_set
26
+ # Remove set '<resource_name>_id' option to force resolving in case of
27
+ # '<resource_name>_[name|title]' was set from CLI
28
+ all_opts.delete(param_option)
29
+ true
30
+ else
31
+ # Don't resolve if resource id was set via CLI
32
+ return false if @command.send(cli_option_resource_id(param_resource))
33
+
34
+ all_opts[param_option].nil?
35
+ end
36
+ end
37
+
38
+ def get_options(_defined_options, result)
17
39
  # resolve all '<resource_name>_id' parameters if they are defined as options
18
40
  # (they can be skipped using .without or .expand.except)
19
41
  return result if @command.action.nil?
42
+
20
43
  available_id_params.each do |api_param|
21
44
  param_resource = HammerCLIForeman.param_to_resource(api_param.name)
22
- if result[HammerCLI.option_accessor_name(api_param.name)].nil? && param_updatable?(param_resource)
23
- resource_id = @command.get_resource_id(param_resource, :scoped => true, :required => api_param.required?, :all_options => result)
24
- result[HammerCLI.option_accessor_name(api_param.name)] = resource_id if resource_id
25
- end
45
+ param_option = HammerCLI.option_accessor_name(api_param.name)
46
+ next unless needs_resolving?(param_option, param_resource, result)
47
+
48
+ resource_id = @command.get_resource_id(
49
+ param_resource, scoped: true, required: api_param.required?, all_options: result
50
+ )
51
+ result[param_option] = resource_id if resource_id
26
52
  end
27
53
  result
28
-
29
54
  rescue HammerCLIForeman::MissingSearchOptions => e
30
-
31
- switches = @command.class.find_options(:referenced_resource => e.resource.singular_name).map(&:long_switch)
55
+ switches = @command.class.find_options(referenced_resource: e.resource.singular_name).map(&:long_switch)
32
56
 
33
57
  if switches.empty?
34
58
  error_message = _("Could not find %{resource}. Some search options were missing, please see --help.")
@@ -40,12 +64,18 @@ module HammerCLIForeman
40
64
 
41
65
  raise MissingSearchOptions.new(
42
66
  error_message % {
43
- :resource => e.resource.singular_name,
44
- :switches => switches.join(", ")
67
+ resource: e.resource.singular_name,
68
+ switches: switches.join(', ')
45
69
  },
46
70
  e.resource
47
71
  )
48
72
  end
73
+
74
+ private
75
+
76
+ def cli_option_resource_id(resource)
77
+ HammerCLI.option_accessor_name("#{resource.singular_name}_id")
78
+ end
49
79
  end
50
80
  end
51
81
  end
@@ -6,25 +6,57 @@ module HammerCLIForeman
6
6
  end
7
7
 
8
8
  def param_updatable?(param_resource)
9
- param_resource && @command.respond_to?(HammerCLI.option_accessor_name("#{param_resource.singular_name}_ids"))
9
+ param_resource && @command.respond_to?(cli_option_resource_ids(param_resource))
10
10
  end
11
11
 
12
12
  def available_ids_params
13
13
  IdArrayParamsFilter.new(:only_required => false).for_action(@command.resource.action(@command.action))
14
14
  end
15
15
 
16
- def get_options(defined_options, result)
17
- return result if @command.action.nil?
16
+ def needs_resolving?(param_option, param_resource, all_opts)
17
+ return false unless param_updatable?(param_resource)
18
+
19
+ cli_searchables_set = @command.searchables.for(param_resource).any? do |s|
20
+ option = HammerCLI.option_accessor_name("#{param_resource.singular_name}_#{s.plural_name}")
21
+ next false unless @command.respond_to?(option)
22
+
23
+ !@command.send(option).nil?
24
+ end
25
+ if cli_searchables_set
26
+ # Remove set '<resource_name>_ids' option to force resolving in case of
27
+ # '<resource_name>_[names|titles]' were set from CLI
28
+ all_opts.delete(param_option)
29
+ true
30
+ else
31
+ # Don't resolve if resource ids were set via CLI
32
+ return false if @command.send(cli_option_resource_ids(param_resource))
33
+
34
+ all_opts[param_option].nil?
35
+ end
36
+ end
37
+
38
+ def get_options(_defined_options, result)
18
39
  # resolve all '<resource_name>_ids' parameters if they are defined as options
40
+ return result if @command.action.nil?
41
+
19
42
  available_ids_params.each do |api_param|
20
43
  param_resource = HammerCLIForeman.param_to_resource(api_param.name)
21
- if result[HammerCLI.option_accessor_name(api_param.name)].nil? && param_updatable?(param_resource)
22
- resource_ids = @command.get_resource_ids(param_resource, :scoped => true, :required => api_param.required?, :all_options => result)
23
- result[HammerCLI.option_accessor_name(api_param.name)] = resource_ids if resource_ids
24
- end
44
+ param_option = HammerCLI.option_accessor_name(api_param.name)
45
+ next unless needs_resolving?(param_option, param_resource, result)
46
+
47
+ resource_ids = @command.get_resource_ids(
48
+ param_resource, scoped: true, required: api_param.required?, all_options: result
49
+ )
50
+ result[param_option] = resource_ids if resource_ids
25
51
  end
26
52
  result
27
53
  end
54
+
55
+ private
56
+
57
+ def cli_option_resource_ids(resource)
58
+ HammerCLI.option_accessor_name("#{resource.singular_name}_ids")
59
+ end
28
60
  end
29
61
  end
30
62
  end
@@ -3,6 +3,5 @@ require 'hammer_cli_foreman/option_sources/ids_params'
3
3
  require 'hammer_cli_foreman/option_sources/self_param'
4
4
  require 'hammer_cli_foreman/option_sources/user_params'
5
5
  require 'hammer_cli_foreman/option_sources/fields_params'
6
- require 'hammer_cli_foreman/option_sources/puppet_environment_params'
7
6
  require 'hammer_cli_foreman/option_sources/new_params'
8
7
  require 'hammer_cli_foreman/option_sources/referenced_resource_id_params'
@@ -36,7 +36,6 @@ module HammerCLIForeman
36
36
  HammerCLIForeman::References.partition_tables(self)
37
37
  HammerCLIForeman::References.domains(self)
38
38
  HammerCLIForeman::References.realms(self)
39
- HammerCLIForeman::References.environments(self)
40
39
  HammerCLIForeman::References.hostgroups(self)
41
40
  HammerCLIForeman::References.parameters(self)
42
41
  collection :locations, _("Locations"), :numbered => false, :hide_blank => true do
@@ -59,8 +58,6 @@ module HammerCLIForeman
59
58
  failure_message _("Could not create the organization")
60
59
 
61
60
  build_options
62
-
63
- extend_with(HammerCLIForeman::CommandExtensions::PuppetEnvironments.new)
64
61
  end
65
62
 
66
63
 
@@ -73,8 +70,6 @@ module HammerCLIForeman
73
70
  failure_message _("Could not update the organization")
74
71
 
75
72
  build_options
76
-
77
- extend_with(HammerCLIForeman::CommandExtensions::PuppetEnvironments.new)
78
73
  end
79
74
 
80
75
 
@@ -114,7 +109,6 @@ module HammerCLIForeman
114
109
 
115
110
 
116
111
  HammerCLIForeman::AssociatingCommands::Hostgroup.extend_command(self)
117
- HammerCLIForeman::AssociatingCommands::PuppetEnvironment.extend_command(self)
118
112
  HammerCLIForeman::AssociatingCommands::Domain.extend_command(self)
119
113
  HammerCLIForeman::AssociatingCommands::Medium.extend_command(self)
120
114
  HammerCLIForeman::AssociatingCommands::Subnet.extend_command(self)
@@ -19,7 +19,12 @@ module HammerCLIForeman
19
19
  response = send_request
20
20
  print_data(response)
21
21
 
22
- return 1 if HammerCLIForeman::CommandExtensions::Ping.failed?(response)
22
+ if HammerCLIForeman::CommandExtensions::Ping.failed?(response)
23
+ HammerCLIForeman::CommandExtensions::Ping.check_for_unrecognized(
24
+ response, output_definition
25
+ )
26
+ return 1
27
+ end
23
28
 
24
29
  HammerCLI::EX_OK
25
30
  end
@@ -112,14 +112,6 @@ module HammerCLIForeman
112
112
  end
113
113
  end
114
114
 
115
- def self.environments(dsl)
116
- dsl.build do
117
- collection :environments, _("Environments"), :numbered => false do
118
- custom_field Fields::Reference
119
- end
120
- end
121
- end
122
-
123
115
  def self.hostgroups(dsl)
124
116
  dsl.build do
125
117
  collection :hostgroups, _("Hostgroups"), :numbered => false do
@@ -153,14 +145,6 @@ module HammerCLIForeman
153
145
  end
154
146
  end
155
147
 
156
- def self.puppetclasses(dsl)
157
- dsl.build do
158
- collection :puppetclasses, _("Puppetclasses"), :numbered => false do
159
- custom_field Fields::Reference
160
- end
161
- end
162
- end
163
-
164
148
  def self.operating_systems(dsl)
165
149
  dsl.build do
166
150
  collection :operatingsystems, _("Operating systems"), :numbered => false do
@@ -0,0 +1,18 @@
1
+ module HammerCLIForeman
2
+ class Registration < HammerCLIForeman::Command
3
+ resource :registration_commands
4
+
5
+ class GenerateCommand < HammerCLIForeman::CreateCommand
6
+ command_name 'generate-command'
7
+ failure_message _("Failed to generate registration command")
8
+
9
+ def print_data(registration_command)
10
+ puts registration_command
11
+ end
12
+
13
+ build_options
14
+ end
15
+
16
+ autoload_subcommands
17
+ end
18
+ end
@@ -20,7 +20,7 @@ module HammerCLIForeman
20
20
  data
21
21
  end
22
22
 
23
- build_options expand: { except: %i[organizations locations] }, without: %i[organization_id location_id]
23
+ build_options
24
24
  end
25
25
 
26
26
  class UpdateCommand < HammerCLIForeman::UpdateCommand
@@ -29,7 +29,7 @@ module HammerCLIForeman
29
29
  success_message _("Setting [%{name}] updated to [%{value}].")
30
30
  failure_message _("Could not update the setting")
31
31
 
32
- build_options expand: { except: %i[organizations locations] }, without: %i[organization_id location_id]
32
+ build_options
33
33
  end
34
34
 
35
35
  class InfoCommand < HammerCLIForeman::InfoCommand
@@ -42,7 +42,7 @@ module HammerCLIForeman
42
42
  field :value, _("Value")
43
43
  end
44
44
 
45
- build_options expand: { except: %i[organizations locations] }, without: %i[organization_id location_id]
45
+ build_options
46
46
  end
47
47
 
48
48
 
@@ -10,8 +10,9 @@ module HammerCLIForeman
10
10
  output do
11
11
  field :id, _("Id")
12
12
  field :name, _("Name")
13
+ field :status, _("Status")
13
14
  field :url, _("URL")
14
- field :_features, _( "Features"), Fields::List, :width => 25, :hide_blank => true
15
+ field :_features, _( "Features"), Fields::List, :hide_blank => true
15
16
  end
16
17
 
17
18
  def extend_data(proxy)
@@ -22,12 +23,13 @@ module HammerCLIForeman
22
23
  build_options
23
24
  end
24
25
 
25
-
26
26
  class InfoCommand < HammerCLIForeman::InfoCommand
27
-
28
27
  output ListCommand.output_definition do
29
- collection :features, _("Features"), :numbered => false do
30
- custom_field Fields::Reference
28
+ field :version, _("Version")
29
+ field :hosts_count, _("Host_count")
30
+ collection :features, _("Features") do
31
+ field :name, _('Name')
32
+ field :version, _('Version')
31
33
  end
32
34
  HammerCLIForeman::References.taxonomies(self)
33
35
  HammerCLIForeman::References.timestamps(self)
@@ -60,58 +62,6 @@ module HammerCLIForeman
60
62
  build_options
61
63
  end
62
64
 
63
-
64
- class ImportPuppetClassesCommand < HammerCLIForeman::Command
65
- action :import_puppetclasses
66
-
67
- command_name "import-classes"
68
-
69
- option "--dryrun", :flag, _("Do not run the import")
70
-
71
- output do
72
- field :message, _("Result"), Fields::LongText
73
- collection :results, _("Changed environments"), :hide_blank => true do
74
- field :name, nil
75
- collection :new_puppetclasses, _("New classes"), :hide_blank => true, :numbered => false do
76
- field nil, nil
77
- end
78
- collection :updated_puppetclasses, _("Updated classes"), :hide_blank => true, :numbered => false do
79
- field nil, nil
80
- end
81
- collection :obsolete_puppetclasses, _("Removed classes"), :hide_blank => true, :numbered => false do
82
- field nil, nil
83
- end
84
- collection :ignored_puppetclasses, _("Ignored classes"), :hide_blank => true, :numbered => false do
85
- field nil, nil
86
- end
87
- end
88
- end
89
-
90
- build_options do |o|
91
- o.without(:smart_proxy_id, :dryrun)
92
- o.expand.except(:smart_proxies)
93
- end
94
-
95
- def request_params
96
- opts = super
97
- opts['dryrun'] = option_dryrun? || false
98
- opts
99
- end
100
-
101
- def transform_format(data)
102
- # Overriding the default behavior that tries to remove nesting
103
- # when there's only {"message": "..."}
104
- data
105
- end
106
-
107
- def print_data(record)
108
- print_record(output_definition, record)
109
- end
110
-
111
- extend_with(HammerCLIForeman::CommandExtensions::PuppetEnvironment.new)
112
- end
113
-
114
-
115
65
  class RefreshFeaturesCommand < HammerCLIForeman::Command
116
66
 
117
67
  action :refresh
@@ -5,25 +5,13 @@ module HammerCLIForeman
5
5
  resource :provisioning_templates
6
6
 
7
7
  module TemplateCreateUpdateCommons
8
-
9
8
  def option_snippet
10
9
  option_type && (option_type == "snippet")
11
10
  end
12
11
 
13
- def option_template_kind_id
14
- table = kinds.inject({}){ |result, k| result.update(k["name"] => k["id"]) }
15
- if option_snippet == false && table[option_type].nil?
16
- signal_usage_error _("unknown template kind")
17
- else
18
- table[option_type]
19
- end
20
- end
21
-
22
- def kinds
23
- HammerCLIForeman.collection_to_common_format(
24
- HammerCLIForeman.foreman_resource!(:template_kinds).call(:index))
25
- end
26
-
12
+ # This method is for IdParams option source to make resolver work for
13
+ # --type option
14
+ def option_template_kind_id; end
27
15
  end
28
16
 
29
17
  class ListCommand < HammerCLIForeman::ListCommand
@@ -56,9 +56,9 @@ module HammerCLIForeman
56
56
  success_message _("User [%{login}] created.")
57
57
  failure_message _("Could not create the user")
58
58
 
59
- extend_with(HammerCLIForeman::CommandExtensions::User.new)
60
-
61
59
  build_options
60
+
61
+ extend_with(HammerCLIForeman::CommandExtensions::User.new)
62
62
  end
63
63
 
64
64
 
@@ -66,9 +66,9 @@ module HammerCLIForeman
66
66
  success_message _("User [%{login}] updated.")
67
67
  failure_message _("Could not update the user")
68
68
 
69
- extend_with(HammerCLIForeman::CommandExtensions::User.new)
70
-
71
69
  build_options
70
+
71
+ extend_with(HammerCLIForeman::CommandExtensions::User.new)
72
72
  end
73
73
 
74
74