hammer_cli_foreman 3.0.0 → 3.3.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 (66) hide show
  1. checksums.yaml +4 -4
  2. data/config/foreman.yml +4 -0
  3. data/doc/configuration.md +30 -0
  4. data/doc/release_notes.md +31 -0
  5. data/lib/hammer_cli_foreman/api/authenticator.rb +9 -0
  6. data/lib/hammer_cli_foreman/api/connection.rb +2 -0
  7. data/lib/hammer_cli_foreman/api/negotiate_auth.rb +36 -0
  8. data/lib/hammer_cli_foreman/api/session_authenticator_wrapper.rb +6 -2
  9. data/lib/hammer_cli_foreman/api.rb +2 -1
  10. data/lib/hammer_cli_foreman/auth.rb +13 -0
  11. data/lib/hammer_cli_foreman/command_extensions/domain.rb +20 -0
  12. data/lib/hammer_cli_foreman/command_extensions/subnet.rb +25 -10
  13. data/lib/hammer_cli_foreman/command_extensions/user.rb +9 -5
  14. data/lib/hammer_cli_foreman/command_extensions.rb +1 -0
  15. data/lib/hammer_cli_foreman/commands.rb +6 -3
  16. data/lib/hammer_cli_foreman/compute_attribute.rb +1 -1
  17. data/lib/hammer_cli_foreman/compute_resource/libvirt.rb +4 -2
  18. data/lib/hammer_cli_foreman/compute_resource/vmware.rb +4 -2
  19. data/lib/hammer_cli_foreman/compute_resource.rb +1 -0
  20. data/lib/hammer_cli_foreman/domain.rb +5 -28
  21. data/lib/hammer_cli_foreman/exception_handler.rb +26 -0
  22. data/lib/hammer_cli_foreman/filter.rb +3 -3
  23. data/lib/hammer_cli_foreman/host.rb +1 -0
  24. data/lib/hammer_cli_foreman/hostgroup.rb +13 -6
  25. data/lib/hammer_cli_foreman/hosts/common_update_options.rb +7 -7
  26. data/lib/hammer_cli_foreman/id_resolver.rb +7 -7
  27. data/lib/hammer_cli_foreman/option_builders.rb +65 -53
  28. data/lib/hammer_cli_foreman/option_sources/id_params.rb +21 -8
  29. data/lib/hammer_cli_foreman/option_sources/ids_params.rb +22 -9
  30. data/lib/hammer_cli_foreman/partition_table.rb +30 -0
  31. data/lib/hammer_cli_foreman/report_template.rb +15 -0
  32. data/lib/hammer_cli_foreman/smart_proxy.rb +18 -5
  33. data/lib/hammer_cli_foreman/template.rb +33 -15
  34. data/lib/hammer_cli_foreman/user.rb +5 -4
  35. data/lib/hammer_cli_foreman/version.rb +1 -1
  36. data/locale/ca/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  37. data/locale/de/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  38. data/locale/en/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  39. data/locale/en_GB/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  40. data/locale/es/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  41. data/locale/fr/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  42. data/locale/it/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  43. data/locale/ja/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  44. data/locale/ko/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  45. data/locale/pt_BR/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  46. data/locale/ru/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  47. data/locale/zh_CN/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  48. data/locale/zh_TW/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  49. data/test/data/3.1/foreman_api.json +1 -0
  50. data/test/functional/compute_attribute_test.rb +20 -20
  51. data/test/functional/domain/create_test.rb +91 -0
  52. data/test/functional/domain/update_test.rb +90 -0
  53. data/test/functional/host_test.rb +34 -0
  54. data/test/functional/hostgroup/create_test.rb +11 -0
  55. data/test/functional/hostgroup/update_test.rb +11 -0
  56. data/test/functional/partition_table_test.rb +63 -0
  57. data/test/functional/personal_access_token_test.rb +4 -4
  58. data/test/functional/report_template_test.rb +24 -0
  59. data/test/functional/template_test.rb +134 -14
  60. data/test/functional/user_mail_notification_test.rb +3 -3
  61. data/test/test_helper.rb +1 -1
  62. data/test/unit/commands_test.rb +1 -2
  63. data/test/unit/option_builders_test.rb +88 -83
  64. data/test/unit/option_sources/id_params_test.rb +0 -9
  65. data/test/unit/option_sources/ids_params_test.rb +0 -9
  66. metadata +54 -44
@@ -1,14 +1,12 @@
1
1
  module HammerCLIForeman
2
2
 
3
3
  class Searchable
4
- attr_reader :name, :description, :format
4
+ attr_reader :name, :description
5
5
 
6
6
  def initialize(name, description, options={})
7
7
  @name = name
8
8
  @description = description
9
9
  @editable = options[:editable].nil? ? true : options[:editable]
10
- @format = options[:format]
11
- @parent = options[:parent]
12
10
  end
13
11
 
14
12
  def plural_name
@@ -18,10 +16,6 @@ module HammerCLIForeman
18
16
  def editable?
19
17
  @editable
20
18
  end
21
-
22
- def parent?
23
- @parent
24
- end
25
19
  end
26
20
 
27
21
  class Searchables
@@ -130,6 +124,12 @@ module HammerCLIForeman
130
124
  @searchables.for(resource)
131
125
  end
132
126
 
127
+ def template_kind_id(options = {})
128
+ name = options['option_type'] == 'snippet' ? nil : options['option_type']
129
+ options['option_name'] = name
130
+ get_id(:template_kinds, options)
131
+ end
132
+
133
133
  protected
134
134
 
135
135
  def define_id_finders
@@ -172,8 +172,7 @@ module HammerCLIForeman
172
172
  def build(builder_params={})
173
173
  resource_name_map = builder_params[:resource_mapping] || {}
174
174
  @searchables.for(@resource).collect do |s|
175
- family = HammerCLI::Options::OptionFamily.new
176
- family.parent(
175
+ option(
177
176
  optionamize("--#{s.name}"),
178
177
  s.name.upcase,
179
178
  s.description,
@@ -213,23 +212,43 @@ module HammerCLIForeman
213
212
 
214
213
  def build(builder_params={})
215
214
  resource_name_map = builder_params[:resource_mapping] || {}
216
- dependent_options(@resource, resource_name_map)
215
+ command = builder_params[:command]
216
+ dependent_options(@resource, resource_name_map, command)
217
217
  end
218
218
 
219
219
  protected
220
220
 
221
- def dependent_options(resource, resource_name_map)
221
+ def dependent_options(resource, resource_name_map, command)
222
222
  options = []
223
223
  searchables = @searchables.for(resource)
224
224
  resource_name = resource.singular_name
225
225
  aliased_name = aliased(resource_name, resource_name_map)
226
226
  types = searchables.map(&:name).push('id').map(&:capitalize).join('/')
227
227
  associated_resource = aliased_name.to_s.tr('_', ' ')
228
- family = HammerCLI::Options::OptionFamily.new(
229
- referenced_resource: resource_name,
230
- aliased_resource: aliased_name,
231
- description: _('%{types} of associated %{resource}') % { types: types, resource: associated_resource }
232
- )
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
233
252
 
234
253
  unless searchables.empty?
235
254
  first = searchables[0]
@@ -240,31 +259,25 @@ module HammerCLIForeman
240
259
  options << family.child(
241
260
  optionamize("--#{aliased_name}"),
242
261
  "#{aliased_name}_#{first.name}".upcase,
243
- first.description || " ",
244
- 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
245
266
  )
246
267
  # Other options are named by the resource plus the searchable name
247
268
  # Eg. --organization-label with accessor option_organization_label
248
269
  remaining.each do |s|
249
- options << family.send(s.parent? ? :parent : :child,
270
+ options << family.child(
250
271
  optionamize("--#{aliased_name}-#{s.name}"),
251
272
  "#{aliased_name}_#{s.name}".upcase,
252
- s.description || " ",
273
+ s.description || ' ',
253
274
  attribute_name: HammerCLI.option_accessor_name("#{resource_name}_#{s.name}"),
254
- format: s.format
275
+ referenced_resource: resource_name,
276
+ aliased_resource: aliased_name
255
277
  )
256
278
  end
257
279
  end
258
280
 
259
- unless options.any? { |o| o.handles?(optionamize("--#{aliased_name}-id")) }
260
- options << family.parent(
261
- optionamize("--#{aliased_name}-id"),
262
- "#{aliased_name}_id".upcase,
263
- description("#{aliased_name}_id", @context[:action]),
264
- attribute_name: HammerCLI.option_accessor_name("#{resource_name}_id"),
265
- format: HammerCLI::Options::Normalizers::Number.new
266
- )
267
- end
268
281
  options
269
282
  end
270
283
 
@@ -285,15 +298,25 @@ module HammerCLIForeman
285
298
  class UpdateDependentSearchablesOptionBuilder < DependentSearchablesOptionBuilder
286
299
  protected
287
300
 
288
- def dependent_options(resource, resource_name_map)
301
+ def dependent_options(resource, resource_name_map, command)
289
302
  options = []
290
303
  searchables = @searchables.for(resource)
291
304
  resource_name = resource.singular_name
292
305
  aliased_name = aliased(resource_name, resource_name_map)
306
+ # Those options are not coming from API docs, thus create a new family only
293
307
  family = HammerCLI::Options::OptionFamily.new(
294
308
  prefix: 'new-',
295
309
  aliased_resource: aliased_name,
296
- 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
297
320
  )
298
321
  unless searchables.empty?
299
322
  first = searchables[0]
@@ -304,73 +327,63 @@ module HammerCLIForeman
304
327
  options << family.child(
305
328
  optionamize("--new-#{aliased_name}"),
306
329
  "new_#{aliased_name}_#{first.name}".upcase,
307
- _('Use to update'),
330
+ _('Use to update associated %s') % aliased_name,
308
331
  attribute_name: HammerCLI.option_accessor_name("new_#{resource_name}_#{first.name}")
309
332
  )
310
333
  # Other options are named by the resource plus the searchable name
311
334
  # Eg. --new-organization-label with accessor option_new_organization_label
312
335
  remaining.each do |s|
313
- options << family.send(s.parent? ? :parent : :child,
336
+ options << family.child(
314
337
  optionamize("--new-#{aliased_name}-#{s.name}"),
315
338
  "new_#{aliased_name}_#{s.name}".upcase,
316
- _('Use to update'),
339
+ _('Use to update associated %s') % aliased_name,
317
340
  attribute_name: HammerCLI.option_accessor_name("new_#{resource_name}_#{s.name}")
318
341
  )
319
342
  end
320
343
  end
321
344
 
322
- unless options.any? { |o| o.handles?(optionamize("--new-#{aliased_name}-id")) }
323
- options << family.parent(
324
- optionamize("--new-#{aliased_name}-id"),
325
- "new_#{aliased_name}_id".upcase,
326
- _('Use to update'),
327
- attribute_name: HammerCLI.option_accessor_name("new_#{resource_name}_id"),
328
- format: HammerCLI::Options::Normalizers::Number.new
329
- )
330
- end
331
345
  options
332
346
  end
333
347
  end
334
348
 
335
349
  class DependentSearchablesArrayOptionBuilder < DependentSearchablesOptionBuilder
336
-
337
-
338
- def dependent_options(resource, resource_name_map)
350
+ def dependent_options(resource, resource_name_map, command)
339
351
  options = []
340
352
  searchables = @searchables.for(resource)
341
353
  resource_name = resource.singular_name
342
354
 
343
355
  aliased_name = aliased(resource_name, resource_name_map)
344
356
  aliased_plural_name = aliased(resource.name, resource_name_map)
345
-
346
357
  unless searchables.empty?
347
358
  first = searchables[0]
348
359
  remaining = searchables[1..-1] || []
349
- types = searchables.map(&:plural_name).map(&:capitalize).join('/')
350
- associated_resource = aliased_plural_name.to_s.tr('_', ' ')
351
- family = HammerCLI::Options::OptionFamily.new(
352
- format: HammerCLI::Options::Normalizers::List.new,
353
- referenced_resource: resource_name,
354
- aliased_resource: aliased_name,
355
- description: _('%{types} of associated %{resource}') % { types: types, resource: associated_resource }
356
- )
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
357
364
  # First option is named by the resource
358
365
  # Eg. --organizations with accessor option_organization_names
359
366
  options << family.child(
360
367
  optionamize("--#{aliased_plural_name}"),
361
368
  "#{aliased_name}_#{first.plural_name}".upcase,
362
369
  ' ',
363
- 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
364
374
  )
365
375
 
366
376
  # Other options are named by the resource plus the searchable name
367
377
  # Eg. --organization-labels with accessor option_organization_labels
368
378
  remaining.each do |s|
369
- options << family.send(s.parent? ? :parent : :child,
379
+ options << family.child(
370
380
  optionamize("--#{aliased_name}-#{s.plural_name}"),
371
381
  "#{aliased_name}_#{s.plural_name}".upcase,
372
382
  ' ',
373
- 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
374
387
  )
375
388
  end
376
389
  end
@@ -421,4 +434,3 @@ module HammerCLIForeman
421
434
  end
422
435
 
423
436
  end
424
-
@@ -6,7 +6,7 @@ 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
@@ -16,16 +16,23 @@ module HammerCLIForeman
16
16
  def needs_resolving?(param_option, param_resource, all_opts)
17
17
  return false unless param_updatable?(param_resource)
18
18
 
19
- searchables_set = @command.searchables.for(param_resource).any? do |s|
19
+ cli_searchables_set = @command.searchables.for(param_resource).any? do |s|
20
20
  option = HammerCLI.option_accessor_name("#{param_resource.singular_name}_#{s.name}")
21
- !all_opts[option].nil?
21
+ next false unless @command.respond_to?(option)
22
+
23
+ !@command.send(option).nil?
22
24
  end
23
- return all_opts[param_option].nil? unless searchables_set
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))
24
33
 
25
- # Remove set '<resource_name>_id' option to force resolving in case of
26
- # '<resource_name>_[name|title]' was set
27
- all_opts.delete(param_option)
28
- true
34
+ all_opts[param_option].nil?
35
+ end
29
36
  end
30
37
 
31
38
  def get_options(_defined_options, result)
@@ -63,6 +70,12 @@ module HammerCLIForeman
63
70
  e.resource
64
71
  )
65
72
  end
73
+
74
+ private
75
+
76
+ def cli_option_resource_id(resource)
77
+ HammerCLI.option_accessor_name("#{resource.singular_name}_id")
78
+ end
66
79
  end
67
80
  end
68
81
  end
@@ -6,7 +6,7 @@ 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
@@ -16,16 +16,23 @@ module HammerCLIForeman
16
16
  def needs_resolving?(param_option, param_resource, all_opts)
17
17
  return false unless param_updatable?(param_resource)
18
18
 
19
- searchables_set = @command.searchables.for(param_resource).any? do |s|
19
+ cli_searchables_set = @command.searchables.for(param_resource).any? do |s|
20
20
  option = HammerCLI.option_accessor_name("#{param_resource.singular_name}_#{s.plural_name}")
21
- !all_opts[option].nil?
22
- end
23
- return all_opts[param_option].nil? unless searchables_set
21
+ next false unless @command.respond_to?(option)
24
22
 
25
- # Remove set '<resource_name>_ids' option to force resolving in case of
26
- # '<resource_name>_[names|titles]' was set
27
- all_opts.delete(param_option)
28
- true
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
29
36
  end
30
37
 
31
38
  def get_options(_defined_options, result)
@@ -44,6 +51,12 @@ module HammerCLIForeman
44
51
  end
45
52
  result
46
53
  end
54
+
55
+ private
56
+
57
+ def cli_option_resource_ids(resource)
58
+ HammerCLI.option_accessor_name("#{resource.singular_name}_ids")
59
+ end
47
60
  end
48
61
  end
49
62
  end
@@ -71,6 +71,36 @@ module HammerCLIForeman
71
71
  build_options
72
72
  end
73
73
 
74
+ class ImportCommand < HammerCLIForeman::Command
75
+ command_name "import"
76
+ action :import
77
+ option '--file', 'PATH', _('Path to a file that contains the template content including metadata'),
78
+ :attribute_name => :option_template, :format => HammerCLI::Options::Normalizers::File.new
79
+
80
+ validate_options do
81
+ all(:option_name, :option_template).required
82
+ end
83
+
84
+ success_message _("Import partition table template succeeded.")
85
+ failure_message _("Could not import partition table template")
86
+
87
+ build_options :without => [:template]
88
+ end
89
+
90
+ class ExportCommand < HammerCLIForeman::DownloadCommand
91
+ command_name "export"
92
+ action :export
93
+
94
+ def default_filename
95
+ "Partition Table Template-#{Time.new.strftime("%Y-%m-%d")}.txt"
96
+ end
97
+
98
+ def saved_response_message(filepath)
99
+ _("The partition table template has been saved to %{path}.") % { path: filepath }
100
+ end
101
+
102
+ build_options
103
+ end
74
104
 
75
105
  HammerCLIForeman::AssociatingCommands::OperatingSystem.extend_command(self)
76
106
 
@@ -148,6 +148,21 @@ module HammerCLIForeman
148
148
  build_options :without => [:template]
149
149
  end
150
150
 
151
+ class ExportCommand < HammerCLIForeman::DownloadCommand
152
+ command_name "export"
153
+ action :export
154
+
155
+ def default_filename
156
+ "Report Template-#{Time.new.strftime("%Y-%m-%d")}.txt"
157
+ end
158
+
159
+ def saved_response_message(filepath)
160
+ _("The report template has been saved to %{path}.") % { path: filepath }
161
+ end
162
+
163
+ build_options
164
+ end
165
+
151
166
  class ReportDataCommand < HammerCLIForeman::DownloadCommand
152
167
  command_name "report-data"
153
168
  action :report_data
@@ -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)
@@ -71,6 +73,17 @@ module HammerCLIForeman
71
73
  build_options
72
74
  end
73
75
 
76
+ class ImportSubnetsCommand < HammerCLIForeman::Command
77
+
78
+ action :import_subnets
79
+
80
+ command_name "import-subnets"
81
+ success_message _("Import subnets succeeded.")
82
+ failure_message _("Could not import subnets")
83
+
84
+ build_options
85
+ end
86
+
74
87
  autoload_subcommands
75
88
  end
76
89
 
@@ -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
@@ -154,7 +142,37 @@ module HammerCLIForeman
154
142
  build_options
155
143
  end
156
144
 
145
+ class ImportCommand < HammerCLIForeman::Command
146
+ command_name "import"
147
+ action :import
148
+ option '--file', 'PATH', _('Path to a file that contains the template content including metadata'),
149
+ :attribute_name => :option_template, :format => HammerCLI::Options::Normalizers::File.new
150
+
151
+ validate_options do
152
+ all(:option_name, :option_template).required
153
+ end
154
+
155
+ success_message _("Import provisioning template succeeded.")
156
+ failure_message _("Could not import provisioning template")
157
+
158
+ build_options :without => [:template]
159
+ end
160
+
161
+ class ExportCommand < HammerCLIForeman::DownloadCommand
162
+ command_name "export"
163
+ action :export
164
+
165
+ def default_filename
166
+ "Template-#{Time.new.strftime("%Y-%m-%d")}.txt"
167
+ end
168
+
169
+ def saved_response_message(filepath)
170
+ _("The provisioning template has been saved to %{path}.") % { path: filepath }
171
+ end
157
172
 
173
+ build_options
174
+ end
175
+
158
176
  class BuildPXEDefaultCommand < HammerCLIForeman::Command
159
177
 
160
178
  action :build_pxe_default
@@ -29,6 +29,7 @@ module HammerCLIForeman
29
29
  class InfoCommand < HammerCLIForeman::InfoCommand
30
30
 
31
31
  output ListCommand.output_definition do
32
+ field :mail_enabled, _("Email enabled"), Fields::Boolean
32
33
  field :effective_admin, _("Effective admin"), Fields::Boolean
33
34
  field :locale, _("Locale")
34
35
  field :timezone, _("Timezone")
@@ -56,9 +57,9 @@ module HammerCLIForeman
56
57
  success_message _("User [%{login}] created.")
57
58
  failure_message _("Could not create the user")
58
59
 
59
- extend_with(HammerCLIForeman::CommandExtensions::User.new)
60
-
61
60
  build_options
61
+
62
+ extend_with(HammerCLIForeman::CommandExtensions::User.new)
62
63
  end
63
64
 
64
65
 
@@ -66,9 +67,9 @@ module HammerCLIForeman
66
67
  success_message _("User [%{login}] updated.")
67
68
  failure_message _("Could not update the user")
68
69
 
69
- extend_with(HammerCLIForeman::CommandExtensions::User.new)
70
-
71
70
  build_options
71
+
72
+ extend_with(HammerCLIForeman::CommandExtensions::User.new)
72
73
  end
73
74
 
74
75
 
@@ -1,5 +1,5 @@
1
1
  module HammerCLIForeman
2
2
  def self.version
3
- @version ||= Gem::Version.new "3.0.0"
3
+ @version ||= Gem::Version.new "3.3.0"
4
4
  end
5
5
  end