hammer_cli_foreman 2.3.2 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/doc/release_notes.md +33 -3
  3. data/lib/hammer_cli_foreman.rb +3 -21
  4. data/lib/hammer_cli_foreman/associating_commands.rb +0 -24
  5. data/lib/hammer_cli_foreman/bookmark.rb +1 -1
  6. data/lib/hammer_cli_foreman/combination.rb +3 -13
  7. data/lib/hammer_cli_foreman/command_extensions.rb +1 -2
  8. data/lib/hammer_cli_foreman/command_extensions/ping.rb +21 -2
  9. data/lib/hammer_cli_foreman/command_extensions/status.rb +1 -1
  10. data/lib/hammer_cli_foreman/command_extensions/update_common.rb +14 -0
  11. data/lib/hammer_cli_foreman/commands.rb +16 -9
  12. data/lib/hammer_cli_foreman/compute_resource.rb +22 -0
  13. data/lib/hammer_cli_foreman/compute_resource/ovirt.rb +2 -1
  14. data/lib/hammer_cli_foreman/config_report.rb +2 -0
  15. data/lib/hammer_cli_foreman/filter.rb +2 -2
  16. data/lib/hammer_cli_foreman/host.rb +1 -47
  17. data/lib/hammer_cli_foreman/hostgroup.rb +2 -53
  18. data/lib/hammer_cli_foreman/hosts/common_update_options.rb +7 -28
  19. data/lib/hammer_cli_foreman/id_resolver.rb +0 -61
  20. data/lib/hammer_cli_foreman/location.rb +0 -6
  21. data/lib/hammer_cli_foreman/operating_system.rb +2 -1
  22. data/lib/hammer_cli_foreman/option_builders.rb +6 -5
  23. data/lib/hammer_cli_foreman/option_sources.rb +0 -1
  24. data/lib/hammer_cli_foreman/option_sources/id_params.rb +27 -10
  25. data/lib/hammer_cli_foreman/option_sources/ids_params.rb +25 -6
  26. data/lib/hammer_cli_foreman/organization.rb +0 -6
  27. data/lib/hammer_cli_foreman/ping.rb +6 -1
  28. data/lib/hammer_cli_foreman/references.rb +0 -16
  29. data/lib/hammer_cli_foreman/registration.rb +18 -0
  30. data/lib/hammer_cli_foreman/smart_proxy.rb +0 -52
  31. data/lib/hammer_cli_foreman/version.rb +1 -1
  32. data/lib/minitest/coverage_reporter.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/2.4/foreman_api.json +1 -0
  47. data/test/data/2.5/foreman_api.json +1 -0
  48. data/test/functional/architecture_test.rb +81 -0
  49. data/test/functional/bookmark_test.rb +24 -1
  50. data/test/functional/compute_profile_test.rb +56 -0
  51. data/test/functional/compute_resource_test.rb +37 -0
  52. data/test/functional/filter_test.rb +115 -47
  53. data/test/functional/host_test.rb +94 -13
  54. data/test/functional/hostgroup/create_test.rb +0 -117
  55. data/test/functional/hostgroup/update_test.rb +0 -79
  56. data/test/functional/http_proxy_test.rb +12 -0
  57. data/test/functional/location_test.rb +13 -3
  58. data/test/functional/mail_notification_test.rb +22 -0
  59. data/test/functional/media_test.rb +11 -0
  60. data/test/functional/model_test.rb +52 -0
  61. data/test/functional/operating_system_test.rb +53 -0
  62. data/test/functional/ping_test.rb +33 -0
  63. data/test/functional/realm_test.rb +11 -0
  64. data/test/functional/registration_test.rb +8 -0
  65. data/test/functional/report_template_test.rb +11 -0
  66. data/test/functional/settings_test.rb +21 -0
  67. data/test/functional/status_test.rb +79 -13
  68. data/test/functional/template_test.rb +16 -37
  69. data/test/functional/user_test.rb +11 -0
  70. data/test/functional/usergroup_test.rb +53 -0
  71. data/test/test_helper.rb +1 -1
  72. data/test/unit/apipie_resource_mock.rb +22 -39
  73. data/test/unit/architecture_test.rb +10 -1
  74. data/test/unit/bookmark_test.rb +95 -0
  75. data/test/unit/compute_profile_test.rb +87 -0
  76. data/test/unit/config_report_test.rb +1 -0
  77. data/test/unit/helpers/command.rb +0 -8
  78. data/test/unit/host_test.rb +14 -61
  79. data/test/unit/hostgroup_test.rb +7 -26
  80. data/test/unit/id_resolver_test.rb +0 -28
  81. data/test/unit/mail_notification_test.rb +53 -0
  82. data/test/unit/model_test.rb +47 -37
  83. data/test/unit/operating_system_test.rb +10 -3
  84. data/test/unit/option_sources/id_params_test.rb +9 -0
  85. data/test/unit/option_sources/ids_params_test.rb +9 -0
  86. data/test/unit/settings_test.rb +4 -0
  87. data/test/unit/smart_proxy_test.rb +0 -12
  88. data/test/unit/usergroup_test.rb +10 -0
  89. metadata +76 -73
  90. data/lib/hammer_cli_foreman/command_extensions/puppet_environment.rb +0 -29
  91. data/lib/hammer_cli_foreman/command_extensions/puppet_environments.rb +0 -29
  92. data/lib/hammer_cli_foreman/config_group.rb +0 -45
  93. data/lib/hammer_cli_foreman/option_sources/puppet_environment_params.rb +0 -59
  94. data/lib/hammer_cli_foreman/puppet_class.rb +0 -61
  95. data/lib/hammer_cli_foreman/puppet_environment.rb +0 -65
  96. data/lib/hammer_cli_foreman/smart_class_parameter.rb +0 -189
  97. data/test/functional/proxy_test.rb +0 -86
  98. data/test/functional/smart_class_parameter_test.rb +0 -97
  99. data/test/unit/config_group_test.rb +0 -72
  100. data/test/unit/puppet_class_test.rb +0 -72
  101. data/test/unit/puppet_environment_test.rb +0 -114
  102. data/test/unit/smart_class_parameter_test.rb +0 -113
@@ -1,29 +0,0 @@
1
- module HammerCLIForeman
2
- module CommandExtensions
3
- class PuppetEnvironment < HammerCLI::CommandExtensions
4
- # Remove when support of --environment options is ended.
5
- option_family(
6
- aliased_resource: 'environment',
7
- description: _('Puppet environment'),
8
- deprecation: _("Use %s instead") % '--puppet-environment[-id]',
9
- deprecated: { '--environment' => _("Use %s instead") % '--puppet-environment[-id]',
10
- '--environment-id' => _("Use %s instead") % '--puppet-environment[-id]'}
11
- ) do
12
- parent '--environment-id', 'ENVIRONMENT_ID', _(''),
13
- format: HammerCLI::Options::Normalizers::Number.new,
14
- attribute_name: :option_environment_id
15
- child '--environment', 'ENVIRONMENT_NAME', _('Environment name'),
16
- attribute_name: :option_environment_name
17
- end
18
-
19
- option_sources do |sources, command|
20
- sources.find_by_name('IdResolution').insert_relative(
21
- :after,
22
- 'IdParams',
23
- HammerCLIForeman::OptionSources::PuppetEnvironmentParams.new(command)
24
- )
25
- sources
26
- end
27
- end
28
- end
29
- end
@@ -1,29 +0,0 @@
1
- module HammerCLIForeman
2
- module CommandExtensions
3
- class PuppetEnvironments < HammerCLI::CommandExtensions
4
- # Remove when support of --environments options is ended.
5
- option_family(
6
- aliased_resource: 'environment',
7
- description: _('Puppet environments'),
8
- deprecation: _("Use %s instead") % '--puppet-environment[s|-ids]',
9
- deprecated: { '--environments' => _("Use %s instead") % '--puppet-environment[s|-ids]',
10
- '--environment-ids' => _("Use %s instead") % '--puppet-environment[s|-ids]' }
11
- ) do
12
- parent '--environment-ids', 'ENVIRONMENT_IDS', _('Environment IDs'),
13
- format: HammerCLI::Options::Normalizers::List.new,
14
- attribute_name: :option_environment_ids
15
- child '--environments', 'ENVIRONMENT_NAMES', _(''),
16
- attribute_name: :option_environment_names
17
- end
18
-
19
- option_sources do |sources, command|
20
- sources.find_by_name('IdResolution').insert_relative(
21
- :after,
22
- 'IdsParams',
23
- HammerCLIForeman::OptionSources::PuppetEnvironmentParams.new(command)
24
- )
25
- sources
26
- end
27
- end
28
- end
29
- end
@@ -1,45 +0,0 @@
1
- module HammerCLIForeman
2
- class ConfigGroup < HammerCLIForeman::Command
3
- resource :config_groups
4
-
5
- class ListCommand < HammerCLIForeman::ListCommand
6
- output do
7
- field :id, _("ID")
8
- field :name, _("Name")
9
- end
10
-
11
- build_options
12
- end
13
-
14
- class InfoCommand < HammerCLIForeman::InfoCommand
15
- output ListCommand.output_definition do
16
- HammerCLIForeman::References.puppetclasses(self)
17
- end
18
-
19
- build_options
20
- end
21
-
22
- class CreateCommand < HammerCLIForeman::CreateCommand
23
- success_message _("Config group created.")
24
- failure_message _("Could not create the config group")
25
-
26
- build_options
27
- end
28
-
29
- class UpdateCommand < HammerCLIForeman::UpdateCommand
30
- success_message _("Config group updated.")
31
- failure_message _("Could not update the config group")
32
-
33
- build_options
34
- end
35
-
36
- class DeleteCommand < HammerCLIForeman::DeleteCommand
37
- success_message _("Config group has been deleted.")
38
- failure_message _("Could not delete the config group")
39
-
40
- build_options
41
- end
42
-
43
- autoload_subcommands
44
- end
45
- end
@@ -1,59 +0,0 @@
1
- module HammerCLIForeman
2
- module OptionSources
3
- class PuppetEnvironmentParams < HammerCLI::Options::Sources::Base
4
- def initialize(command)
5
- @command = command
6
- end
7
-
8
- def get_options(_defined_options, result)
9
- if result['option_environment_id'].nil? &&
10
- (@command.respond_to?(:option_environment_id) ||
11
- @command.respond_to?(:option_environment_name))
12
- put_puppet_environment_id(result)
13
- end
14
- if result['option_environment_ids'].nil? &&
15
- (@command.respond_to?(:option_environment_ids) ||
16
- @command.respond_to?(:option_environment_names))
17
- put_puppet_environment_ids(result)
18
- end
19
- result
20
- end
21
-
22
- private
23
-
24
- def put_puppet_environment_id(result)
25
- if result['option_environment_name'].nil?
26
- if @command.option_environment_id
27
- result['option_environment_id'] = @command.option_environment_id
28
- elsif @command.option_environment_name
29
- result['option_environment_name'] = @command.option_environment_name
30
- result['option_environment_id'] = @command.resolver.puppet_environment_id(
31
- @command.resolver.scoped_options('environment', result, :single)
32
- )
33
- end
34
- else
35
- result['option_environment_id'] = @command.resolver.puppet_environment_id(
36
- @command.resolver.scoped_options('environment', result, :single)
37
- )
38
- end
39
- end
40
-
41
- def put_puppet_environment_ids(result)
42
- if result['option_environment_names'].nil?
43
- if @command.option_environment_ids
44
- result['option_environment_ids'] = @command.option_environment_ids
45
- elsif @command.option_environment_names
46
- result['option_environment_names'] = @command.option_environment_names
47
- result['option_environment_ids'] = @command.resolver.puppet_environment_ids(
48
- @command.resolver.scoped_options('environment', result, :multi)
49
- )
50
- end
51
- else
52
- result['option_environment_ids'] = @command.resolver.puppet_environment_ids(
53
- @command.resolver.scoped_options('environment', result, :multi)
54
- )
55
- end
56
- end
57
- end
58
- end
59
- end
@@ -1,61 +0,0 @@
1
- require 'hammer_cli_foreman/smart_class_parameter'
2
-
3
- module HammerCLIForeman
4
-
5
- class PuppetClass < HammerCLIForeman::Command
6
-
7
- resource :puppetclasses
8
-
9
- class ListCommand < HammerCLIForeman::ListCommand
10
-
11
- output do
12
- field :id, _("Id")
13
- field :name, _("Name")
14
- end
15
-
16
- def send_request
17
- self.class.unhash_classes(super)
18
- end
19
-
20
- def self.unhash_classes(classes)
21
- clss = classes.first.inject([]) { |list, (pp_module, pp_module_classes)| list + pp_module_classes }
22
-
23
- HammerCLI::Output::RecordCollection.new(clss, :meta => classes.meta)
24
-
25
- end
26
-
27
- build_options
28
-
29
- extend_with(HammerCLIForeman::CommandExtensions::PuppetEnvironment.new)
30
- end
31
-
32
-
33
- class InfoCommand < HammerCLIForeman::InfoCommand
34
- output ListCommand.output_definition do
35
- collection :smart_class_parameters, _("Smart class parameters"), :numbered => false do
36
- custom_field Fields::Reference, :name_key => :parameter
37
- end
38
- HammerCLIForeman::References.hostgroups(self)
39
- HammerCLIForeman::References.environments(self)
40
- HammerCLIForeman::References.parameters(self)
41
- end
42
-
43
- build_options
44
-
45
- extend_with(HammerCLIForeman::CommandExtensions::PuppetEnvironment.new)
46
- end
47
-
48
-
49
- class SCParamsCommand < HammerCLIForeman::SmartClassParametersBriefList
50
- build_options_for :puppetclasses
51
-
52
- def validate_options
53
- super
54
- validator.any(:option_puppetclass_name, :option_puppetclass_id).required
55
- end
56
- end
57
-
58
- autoload_subcommands
59
- end
60
-
61
- end
@@ -1,65 +0,0 @@
1
- require 'hammer_cli'
2
- require 'hammer_cli_foreman/smart_class_parameter'
3
-
4
- module HammerCLIForeman
5
-
6
- class PuppetEnvironment < HammerCLIForeman::Command
7
-
8
- resource :environments
9
-
10
- class ListCommand < HammerCLIForeman::ListCommand
11
-
12
- output do
13
- field :id, _("Id")
14
- field :name, _("Name")
15
- end
16
-
17
- build_options
18
- end
19
-
20
-
21
- class InfoCommand < HammerCLIForeman::InfoCommand
22
- output ListCommand.output_definition do
23
- HammerCLIForeman::References.puppetclasses(self)
24
- HammerCLIForeman::References.taxonomies(self)
25
- HammerCLIForeman::References.timestamps(self)
26
- end
27
-
28
- build_options
29
- end
30
-
31
-
32
- class CreateCommand < HammerCLIForeman::CreateCommand
33
- success_message _("Environment created.")
34
- failure_message _("Could not create the environment")
35
-
36
- build_options
37
- end
38
-
39
-
40
- class UpdateCommand < HammerCLIForeman::UpdateCommand
41
- success_message _("Environment updated.")
42
- failure_message _("Could not update the environment")
43
-
44
- build_options
45
- end
46
-
47
-
48
- class DeleteCommand < HammerCLIForeman::DeleteCommand
49
- success_message _("Environment deleted.")
50
- failure_message _("Could not delete the environment")
51
-
52
- build_options
53
- end
54
-
55
- class SCParamsCommand < HammerCLIForeman::SmartClassParametersList
56
- build_options_for :environments
57
-
58
- extend_with(HammerCLIForeman::CommandExtensions::PuppetEnvironment.new)
59
- end
60
-
61
-
62
- autoload_subcommands
63
- end
64
-
65
- end
@@ -1,189 +0,0 @@
1
- module HammerCLIForeman
2
-
3
- class SmartClassParametersBriefList < HammerCLIForeman::ListCommand
4
- resource :smart_class_parameters, :index
5
- command_name 'sc-params'
6
-
7
- output do
8
- field :id, _("Id")
9
-
10
- field :parameter, _("Parameter")
11
- field :default_value, _("Default Value")
12
- field :override, _("Override")
13
- end
14
-
15
- def send_request
16
- res = super
17
- # FIXME: API returns doubled records, probably just if filtered by puppetclasses
18
- # it seems group by environment is missing
19
- # having the uniq to fix that
20
- HammerCLI::Output::RecordCollection.new(res.uniq, :meta => res.meta)
21
- end
22
-
23
- def self.build_options_for(resource)
24
- options = {}
25
- options[:without] = [:host_id, :puppetclass_id, :environment_id, :hostgroup_id]
26
- options[:expand] = {}
27
- options[:expand][:except] = ([:hosts, :puppetclasses, :environments, :hostgroups] - [resource])
28
- build_options(options)
29
- end
30
- end
31
-
32
- class SmartClassParametersList < SmartClassParametersBriefList
33
-
34
- output do
35
- field :puppetclass_name, _("Puppet class")
36
- field :puppetclass_id, _("Class Id"), Fields::Id
37
- end
38
- end
39
-
40
- class SmartClassParameter < HammerCLIForeman::Command
41
-
42
- resource :smart_class_parameters
43
-
44
- class ListCommand < HammerCLIForeman::ListCommand
45
-
46
- output SmartClassParametersList.output_definition
47
-
48
- def extend_data(res)
49
- res['parameter_type'] ||= 'string'
50
- res
51
- end
52
-
53
- build_options
54
-
55
- extend_with(HammerCLIForeman::CommandExtensions::PuppetEnvironment.new)
56
- end
57
-
58
- class InfoCommand < HammerCLIForeman::InfoCommand
59
-
60
- output ListCommand.output_definition do
61
- field :description, _("Description")
62
- field :parameter_type, _("Type")
63
- field :hidden_value?, _("Hidden Value?")
64
- field :omit, _("Omit"), Fields::Boolean
65
- field :required, _("Required")
66
-
67
- label _("Validator") do
68
- field :validator_type, _("Type")
69
- field :validator_rule, _("Rule")
70
- end
71
- label _("Override values") do
72
- field :merge_overrides, _("Merge overrides"), Fields::Boolean
73
- field :merge_default, _("Merge default value"), Fields::Boolean
74
- field :avoid_duplicates, _("Avoid duplicates"), Fields::Boolean
75
- field :override_value_order, _("Order"), Fields::LongText
76
-
77
- collection :override_values, _("Values") do
78
- field :id, _('Id')
79
- field :match, _('Match')
80
- field :value, _('Value')
81
- field :omit, _('Omit'), Fields::Boolean
82
- end
83
- end
84
- HammerCLIForeman::References.environments(self)
85
- HammerCLIForeman::References.timestamps(self)
86
- end
87
-
88
- def extend_data(res)
89
- res['parameter_type'] ||= 'string'
90
- res['omit'] ||= false
91
- res
92
- end
93
-
94
- build_options do |options|
95
- options.expand.including(:puppetclasses)
96
- end
97
-
98
- validate_options do
99
- if option(:option_name).exist?
100
- any(:option_puppetclass_name, :option_puppetclass_id).required
101
- end
102
- end
103
- end
104
-
105
- class UpdateCommand < HammerCLIForeman::UpdateCommand
106
-
107
- success_message _("Parameter updated.")
108
- failure_message _("Could not update the parameter")
109
-
110
- option '--default-value', 'VALUE', _('Value to use when there is no match')
111
-
112
- build_options do |options|
113
- options.expand.including(:puppetclasses)
114
- options.without(:parameter_type, :validator_type, :override, :required, :override_value_order)
115
- end
116
-
117
- option "--override", "OVERRIDE", _("Override this parameter"),
118
- :format => HammerCLI::Options::Normalizers::Bool.new
119
- option "--required", "REQUIRED", _("This parameter is required"),
120
- :format => HammerCLI::Options::Normalizers::Bool.new
121
- option "--parameter-type", "PARAMETER_TYPE", _("Type of the parameter"),
122
- :format => HammerCLI::Options::Normalizers::Enum.new(
123
- ['string', 'boolean', 'integer', 'real', 'array', 'hash', 'yaml', 'json'])
124
- option "--validator-type", "VALIDATOR_TYPE", _("Type of the validator"),
125
- :format => HammerCLI::Options::Normalizers::Enum.new(['regexp', 'list', ''])
126
- option "--override-value-order", "OVERRIDE_VALUE_ORDER", _("The order in which values are resolved"),
127
- :format => HammerCLI::Options::Normalizers::List.new
128
-
129
- validate_options do
130
- if option(:option_name).exist?
131
- any(:option_puppetclass_name, :option_puppetclass_id).required
132
- end
133
- end
134
-
135
- def request_params
136
- params = super
137
- override_order = params['smart_class_parameter']['override_value_order']
138
- params['smart_class_parameter']['override_value_order'] = override_order.join("\n") if override_order.is_a?(Array)
139
- params
140
- end
141
- end
142
-
143
- class AddMatcherCommand < HammerCLIForeman::CreateCommand
144
- resource :override_values
145
- command_name 'add-matcher'
146
-
147
- option '--value', 'VALUE', _('Override value, required if omit is false')
148
-
149
- success_message _("Override value created.")
150
- failure_message _("Could not create the override value")
151
-
152
- build_options do |options|
153
- options.expand.including(:puppetclasses)
154
- end
155
-
156
- validate_options do
157
- if option(:option_omit).value
158
- option(:option_value).rejected(:msg => _('Cannot use --value when --omit is true.'))
159
- end
160
-
161
- if option(:option_smart_class_parameter_name).exist?
162
- any(:option_puppetclass_name, :option_puppetclass_id).required
163
- end
164
- end
165
- end
166
-
167
- class RemoveMatcherCommand < HammerCLIForeman::DeleteCommand
168
- resource :override_values
169
- command_name 'remove-matcher'
170
-
171
- success_message _("Override value deleted.")
172
- failure_message _("Could not delete the override value")
173
-
174
- build_options do |options|
175
- options.expand.including(:puppetclasses)
176
- end
177
-
178
- validate_options do
179
- if option(:option_smart_class_parameter_name).exist?
180
- any(:option_puppetclass_name, :option_puppetclass_id).required
181
- end
182
- end
183
- end
184
-
185
- autoload_subcommands
186
-
187
- end
188
-
189
- end