hammer_cli_foreman 0.17.2 → 0.18.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 (52) hide show
  1. checksums.yaml +4 -4
  2. data/doc/host_create.md +17 -17
  3. data/doc/release_notes.md +19 -6
  4. data/lib/hammer_cli_foreman/command_extensions.rb +2 -3
  5. data/lib/hammer_cli_foreman/command_extensions/fields.rb +13 -0
  6. data/lib/hammer_cli_foreman/command_extensions/hosts.rb +1 -0
  7. data/lib/hammer_cli_foreman/command_extensions/hosts/help.rb +2 -0
  8. data/lib/hammer_cli_foreman/command_extensions/hosts/help/compute_resources.rb +85 -0
  9. data/lib/hammer_cli_foreman/command_extensions/hosts/help/interfaces.rb +55 -0
  10. data/lib/hammer_cli_foreman/commands.rb +111 -0
  11. data/lib/hammer_cli_foreman/common_parameter.rb +4 -2
  12. data/lib/hammer_cli_foreman/compute_attribute.rb +20 -36
  13. data/lib/hammer_cli_foreman/compute_resource.rb +5 -25
  14. data/lib/hammer_cli_foreman/compute_resource/base.rb +6 -4
  15. data/lib/hammer_cli_foreman/compute_resource/ec2.rb +10 -9
  16. data/lib/hammer_cli_foreman/compute_resource/gce.rb +22 -8
  17. data/lib/hammer_cli_foreman/compute_resource/libvirt.rb +14 -15
  18. data/lib/hammer_cli_foreman/compute_resource/openstack.rb +11 -9
  19. data/lib/hammer_cli_foreman/compute_resource/ovirt.rb +22 -17
  20. data/lib/hammer_cli_foreman/compute_resource/rackspace.rb +9 -6
  21. data/lib/hammer_cli_foreman/compute_resource/register_compute_resources.rb +1 -2
  22. data/lib/hammer_cli_foreman/compute_resource/utils.rb +27 -0
  23. data/lib/hammer_cli_foreman/compute_resource/vmware.rb +46 -37
  24. data/lib/hammer_cli_foreman/host.rb +30 -7
  25. data/lib/hammer_cli_foreman/hosts/common_update_options.rb +16 -1
  26. data/lib/hammer_cli_foreman/image.rb +1 -0
  27. data/lib/hammer_cli_foreman/option_builders.rb +46 -0
  28. data/lib/hammer_cli_foreman/option_sources.rb +2 -0
  29. data/lib/hammer_cli_foreman/option_sources/fields_params.rb +20 -0
  30. data/lib/hammer_cli_foreman/option_sources/new_params.rb +26 -0
  31. data/lib/hammer_cli_foreman/report_template.rb +6 -2
  32. data/lib/hammer_cli_foreman/version.rb +1 -1
  33. data/locale/ca/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  34. data/locale/de/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  35. data/locale/en/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  36. data/locale/en_GB/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  37. data/locale/es/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  38. data/locale/fr/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  39. data/locale/it/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  40. data/locale/ja/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  41. data/locale/ko/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  42. data/locale/pt_BR/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  43. data/locale/ru/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  44. data/locale/zh_CN/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  45. data/locale/zh_TW/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  46. data/test/data/1.22/foreman_api.json +1 -1
  47. data/test/functional/host_test.rb +89 -0
  48. data/test/functional/report_template_test.rb +19 -0
  49. data/test/unit/commands_test.rb +24 -1
  50. metadata +13 -7
  51. data/lib/hammer_cli_foreman/compute_resource/help_utils.rb +0 -34
  52. data/lib/hammer_cli_foreman/hosts/common_update_help.rb +0 -47
@@ -2,21 +2,24 @@ module HammerCLIForeman
2
2
  module ComputeResources
3
3
  class Rackspace < Base
4
4
  def name
5
- _('Rackspace')
5
+ 'Rackspace'
6
6
  end
7
7
 
8
8
  def compute_attributes
9
+ %w[flavor_id image_id]
10
+ end
11
+
12
+ def provider_specific_fields
9
13
  [
10
- 'flavor_id',
11
- 'image_id'
14
+ Fields::Field.new(:label => _('Region'), :path => [:region])
12
15
  ]
13
16
  end
14
17
 
15
18
  def mandatory_resource_options
16
- super + [:url]
19
+ super + %i[url]
17
20
  end
18
-
19
21
  end
22
+
20
23
  HammerCLIForeman.register_compute_resource('rackspace', Rackspace.new)
21
24
  end
22
- end
25
+ end
@@ -8,7 +8,6 @@ module HammerCLIForeman
8
8
  @compute_resources[name] = compute_resource
9
9
  end
10
10
 
11
-
12
11
  require 'hammer_cli_foreman/compute_resource/base'
13
12
  require 'hammer_cli_foreman/compute_resource/ec2.rb'
14
13
  require 'hammer_cli_foreman/compute_resource/gce.rb'
@@ -17,4 +16,4 @@ module HammerCLIForeman
17
16
  require 'hammer_cli_foreman/compute_resource/ovirt.rb'
18
17
  require 'hammer_cli_foreman/compute_resource/rackspace.rb'
19
18
  require 'hammer_cli_foreman/compute_resource/vmware.rb'
20
- end
19
+ end
@@ -0,0 +1,27 @@
1
+ module HammerCLIForeman
2
+ module ComputeResources
3
+ def self.get_image_uuid(compute_resource_id, image_id)
4
+ HammerCLIForeman.record_to_common_format(
5
+ HammerCLIForeman.foreman_resource(:images).call(
6
+ :show, 'compute_resource_id' => compute_resource_id, 'id' => image_id
7
+ )['uuid']
8
+ )
9
+ end
10
+
11
+ def self.get_host_compute_resource_id(host_id)
12
+ HammerCLIForeman.record_to_common_format(
13
+ HammerCLIForeman.foreman_resource(:hosts).call(
14
+ :show, 'id' => host_id
15
+ )['compute_resource_id']
16
+ )
17
+ end
18
+
19
+ def self.resource_provider(compute_resource_id)
20
+ HammerCLIForeman.record_to_common_format(
21
+ HammerCLIForeman.foreman_resource(:compute_resources).call(
22
+ :show, 'id' => compute_resource_id
23
+ )
24
+ )['provider'].downcase
25
+ end
26
+ end
27
+ end
@@ -1,68 +1,77 @@
1
1
  module HammerCLIForeman
2
2
  module ComputeResources
3
3
  class VMware < Base
4
- INTERFACE_TYPES = %w(
5
- VirtualVmxnet3,
6
- VirtualE1000
7
- )
4
+ INTERFACE_TYPES = %w[VirtualVmxnet3 VirtualE1000]
8
5
 
9
6
  def name
10
- _('VMware')
7
+ 'VMware'
11
8
  end
12
9
 
13
10
  def compute_attributes
14
11
  [
15
- ['cpus', _('CPU count')],
16
- ['corespersocket', _('Number of cores per socket (applicable to hardware versions < 10 only)')],
17
- ['memory_mb', _('Integer number, amount of memory in MB')],
18
- ['firmware', 'automatic/bios/efi'],
19
- ['cluster', _('Cluster ID from VMware')],
20
- ['resource_pool', _('Resource Pool ID from VMware')],
21
- ['path', _('Path to folder')],
22
- ['guest_id', _('Guest OS ID form VMware')],
23
- ['scsi_controller_type', _('ID of the controller from VMware')],
24
- ['hardware_version', _('Hardware version ID from VMware')],
25
- ['add_cdrom', _('Must be a 1 or 0, Add a CD-ROM drive to the virtual machine')],
26
- ['cpuHotAddEnabled', _('Must be a 1 or 0, lets you add memory resources while the machine is on')],
27
- ['memoryHotAddEnabled', _('Must be a 1 or 0, lets you add CPU resources while the machine is on')],
28
- ['annotation', _("Annotation Notes")]
12
+ ['cpus', _('CPU count')],
13
+ ['corespersocket', _('Number of cores per socket (applicable to hardware versions < 10 only)')],
14
+ ['memory_mb', _('Integer number, amount of memory in MB')],
15
+ ['firmware', 'automatic/bios/efi'],
16
+ ['cluster', _('Cluster ID from VMware')],
17
+ ['resource_pool', _('Resource Pool ID from VMware')],
18
+ ['path', _('Path to folder')],
19
+ ['guest_id', _('Guest OS ID form VMware')],
20
+ ['hardware_version', _('Hardware version ID from VMware')],
21
+ ['memoryHotAddEnabled', _('Must be a 1 or 0, lets you add CPU resources while the machine is on')],
22
+ ['cpuHotAddEnabled', _('Must be a 1 or 0, lets you add memory resources while the machine is on')],
23
+ ['add_cdrom', _('Must be a 1 or 0, Add a CD-ROM drive to the virtual machine')],
24
+ ['annotation', _('Annotation Notes')],
25
+ ['scsi_controllers', [_('List with SCSI controllers definitions'),
26
+ ' type - ' + _('ID of the controller from VMware'),
27
+ ' key - ' + _('Key of the controller (e.g. 1000)')
28
+ ].flatten(1).join("\n")]
29
29
  ]
30
30
  end
31
31
 
32
32
  def host_attributes
33
33
  [
34
- ['start', _("Must be a 1 or 0, whether to start the machine or not")],
34
+ ['start', _('Must be a 1 or 0, whether to start the machine or not')]
35
+ ]
36
+ end
37
+
38
+ def volume_attributes
39
+ [
40
+ ['name'],
41
+ ['storage_pod', _('Storage Pod ID from VMware')],
42
+ ['datastore', _('Datastore ID from VMware')],
43
+ ['mode', 'persistent/independent_persistent/independent_nonpersistent'],
44
+ ['size_gb', _('Integer number, volume size in GB')],
45
+ ['thin', 'true/false'],
46
+ ['eager_zero', 'true/false'],
47
+ ['controller_key', 'Associated SCSI controller key']
35
48
  ]
36
49
  end
37
50
 
38
51
  def interface_attributes
39
52
  [
40
- ['compute_type', [
41
- _('Type of the network adapter, for example one of:'),
42
- INTERFACE_TYPES.map { |it| ' ' + it },
43
- _('See documentation center for your version of vSphere to find more details about available adapter types:'),
44
- ' https://www.vmware.com/support/pubs/'].flatten(1).join("\n") ] ,
45
- ['compute_network', _('Network ID from VMware')]
53
+ ['compute_type', [
54
+ _('Type of the network adapter, for example one of:'),
55
+ INTERFACE_TYPES.map { |it| ' ' + it },
56
+ _('See documentation center for your version of vSphere to find more details about available adapter types:'),
57
+ ' https://www.vmware.com/support/pubs/'
58
+ ].flatten(1).join("\n")],
59
+ ['compute_network', _('Network ID from VMware')]
46
60
  ]
47
61
  end
48
62
 
49
- def volume_attributes;
63
+ def provider_specific_fields
50
64
  [
51
- ['name'],
52
- ['storage_pod', _('Storage Pod ID from VMware')],
53
- ['datastore', _('Datastore ID from VMware')],
54
- ['size_gb', _('Integer number, volume size in GB')],
55
- ['thin', 'true/false'],
56
- ['eager_zero', 'true/false'],
57
- ['mode', 'persistent/independent_persistent/independent_nonpersistent']
65
+ Fields::Field.new(:label => _('Datacenter'), :path => [:datacenter]),
66
+ Fields::Field.new(:label => _('Server'), :path => [:server])
58
67
  ]
59
68
  end
60
69
 
61
70
  def mandatory_resource_options
62
- super + [:user, :password, :datacenter, :server]
63
-
71
+ super + %i[user password datacenter server]
64
72
  end
65
73
  end
74
+
66
75
  HammerCLIForeman.register_compute_resource('vmware', VMware.new)
67
76
  end
68
- end
77
+ end
@@ -5,10 +5,8 @@ require 'hammer_cli_foreman/smart_class_parameter'
5
5
  require 'hammer_cli_foreman/smart_variable'
6
6
  require 'hammer_cli_foreman/interface'
7
7
  require 'hammer_cli_foreman/hosts/common_update_options'
8
- require 'hammer_cli_foreman/hosts/common_update_help'
9
8
  require 'hammer_cli_foreman/compute_resource/register_compute_resources'
10
- require 'hammer_cli_foreman/compute_resource/help_utils'
11
-
9
+ require 'hammer_cli_foreman/compute_resource/utils'
12
10
  require 'highline/import'
13
11
 
14
12
  module HammerCLIForeman
@@ -28,6 +26,9 @@ module HammerCLIForeman
28
26
  field :ip, _("IP")
29
27
  field :mac, _("MAC")
30
28
  field :global_status_label, _("Global Status")
29
+ field nil, _("Organization"), Fields::SingleReference, :key => :organization, :hide_blank => true, :sets => ['ALL']
30
+ field nil, _("Location"), Fields::SingleReference, :key => :location, :hide_blank => true, :sets => ['ALL']
31
+ field :comment, _("Additional Information"), nil, :sets => ['ALL']
31
32
  end
32
33
 
33
34
  build_options :without => [:include]
@@ -284,12 +285,11 @@ module HammerCLIForeman
284
285
  end
285
286
 
286
287
  class CreateCommand < HammerCLIForeman::CreateCommand
288
+ include HammerCLIForeman::Hosts::CommonUpdateOptions
289
+
287
290
  success_message _("Host created.")
288
291
  failure_message _("Could not create the host")
289
292
 
290
- include HammerCLIForeman::Hosts::CommonUpdateOptions
291
- include HammerCLIForeman::Hosts::CommonUpdateHelp
292
-
293
293
  def validate_options
294
294
  super
295
295
  unless validator.any(:option_hostgroup_id, :option_hostgroup_name, :option_hostgroup_title).exist?
@@ -303,16 +303,39 @@ module HammerCLIForeman
303
303
  end
304
304
 
305
305
  extend_with(HammerCLIForeman::CommandExtensions::PuppetEnvironment.new)
306
+ extend_with(HammerCLIForeman::CommandExtensions::Hosts::Help::Interfaces.new)
307
+ extend_with(HammerCLIForeman::CommandExtensions::Hosts::Help::ComputeResources.custom(add_host_specific_attrs: true).new)
306
308
  end
307
309
 
308
310
  class UpdateCommand < HammerCLIForeman::UpdateCommand
309
311
  success_message _("Host updated.")
310
312
  failure_message _("Could not update the host")
311
313
 
314
+ def self.create_option_builder
315
+ builder = super
316
+ %i[locations organizations].each do |resource_name|
317
+ builder.builders << UpdateDependentSearchablesOptionBuilder.new(
318
+ HammerCLIForeman.foreman_resource(resource_name), searchables
319
+ )
320
+ end
321
+ builder
322
+ end
323
+
312
324
  include HammerCLIForeman::Hosts::CommonUpdateOptions
313
- include HammerCLIForeman::Hosts::CommonUpdateHelp
325
+
326
+ def option_sources
327
+ sources = super
328
+ sources.find_by_name('IdResolution').insert_relative(
329
+ :after,
330
+ 'SelfParam',
331
+ HammerCLIForeman::OptionSources::NewParams.new(self)
332
+ )
333
+ sources
334
+ end
314
335
 
315
336
  extend_with(HammerCLIForeman::CommandExtensions::PuppetEnvironment.new)
337
+ extend_with(HammerCLIForeman::CommandExtensions::Hosts::Help::Interfaces.new)
338
+ extend_with(HammerCLIForeman::CommandExtensions::Hosts::Help::ComputeResources.custom(add_host_specific_attrs: true).new)
316
339
  end
317
340
 
318
341
 
@@ -52,7 +52,6 @@ module HammerCLIForeman
52
52
 
53
53
  def request_params
54
54
  params = super
55
-
56
55
  owner_id = get_resource_id(HammerCLIForeman.foreman_resource(:users), :required => false, :scoped => true)
57
56
  params['host']['owner_id'] ||= owner_id unless owner_id.nil?
58
57
 
@@ -78,11 +77,27 @@ module HammerCLIForeman
78
77
  if action == :update
79
78
  params['host']['compute_attributes']['volumes_attributes'] = nested_attributes(option_volume_list) unless option_volume_list.empty?
80
79
  params['host']['interfaces_attributes'] = interfaces_attributes unless option_interface_list.empty?
80
+ if options['option_new_location_id']
81
+ params['host']['location_id'] = options['option_new_location_id']
82
+ else
83
+ params['host'].delete('location_id')
84
+ end
85
+ if options['option_new_organization_id']
86
+ params['host']['organization_id'] = options['option_new_organization_id']
87
+ else
88
+ params['host'].delete('organization_id')
89
+ end
81
90
  else
82
91
  params['host']['compute_attributes']['volumes_attributes'] = nested_attributes(option_volume_list)
83
92
  params['host']['interfaces_attributes'] = interfaces_attributes
84
93
  end
85
94
 
95
+ if options["option_image_id"]
96
+ compute_resource_id = params['host']['compute_resource_id'] || ::HammerCLIForeman::ComputeResources.get_host_compute_resource_id(params['id'])
97
+ raise ArgumentError, "Missing argument for 'compute_resource'" if compute_resource_id.nil?
98
+ image_uuid = ::HammerCLIForeman::ComputeResources.get_image_uuid(compute_resource_id, options["option_image_id"])
99
+ params['host']['compute_attributes']['image_id'] = image_uuid
100
+ end
86
101
  params['host']['root_pass'] = option_root_password unless option_root_password.nil?
87
102
 
88
103
  if option_ask_root_password
@@ -31,6 +31,7 @@ module HammerCLIForeman
31
31
  field nil, _("Operating System"), Fields::SingleReference, :key => :operatingsystem
32
32
  field :username, _("Username")
33
33
  field :uuid, _("UUID")
34
+ field :user_data, _("User Data")
34
35
  end
35
36
 
36
37
  end
@@ -245,7 +245,53 @@ module HammerCLIForeman
245
245
 
246
246
  end
247
247
 
248
+ class UpdateDependentSearchablesOptionBuilder < DependentSearchablesOptionBuilder
249
+ protected
250
+
251
+ def dependent_options(resource, resource_name_map)
252
+ options = []
253
+ searchables = @searchables.for(resource)
254
+ resource_name = resource.singular_name
255
+ aliased_name = aliased(resource_name, resource_name_map)
248
256
 
257
+ unless searchables.empty?
258
+ first = searchables[0]
259
+ remaining = searchables[1..-1] || []
260
+
261
+ # First option is named by the resource
262
+ # Eg. --new-organization with accessor option_new_organization_name
263
+ options << option(
264
+ optionamize("--new-#{aliased_name}"),
265
+ "new_#{aliased_name}_#{first.name}".upcase,
266
+ first.description || ' ',
267
+ attribute_name: HammerCLI.option_accessor_name("new_#{resource_name}_#{first.name}"),
268
+ referenced_resource: resource.singular_name
269
+ )
270
+
271
+ # Other options are named by the resource plus the searchable name
272
+ # Eg. --new-organization-label with accessor option_new_organization_label
273
+ remaining.each do |s|
274
+ options << option(
275
+ optionamize("--new-#{aliased_name}-#{s.name}"),
276
+ "new_#{aliased_name}_#{s.name}".upcase,
277
+ s.description || ' ',
278
+ attribute_name: HammerCLI.option_accessor_name("new_#{resource_name}_#{s.name}"),
279
+ referenced_resource: resource.singular_name
280
+ )
281
+ end
282
+ end
283
+
284
+ options << option(
285
+ optionamize("--new-#{aliased_name}-id"),
286
+ "new_#{aliased_name}_id".upcase,
287
+ description('id', :show),
288
+ attribute_name: HammerCLI.option_accessor_name("new_#{resource_name}_id"),
289
+ format: HammerCLI::Options::Normalizers::Number.new,
290
+ referenced_resource: resource.singular_name
291
+ )
292
+ options
293
+ end
294
+ end
249
295
 
250
296
  class DependentSearchablesArrayOptionBuilder < DependentSearchablesOptionBuilder
251
297
 
@@ -2,4 +2,6 @@ require 'hammer_cli_foreman/option_sources/id_params'
2
2
  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
+ require 'hammer_cli_foreman/option_sources/fields_params'
5
6
  require 'hammer_cli_foreman/option_sources/puppet_environment_params'
7
+ require 'hammer_cli_foreman/option_sources/new_params'
@@ -0,0 +1,20 @@
1
+ module HammerCLIForeman
2
+ module OptionSources
3
+ class FieldsParams < HammerCLI::Options::Sources::Base
4
+ def initialize(command)
5
+ @command = command
6
+ end
7
+
8
+ def process(defined_options, result)
9
+ get_options(defined_options, result)
10
+ end
11
+
12
+ def get_options(_defined_options, result)
13
+ if @command.respond_to?(:option_fields) && @command.option_fields == ['THIN']
14
+ result[HammerCLI.option_accessor_name('thin')] = true
15
+ end
16
+ result
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,26 @@
1
+ module HammerCLIForeman
2
+ module OptionSources
3
+ class NewParams < HammerCLI::Options::Sources::Base
4
+ def initialize(command)
5
+ @command = command
6
+ end
7
+
8
+ def get_options(_defined_options, result)
9
+ resource_names = @command.class.option_builder.builders
10
+ .select { |b| b.class == HammerCLIForeman::UpdateDependentSearchablesOptionBuilder }
11
+ .collect(&:resource)
12
+ .collect(&:singular_name)
13
+ new_result = resource_names.each_with_object({}) do |name, results|
14
+ new_name = @command.send("option_new_#{name}_name") || @command.send("option_new_#{name}_title")
15
+ results["option_new_#{name}_id"] =
16
+ if new_name
17
+ @command.resolver.send("#{name}_id", 'option_name' => new_name)
18
+ else
19
+ @command.send("option_new_#{name}_id")
20
+ end
21
+ end
22
+ result.merge!(new_result)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -77,7 +77,7 @@ module HammerCLIForeman
77
77
  build_options
78
78
  end
79
79
 
80
- class ScheduleCommand < HammerCLIForeman::CreateCommand
80
+ class ScheduleCommand < HammerCLIForeman::Command
81
81
  command_name "schedule"
82
82
  action :schedule_report
83
83
 
@@ -93,6 +93,10 @@ module HammerCLIForeman
93
93
  params
94
94
  end
95
95
 
96
+ def transform_format(data)
97
+ data
98
+ end
99
+
96
100
  def execute
97
101
  data = send_request
98
102
  if option_wait?
@@ -119,7 +123,7 @@ module HammerCLIForeman
119
123
 
120
124
  def build_report_data_args(schedule_data)
121
125
  [
122
- '--id', option_id,
126
+ '--id', options['option_id'],
123
127
  '--job-id', schedule_data['job_id'],
124
128
  '--path', option_path
125
129
  ]