hammer_cli_foreman 0.17.2 → 0.18.0

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8cfafe507d907c2ab1aed91af69e697a96b3ebf53a986c95e08eb983d428d5c3
4
- data.tar.gz: 66077cbc504c823917ce78e519f5483d6bb3dc64ca879926105ce9074e36a740
3
+ metadata.gz: 918e60154e914780c804e9b033bec387c7fdb2390db19c46023cf65d9238896a
4
+ data.tar.gz: 57dda224b72156be5abab4ca2f23e6fdf0ee13145137cdd0384d198d5730eb4b
5
5
  SHA512:
6
- metadata.gz: 3cf5631ead2692b824488dfe9583fd6e08f39a10a51c52bef283ad073e8ce985566de787262704bee7811f84e1c57e8b44bfaddf1aa1247684c9db3c1b0fc16d
7
- data.tar.gz: 4e708bb0f305e0affc530a9418030952c8bbea70183ab50500f336d7c4f9f355eef7dde9e877a16c7f333c8dfb44b9c6fc664d9eab57c9a232beaedb11e65d0f
6
+ metadata.gz: a54d4883620ffc7f974368651d5b8dfdbfeb245489236d3c76f0d9f4d850fe1083d62f48101c0dbc4ac1b10df577de54f43a7237cbcbfc89203f2693a01eec29
7
+ data.tar.gz: c1bc962fe6550212ed81a50ca0c5f6e05efe6b134079929a203e82c6432aef9646ce8dcf637a530579dfd9760add6366da71caf37892fbff90b22810fb03db7a
data/doc/host_create.md CHANGED
@@ -16,7 +16,7 @@ Usage:
16
16
 
17
17
  Options:
18
18
  --architecture ARCHITECTURE_NAME Architecture name
19
- --architecture-id ARCHITECTURE_ID
19
+ --architecture-id ARCHITECTURE_ID
20
20
  --ask-root-password ASK_ROOT_PW One of true/false, yes/no, 1/0.
21
21
  --autoheal AUTOHEAL Sets whether the Host will autoheal subscriptions upon checkin
22
22
  One of true/false, yes/no, 1/0.
@@ -25,14 +25,14 @@ Options:
25
25
  --compute-attributes COMPUTE_ATTRS Compute resource attributes
26
26
  Comma-separated list of key=value
27
27
  --compute-profile COMPUTE_PROFILE_NAME Name to search by
28
- --compute-profile-id COMPUTE_PROFILE_ID
28
+ --compute-profile-id COMPUTE_PROFILE_ID
29
29
  --compute-resource COMPUTE_RESOURCE_NAME Compute resource name
30
- --compute-resource-id COMPUTE_RESOURCE_ID
30
+ --compute-resource-id COMPUTE_RESOURCE_ID
31
31
  --config-group-ids CONFIG_GROUP_IDS IDs of associated config groups
32
32
  Comma separated list of values. Values containing comma should be quoted or escaped with backslash
33
33
  --config-groups CONFIG_GROUP_NAMES Comma separated list of values. Values containing comma should be quoted or escaped with backslash
34
34
  --content-source CONTENT_SOURCE_NAME Content Source name
35
- --content-source-id CONTENT_SOURCE_ID
35
+ --content-source-id CONTENT_SOURCE_ID
36
36
  --content-view CONTENT_VIEW_NAME Name to search by
37
37
  --content-view-id CONTENT_VIEW_ID Content view numeric identifier
38
38
  --domain DOMAIN_NAME Domain name
@@ -40,12 +40,12 @@ Options:
40
40
  --enabled ENABLED Include this host within Foreman reporting
41
41
  One of true/false, yes/no, 1/0.
42
42
  --hostgroup HOSTGROUP_NAME Hostgroup name
43
- --hostgroup-id HOSTGROUP_ID
43
+ --hostgroup-id HOSTGROUP_ID
44
44
  --hostgroup-title HOSTGROUP_TITLE Hostgroup title
45
45
  --hypervisor-guest-uuids HYPERVISOR_GUEST_UUIDS List of hypervisor guest uuids
46
46
  Comma separated list of values. Values containing comma should be quoted or escaped with backslash
47
47
  --image IMAGE_NAME Name to search by
48
- --image-id IMAGE_ID
48
+ --image-id IMAGE_ID
49
49
  --installed-products-attributes INSTALLED_PRODUCTS_ATTRIBUTES List of products installed on the host
50
50
  Comma separated list of values. Values containing comma should be quoted or escaped with backslash
51
51
  --interface INTERFACE Interface parameters
@@ -57,7 +57,7 @@ Options:
57
57
  --lifecycle-environment LIFECYCLE_ENVIRONMENT_NAME Name to search by
58
58
  --lifecycle-environment-id LIFECYCLE_ENVIRONMENT_ID ID of the environment
59
59
  --location LOCATION_NAME Location name
60
- --location-id LOCATION_ID
60
+ --location-id LOCATION_ID
61
61
  --location-title LOCATION_TITLE Location title
62
62
  --mac MAC Required for managed host that is bare metal, not required if it's a
63
63
  Virtual machine
@@ -65,12 +65,12 @@ Options:
65
65
  Also determines whether several parameters are required or not
66
66
  One of true/false, yes/no, 1/0.
67
67
  --medium MEDIUM_NAME Medium name
68
- --medium-id MEDIUM_ID
68
+ --medium-id MEDIUM_ID
69
69
  --model MODEL_NAME Model name
70
- --model-id MODEL_ID
71
- --name NAME
70
+ --model-id MODEL_ID
71
+ --name NAME
72
72
  --operatingsystem OPERATINGSYSTEM_TITLE Operating system title
73
- --operatingsystem-id OPERATINGSYSTEM_ID
73
+ --operatingsystem-id OPERATINGSYSTEM_ID
74
74
  --organization ORGANIZATION_NAME Organization name
75
75
  --organization-id ORGANIZATION_ID Organization ID
76
76
  --organization-title ORGANIZATION_TITLE Organization title
@@ -83,20 +83,20 @@ Options:
83
83
  --parameters PARAMS Host parameters
84
84
  Comma-separated list of key=value
85
85
  --partition-table PARTITION_TABLE_NAME Partition table name
86
- --partition-table-id PARTITION_TABLE_ID
86
+ --partition-table-id PARTITION_TABLE_ID
87
87
  --product PRODUCT_NAME Name to search by
88
88
  --product-id PRODUCT_ID Product numeric identifier
89
89
  --progress-report-id PROGRESS_REPORT_ID UUID to track orchestration tasks status, GET
90
90
  /api/orchestration/:UUID/tasks
91
91
  --provision-method PROVISION_METHOD The method used to provision the host.
92
92
  Possible value(s): 'build', 'image'
93
- --puppet-ca-proxy PUPPET_CA_PROXY_NAME
93
+ --puppet-ca-proxy PUPPET_CA_PROXY_NAME
94
94
  --puppet-ca-proxy-id PUPPET_CA_PROXY_ID Puppet CA proxy ID
95
95
  --puppet-class-ids PUPPET_CLASS_IDS Comma separated list of values. Values containing comma should be quoted or escaped with backslash
96
96
  --puppet-classes PUPPET_CLASS_NAMES Comma separated list of values. Values containing comma should be quoted or escaped with backslash
97
97
  --puppet-environment PUPPET_ENVIRONMENT_NAME Puppet Environment name
98
- --puppet-environment-id PUPPET_ENVIRONMENT_ID
99
- --puppet-proxy PUPPET_PROXY_NAME
98
+ --puppet-environment-id PUPPET_ENVIRONMENT_ID
99
+ --puppet-proxy PUPPET_PROXY_NAME
100
100
  --puppet-proxy-id PUPPET_PROXY_ID Puppet proxy ID
101
101
  --pxe-loader PXE_LOADER DHCP filename option (Grub2/PXELinux by default)
102
102
  Possible value(s): 'None', 'PXELinux BIOS', 'PXELinux UEFI', 'Grub UEFI', 'Grub2 UEFI', 'Grub2 UEFI SecureBoot', 'Grub2 UEFI HTTP', 'Grub2 UEFI HTTPS', 'Grub2 UEFI HTTPS SecureBoot', 'iPXE Embedded', 'iPXE UEFI HTTP', 'iPXE Chain BIOS', 'iPXE Chain UEFI'
@@ -106,7 +106,7 @@ Options:
106
106
  --root-password ROOT_PW Required if host is managed and value is not inherited from host group or default password in settings
107
107
  --service-level SERVICE_LEVEL Service level to be used for autoheal
108
108
  --subnet SUBNET_NAME Subnet name
109
- --subnet-id SUBNET_ID
109
+ --subnet-id SUBNET_ID
110
110
  --volume VOLUME Volume parameters
111
111
  Comma-separated list of key=value
112
112
  Can be specified multiple times.
@@ -187,7 +187,7 @@ Available keys for `--compute-attributes`:
187
187
  machine_type # one of available flavors
188
188
  image_id
189
189
  network
190
- external_ip
190
+ associate_external_ip
191
191
  ```
192
192
 
193
193
  ## Libvirt
data/doc/release_notes.md CHANGED
@@ -1,13 +1,26 @@
1
1
  Release notes
2
2
  =============
3
- ### 0.17.2 (2019-08-13)
3
+ ### 0.18.0 (2019-08-01)
4
+ * Report template schedule works with --name ([#27339](http://projects.theforeman.org/issues/27339))
5
+ * Possibility to change host loc/org via hammer ([PR #416](https://github.com/theforeman/hammer-cli-foreman/pull/416)) ([#26536](http://projects.theforeman.org/issues/26536))
6
+ * Consider value not display name of compute_resource ([PR #432](https://github.com/theforeman/hammer-cli-foreman/pull/432)) ([#27343](http://projects.theforeman.org/issues/27343))
7
+ * Return missing helper methods for host ([#27444](http://projects.theforeman.org/issues/27444))
8
+ * Customize CR fields using provider_specific_fields ([#27342](http://projects.theforeman.org/issues/27342))
9
+ * Added volume attributes for GCE ([#27342](http://projects.theforeman.org/issues/27342))
10
+ * Add additional keys in GCE compute resource ([#27342](http://projects.theforeman.org/issues/27342))
11
+ * Adds project domain flags ([#26668](http://projects.theforeman.org/issues/26668))
12
+ * Remove duplicate options ([#27375](http://projects.theforeman.org/issues/27375))
13
+ * Full-help doesn't asks for credentials ([#26894](http://projects.theforeman.org/issues/26894))
4
14
  * Update environments options for puppet context ([#27323](http://projects.theforeman.org/issues/27323))
5
- * Consistent puppet environment naming in hammer ([#23204](http://projects.theforeman.org/issues/23204))
6
-
7
- ### 0.17.1 (2019-07-10)
8
- * Consistent puppet environment naming in hammer ([#23204](http://projects.theforeman.org/issues/23204))
15
+ * Report template schedule shows job ID ([#27341](http://projects.theforeman.org/issues/27341))
16
+ * Host creation with multi SCSI controllers ([#25093](http://projects.theforeman.org/issues/25093), [#26421](http://projects.theforeman.org/issues/26421))
17
+ * Add Location and Description Fields ([#21764](http://projects.theforeman.org/issues/21764))
9
18
  * Create hostgroup with puppet classes ([#24717](http://projects.theforeman.org/issues/24717))
10
- * Fix help on commands with no resource ([#26865](http://projects.theforeman.org/issues/26865))
19
+ * Consistent puppet environment naming in hammer ([#23204](http://projects.theforeman.org/issues/23204))
20
+ * Add abstraction for subcommand searching ([PR #342](https://github.com/theforeman/hammer-cli-foreman/pull/342)) ([#21674](http://projects.theforeman.org/issues/21674))
21
+ * Possibility to limit fields that are displayed ([PR #407](https://github.com/theforeman/hammer-cli-foreman/pull/407)) ([#19135](http://projects.theforeman.org/issues/19135))
22
+ * action for false:FalseClass ([#26865](http://projects.theforeman.org/issues/26865))
23
+ * Move image_id to the compute_attributes ([#6159](http://projects.theforeman.org/issues/6159))
11
24
 
12
25
  ### 0.17.0 (2019-04-24)
13
26
  * Add public key option in create compute resource CLI ([#25491](http://projects.theforeman.org/issues/25491))
@@ -1,6 +1,5 @@
1
+ require 'hammer_cli_foreman/command_extensions/fields'
1
2
  require 'hammer_cli_foreman/command_extensions/puppet_environment'
2
- require 'hammer_cli_foreman/command_extensions/puppet_environment'
3
- require 'hammer_cli_foreman/command_extensions/puppet_environments'
4
- require 'hammer_cli_foreman/command_extensions/option_sources'
5
3
  require 'hammer_cli_foreman/command_extensions/puppet_environments'
6
4
  require 'hammer_cli_foreman/command_extensions/option_sources'
5
+ require 'hammer_cli_foreman/command_extensions/hosts'
@@ -0,0 +1,13 @@
1
+ module HammerCLIForeman
2
+ module CommandExtensions
3
+ class Fields < HammerCLI::CommandExtensions
4
+ inheritable true
5
+
6
+ use_option :fields
7
+
8
+ option_sources do |sources, command|
9
+ sources << HammerCLIForeman::OptionSources::FieldsParams.new(command)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1 @@
1
+ require 'hammer_cli_foreman/command_extensions/hosts/help'
@@ -0,0 +1,2 @@
1
+ require 'hammer_cli_foreman/command_extensions/hosts/help/interfaces'
2
+ require 'hammer_cli_foreman/command_extensions/hosts/help/compute_resources'
@@ -0,0 +1,85 @@
1
+ module HammerCLIForeman
2
+ module CommandExtensions
3
+ module Hosts
4
+ module Help
5
+ class ComputeResources < HammerCLI::CommandExtensions
6
+ class << self
7
+ attr_writer :current_providers, :add_host_specific_attrs,
8
+ :attributes
9
+
10
+ def current_providers
11
+ @current_providers ||= HammerCLIForeman.compute_resources.keys
12
+ @current_providers
13
+ end
14
+
15
+ def add_host_specific_attrs?
16
+ @add_host_specific_attrs ||= false
17
+ @add_host_specific_attrs
18
+ end
19
+
20
+ def attributes
21
+ @attributes ||= :all
22
+ @attributes
23
+ end
24
+
25
+ def customized?
26
+ @customized
27
+ end
28
+
29
+ def customized=(boolean)
30
+ @customized ||= boolean
31
+ end
32
+
33
+ def custom(options = {})
34
+ new_self = Class.new(ComputeResources)
35
+ new_self.add_host_specific_attrs = options[:add_host_specific_attrs]
36
+ new_self.attributes = options[:attributes]
37
+ new_self.current_providers = options[:providers]
38
+ new_self.class_eval(&help_block)
39
+ new_self.customized = true
40
+ new_self
41
+ end
42
+
43
+ def help_block
44
+ @help_block ||= Proc.new do
45
+ help do |h|
46
+ h.section(_('Provider specific options')) do |h|
47
+ HammerCLIForeman.compute_resources.each do |name, provider|
48
+ next unless current_providers.include?(name)
49
+
50
+ h.section(provider.name, id: name.to_sym) do |h|
51
+ compute_attributes = provider.compute_attributes
52
+ compute_attributes += provider.host_attributes if add_host_specific_attrs?
53
+ if %i[all volume].include?(attributes)
54
+ h.section('--volume') do |h|
55
+ h.list(provider.volume_attributes)
56
+ end
57
+ end
58
+ if %i[all interface].include?(attributes)
59
+ h.section('--interface') do |h|
60
+ h.list(provider.interface_attributes)
61
+ end
62
+ end
63
+ if %i[all compute].include?(attributes)
64
+ h.section('--compute-attributes', id: :s_compute_attributes) do |h|
65
+ h.list(compute_attributes, id: :l_compute_attributes)
66
+ end
67
+ end
68
+ end
69
+ provider.extend_help(h) if provider.respond_to?(:extend_help)
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+
77
+ def initialize(options = {})
78
+ super
79
+ self.class.class_eval(&self.class.help_block) unless self.class.customized?
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,55 @@
1
+ module HammerCLIForeman
2
+ module CommandExtensions
3
+ module Hosts
4
+ module Help
5
+ class Interfaces < HammerCLI::CommandExtensions
6
+ help do |h|
7
+ h.section(_('Available keys for %{option}') % { :option => '--interface' }) do |h|
8
+ h.list(
9
+ [
10
+ 'mac',
11
+ 'ip',
12
+ ['type', _('Possible values: %s') % 'interface, bmc, bond, bridge'],
13
+ 'name',
14
+ 'subnet_id',
15
+ 'domain_id',
16
+ 'identifier',
17
+ ['managed', 'true/false'],
18
+ ['primary', _('%{value}, each managed hosts needs to have one primary interface.') % {:value => 'true/false'}],
19
+ ['provision', 'true/false'],
20
+ ['virtual', 'true/false']
21
+ ]
22
+ )
23
+ h.section(_('For %{condition}') % { :condition => 'virtual=true' }) do |h|
24
+ h.list(
25
+ [
26
+ ['tag', _('VLAN tag, this attribute has precedence over the subnet VLAN ID. Only for virtual interfaces.')],
27
+ ['attached_to', _('Identifier of the interface to which this interface belongs, e.g. eth1.')]
28
+ ]
29
+ )
30
+ end
31
+ h.section(_('For %{condition}') % { :condition => 'type=bond' }) do |h|
32
+ h.list(
33
+ [
34
+ ['mode', _('Possible values: %s') % 'balance-rr, active-backup, balance-xor, broadcast, 802.3ad, balance-tlb, balance-alb'],
35
+ ['attached_devices', _('Identifiers of slave interfaces, e.g. [eth1,eth2]')],
36
+ 'bond_options'
37
+ ]
38
+ )
39
+ end
40
+ h.section(_('For %{condition}') % { :condition => 'type=bmc' }) do |h|
41
+ h.list(
42
+ [
43
+ ['provider', _('always IPMI')],
44
+ 'username',
45
+ 'password'
46
+ ]
47
+ )
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -230,6 +230,15 @@ module HammerCLIForeman
230
230
  RETRIEVE_ALL_PER_PAGE = 1000
231
231
  DEFAULT_PER_PAGE = 20
232
232
 
233
+ def self.output(definition = nil, &block)
234
+ super
235
+ begin
236
+ output_definition.update_field_sets('THIN', (searchables.for(resource).map(&:name) + ['id']).map(&:to_sym))
237
+ rescue StandardError => e
238
+ # Some subcommands may not have such fields or defined resource
239
+ end
240
+ end
241
+
233
242
  def adapter
234
243
  @context[:adapter] || :table
235
244
  end
@@ -278,6 +287,8 @@ module HammerCLIForeman
278
287
  super
279
288
  end
280
289
 
290
+ extend_with(HammerCLIForeman::CommandExtensions::Fields.new)
291
+
281
292
  protected
282
293
 
283
294
  def retrieve_all
@@ -324,6 +335,96 @@ module HammerCLIForeman
324
335
  end
325
336
  end
326
337
 
338
+ class AssociatedListSearchCommand < ListCommand
339
+ def self.search_resource(res, action = :index)
340
+ resource res, action
341
+ default_search_options
342
+ end
343
+
344
+ def self.default_search_options
345
+ option("--id", "ID", _("%s Id") % module_resource.singular_name)
346
+ option("--name", "NAME", _("%s name") % module_resource.singular_name)
347
+ end
348
+
349
+ def self.search_options_mapping(mapping = {})
350
+ { "name" => module_resource.singular_name,
351
+ "id" => "#{module_resource.singular_name}_id"
352
+ }.merge mapping
353
+ end
354
+
355
+ def option_sources
356
+ sources = super
357
+ sources.find_by_name('IdResolution').insert_relative(
358
+ :replace,
359
+ 'SelfParam',
360
+ HammerCLI::Options::Sources::Base.new
361
+ )
362
+ sources
363
+ end
364
+
365
+ def validate_options
366
+ super
367
+ validator.any("option_name".to_sym, "option_id".to_sym).required
368
+ end
369
+
370
+ def parent_resource_name
371
+ self.class.module_resource.singular_name
372
+ end
373
+
374
+ def search_mapping(key)
375
+ self.class.search_options_mapping[key]
376
+ end
377
+
378
+ def parent_resource_name_attr
379
+ "name"
380
+ end
381
+
382
+ def parent_resource_id_attr
383
+ "id"
384
+ end
385
+
386
+ def name_attr(resource_name)
387
+ "#{resource_name}_name"
388
+ end
389
+
390
+ def id_attr(resource_name)
391
+ "#{resource_name}_id"
392
+ end
393
+
394
+ def request_params
395
+ params = super
396
+ search = []
397
+ search << params['search'] if params['search']
398
+
399
+ resource_name = get_option_value(parent_resource_name_attr)
400
+ search << %Q(#{search_mapping parent_resource_name_attr}="#{resource_name}") if resource_name
401
+
402
+ resource_id = get_option_value(parent_resource_id_attr)
403
+ search << "#{search_mapping parent_resource_id_attr}=#{resource_id}" if resource_id
404
+
405
+ search += taxonomy_request_params('organization', params)
406
+ search += taxonomy_request_params('location', params)
407
+
408
+ params['search'] = search.join(' and ') unless search.empty?
409
+ params
410
+ end
411
+
412
+ def taxonomy_request_params(taxonomy, params)
413
+ res = []
414
+ tax_name = get_option_value(name_attr taxonomy)
415
+ if tax_name
416
+ res << "#{name_attr taxonomy}=#{tax_name}"
417
+ params.delete(name_attr taxonomy)
418
+ end
419
+
420
+ tax_id = get_option_value(id_attr taxonomy)
421
+ if tax_id
422
+ res << "#{id_attr taxonomy}=#{tax_id}"
423
+ params.delete(id_attr taxonomy)
424
+ end
425
+ res
426
+ end
427
+ end
327
428
 
328
429
  class SingleResourceCommand < Command
329
430
 
@@ -364,6 +465,15 @@ module HammerCLIForeman
364
465
 
365
466
  action :show
366
467
 
468
+ def self.output(definition = nil, &block)
469
+ super
470
+ begin
471
+ output_definition.update_field_sets('THIN', (searchables.for(resource).map(&:name) + ['id']).map(&:to_sym))
472
+ rescue StandardError => e
473
+ # Some subcommands may not have such fields or defined resource
474
+ end
475
+ end
476
+
367
477
  def self.command_name(name=nil)
368
478
  super(name) || "info"
369
479
  end
@@ -381,6 +491,7 @@ module HammerCLIForeman
381
491
  print_record(output_definition, record)
382
492
  end
383
493
 
494
+ extend_with(HammerCLIForeman::CommandExtensions::Fields.new)
384
495
  end
385
496
 
386
497