hammer_cli_foreman 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of hammer_cli_foreman might be problematic. Click here for more details.

Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -1
  3. data/doc/configuration.md +13 -0
  4. data/lib/hammer_cli_foreman.rb +3 -0
  5. data/lib/hammer_cli_foreman/architecture.rb +9 -9
  6. data/lib/hammer_cli_foreman/associating_commands.rb +57 -34
  7. data/lib/hammer_cli_foreman/commands.rb +188 -101
  8. data/lib/hammer_cli_foreman/common_parameter.rb +7 -10
  9. data/lib/hammer_cli_foreman/compute_resource.rb +8 -11
  10. data/lib/hammer_cli_foreman/domain.rb +14 -40
  11. data/lib/hammer_cli_foreman/environment.rb +10 -15
  12. data/lib/hammer_cli_foreman/exceptions.rb +4 -0
  13. data/lib/hammer_cli_foreman/fact.rb +5 -5
  14. data/lib/hammer_cli_foreman/host.rb +76 -132
  15. data/lib/hammer_cli_foreman/hostgroup.rb +26 -61
  16. data/lib/hammer_cli_foreman/id_resolver.rb +163 -0
  17. data/lib/hammer_cli_foreman/image.rb +14 -50
  18. data/lib/hammer_cli_foreman/location.rb +35 -17
  19. data/lib/hammer_cli_foreman/media.rb +9 -16
  20. data/lib/hammer_cli_foreman/model.rb +6 -8
  21. data/lib/hammer_cli_foreman/operating_system.rb +129 -63
  22. data/lib/hammer_cli_foreman/organization.rb +36 -16
  23. data/lib/hammer_cli_foreman/output/fields.rb +10 -2
  24. data/lib/hammer_cli_foreman/output/formatters.rb +44 -18
  25. data/lib/hammer_cli_foreman/parameter.rb +45 -41
  26. data/lib/hammer_cli_foreman/partition_table.rb +9 -12
  27. data/lib/hammer_cli_foreman/puppet_class.rb +14 -14
  28. data/lib/hammer_cli_foreman/references.rb +122 -0
  29. data/lib/hammer_cli_foreman/report.rb +3 -6
  30. data/lib/hammer_cli_foreman/searchables_option_builder.rb +99 -0
  31. data/lib/hammer_cli_foreman/smart_class_parameter.rb +17 -13
  32. data/lib/hammer_cli_foreman/smart_proxy.rb +18 -28
  33. data/lib/hammer_cli_foreman/subnet.rb +12 -13
  34. data/lib/hammer_cli_foreman/template.rb +10 -19
  35. data/lib/hammer_cli_foreman/user.rb +9 -28
  36. data/lib/hammer_cli_foreman/version.rb +1 -1
  37. data/locale/hammer-cli-foreman.pot +828 -817
  38. data/test/unit/apipie_resource_mock.rb +33 -11
  39. data/test/unit/architecture_test.rb +7 -10
  40. data/test/unit/commands_test.rb +8 -9
  41. data/test/unit/common_parameter_test.rb +6 -8
  42. data/test/unit/compute_resource_test.rb +9 -12
  43. data/test/unit/data/1.5/foreman_api.json +14130 -0
  44. data/test/unit/domain_test.rb +19 -22
  45. data/test/unit/environment_test.rb +9 -11
  46. data/test/unit/fact_test.rb +5 -6
  47. data/test/unit/helpers/command.rb +115 -59
  48. data/test/unit/helpers/fake_searchables.rb +19 -0
  49. data/test/unit/host_test.rb +44 -33
  50. data/test/unit/hostgroup_test.rb +19 -26
  51. data/test/unit/id_resolver_test.rb +225 -0
  52. data/test/unit/image_test.rb +16 -18
  53. data/test/unit/location_test.rb +8 -10
  54. data/test/unit/media_test.rb +11 -13
  55. data/test/unit/model_test.rb +8 -10
  56. data/test/unit/operating_system_test.rb +23 -23
  57. data/test/unit/organization_test.rb +9 -10
  58. data/test/unit/output/formatters_test.rb +133 -20
  59. data/test/unit/partition_table_test.rb +12 -9
  60. data/test/unit/puppet_class_test.rb +3 -7
  61. data/test/unit/report_test.rb +3 -7
  62. data/test/unit/searchables_option_builder_test.rb +172 -0
  63. data/test/unit/smart_class_parameter_test.rb +5 -7
  64. data/test/unit/smart_proxy_test.rb +11 -12
  65. data/test/unit/subnet_test.rb +15 -16
  66. data/test/unit/template_test.rb +15 -12
  67. data/test/unit/test_helper.rb +1 -1
  68. data/test/unit/user_test.rb +9 -12
  69. metadata +536 -509
@@ -14,19 +14,33 @@ module HammerCLIForeman
14
14
  field :name, _("Name")
15
15
  end
16
16
 
17
- apipie_options
17
+ build_options
18
18
  end
19
19
 
20
20
 
21
21
  class InfoCommand < HammerCLIForeman::InfoCommand
22
22
  include HammerCLIForeman::ResourceSupportedTest
23
23
 
24
+ option '--id', 'ID', _("Location numeric id to search by")
25
+
24
26
  output ListCommand.output_definition do
25
- field :created_at, _("Created at"), Fields::Date
26
- field :updated_at, _("Updated at"), Fields::Date
27
+ HammerCLIForeman::References.users(self)
28
+ HammerCLIForeman::References.smart_proxies(self)
29
+ HammerCLIForeman::References.subnets(self)
30
+ HammerCLIForeman::References.compute_resources(self)
31
+ HammerCLIForeman::References.media(self)
32
+ HammerCLIForeman::References.config_templates(self)
33
+ HammerCLIForeman::References.domains(self)
34
+ HammerCLIForeman::References.environments(self)
35
+ HammerCLIForeman::References.hostgroups(self)
36
+ HammerCLIForeman::References.parameters(self)
37
+ collection :organizations, _("Organizations"), :numbered => false, :hide_blank => true do
38
+ custom_field Fields::Reference
39
+ end
40
+ HammerCLIForeman::References.timestamps(self)
27
41
  end
28
42
 
29
- apipie_options
43
+ build_options
30
44
  end
31
45
 
32
46
 
@@ -36,39 +50,43 @@ module HammerCLIForeman
36
50
  success_message _("Location created")
37
51
  failure_message _("Could not create the location")
38
52
 
39
- apipie_options
53
+ build_options
40
54
  end
41
55
 
42
56
 
43
57
  class UpdateCommand < HammerCLIForeman::UpdateCommand
44
58
  include HammerCLIForeman::ResourceSupportedTest
45
59
 
60
+ option '--id', 'ID', _("Location numeric id to search by")
61
+
46
62
  success_message _("Location updated")
47
63
  failure_message _("Could not update the location")
48
64
 
49
- apipie_options
65
+ build_options
50
66
  end
51
67
 
52
68
 
53
69
  class DeleteCommand < HammerCLIForeman::DeleteCommand
54
70
  include HammerCLIForeman::ResourceSupportedTest
55
71
 
72
+ option '--id', 'ID', _("Location numeric id to search by")
73
+
56
74
  success_message _("Location deleted")
57
75
  failure_message _("Could not delete the location")
58
76
 
59
- apipie_options
77
+ build_options
60
78
  end
61
79
 
62
- include HammerCLIForeman::AssociatingCommands::Hostgroup
63
- include HammerCLIForeman::AssociatingCommands::Environment
64
- include HammerCLIForeman::AssociatingCommands::Domain
65
- include HammerCLIForeman::AssociatingCommands::Medium
66
- include HammerCLIForeman::AssociatingCommands::Subnet
67
- include HammerCLIForeman::AssociatingCommands::ComputeResource
68
- include HammerCLIForeman::AssociatingCommands::SmartProxy
69
- include HammerCLIForeman::AssociatingCommands::User
70
- include HammerCLIForeman::AssociatingCommands::ConfigTemplate
71
- include HammerCLIForeman::AssociatingCommands::Organization
80
+ HammerCLIForeman::AssociatingCommands::Hostgroup.extend_command(self)
81
+ HammerCLIForeman::AssociatingCommands::Environment.extend_command(self)
82
+ HammerCLIForeman::AssociatingCommands::Domain.extend_command(self)
83
+ HammerCLIForeman::AssociatingCommands::Medium.extend_command(self)
84
+ HammerCLIForeman::AssociatingCommands::Subnet.extend_command(self)
85
+ HammerCLIForeman::AssociatingCommands::ComputeResource.extend_command(self)
86
+ HammerCLIForeman::AssociatingCommands::SmartProxy.extend_command(self)
87
+ HammerCLIForeman::AssociatingCommands::User.extend_command(self)
88
+ HammerCLIForeman::AssociatingCommands::ConfigTemplate.extend_command(self)
89
+ HammerCLIForeman::AssociatingCommands::Organization.extend_command(self)
72
90
 
73
91
  autoload_subcommands
74
92
  end
@@ -11,24 +11,19 @@ module HammerCLIForeman
11
11
  field :path, _("Path")
12
12
  end
13
13
 
14
- apipie_options
14
+ build_options
15
15
  end
16
16
 
17
17
 
18
18
  class InfoCommand < HammerCLIForeman::InfoCommand
19
19
  output ListCommand.output_definition do
20
20
  field :os_family, _("OS Family")
21
- field :operatingsystem_ids, _("OS IDs"), Fields::List
22
- field :created_at, _("Created at"), Fields::Date
23
- field :updated_at, _("Updated at"), Fields::Date
21
+ HammerCLIForeman::References.operating_systems(self)
22
+ HammerCLIForeman::References.taxonomies(self)
23
+ HammerCLIForeman::References.timestamps(self)
24
24
  end
25
25
 
26
- def extend_data(res)
27
- res['operatingsystem_ids'] = res['operatingsystems'].map { |e| e["id"] } rescue []
28
- res
29
- end
30
-
31
- apipie_options
26
+ build_options
32
27
  end
33
28
 
34
29
 
@@ -37,31 +32,29 @@ module HammerCLIForeman
37
32
  success_message _("Installation medium created")
38
33
  failure_message _("Could not create the installation medium")
39
34
 
40
- apipie_options
35
+ build_options
41
36
 
42
37
  end
43
38
 
44
39
 
45
40
  class UpdateCommand < HammerCLIForeman::UpdateCommand
46
-
47
41
  success_message _("Installation medium updated")
48
42
  failure_message _("Could not update the installation media")
49
43
 
50
- apipie_options
44
+ build_options
51
45
 
52
46
  end
53
47
 
54
48
 
55
49
  class DeleteCommand < HammerCLIForeman::DeleteCommand
56
-
57
50
  success_message _("Installation medium deleted")
58
51
  failure_message _("Could not delete the installation media")
59
52
 
60
- apipie_options
53
+ build_options
61
54
  end
62
55
 
63
56
 
64
- include HammerCLIForeman::AssociatingCommands::OperatingSystem
57
+ HammerCLIForeman::AssociatingCommands::OperatingSystem.extend_command(self)
65
58
 
66
59
  autoload_subcommands
67
60
  end
@@ -13,19 +13,17 @@ module HammerCLIForeman
13
13
  field :hardware_model, _("HW model")
14
14
  end
15
15
 
16
- apipie_options
16
+ build_options
17
17
  end
18
18
 
19
19
 
20
20
  class InfoCommand < HammerCLIForeman::InfoCommand
21
-
22
21
  output ListCommand.output_definition do
23
22
  field :info, _("Info")
24
- field :created_at, _("Created at"), Fields::Date
25
- field :updated_at, _("Updated at"), Fields::Date
23
+ HammerCLIForeman::References.timestamps(self)
26
24
  end
27
25
 
28
- apipie_options
26
+ build_options
29
27
  end
30
28
 
31
29
 
@@ -33,14 +31,14 @@ module HammerCLIForeman
33
31
  success_message _("Hardware model created")
34
32
  failure_message _("Could not create the hardware model")
35
33
 
36
- apipie_options
34
+ build_options
37
35
  end
38
36
 
39
37
  class DeleteCommand < HammerCLIForeman::DeleteCommand
40
38
  success_message _("Hardware model deleted")
41
39
  failure_message _("Could not delete the hardware model")
42
40
 
43
- apipie_options
41
+ build_options
44
42
  end
45
43
 
46
44
 
@@ -48,7 +46,7 @@ module HammerCLIForeman
48
46
  success_message _("Hardware model updated")
49
47
  failure_message _("Could not update the hardware model")
50
48
 
51
- apipie_options
49
+ build_options
52
50
  end
53
51
 
54
52
 
@@ -8,52 +8,41 @@ module HammerCLIForeman
8
8
 
9
9
  output do
10
10
  field :id, _("Id")
11
- field :_os_name, _("Name"), Fields::OSName
11
+ field :fullname, _("Full name")
12
12
  field :release_name, _("Release name")
13
13
  field :family, _("Family")
14
14
  end
15
15
 
16
- def extend_data(os)
17
- os["_os_name"] = Hash[os.select { |k, v| ["name", "major", "minor"].include? k }]
18
- os
19
- end
20
-
21
- apipie_options
16
+ build_options
22
17
  end
23
18
 
24
19
 
25
20
  class InfoCommand < HammerCLIForeman::InfoCommand
26
-
27
- identifiers :id
28
-
29
21
  output ListCommand.output_definition do
30
- field :media_names, _("Installation media"), Fields::List
31
- field :architecture_names, _("Architectures"), Fields::List
32
- field :ptable_names, _("Partition tables"), Fields::List
33
- field :config_template_names, _("Config templates"), Fields::List
34
- collection :parameters, _("Parameters") do
35
- field nil, nil, Fields::KeyValue
22
+ field :name, _("Name")
23
+ field :major, _("Major version")
24
+ field :minor, _("Minor version")
25
+ collection :ptables, _("Partition tables"), :numbered => false do
26
+ custom_field Fields::Reference
36
27
  end
28
+ collection :os_default_templates, _("Default templates"), :numbered => false do
29
+ custom_field Fields::Template, :id_key => :config_template_id, :name_key => :config_template_name
30
+ end
31
+ collection :architectures, _("Architectures"), :numbered => false do
32
+ custom_field Fields::Reference
33
+ end
34
+ HammerCLIForeman::References.media(self)
35
+ HammerCLIForeman::References.config_templates(self)
36
+ HammerCLIForeman::References.parameters(self)
37
37
  end
38
38
 
39
- #FIXME: remove custom retrieve_data after the api has support for listing names
40
- def extend_data(os)
41
- os["_os_name"] = Hash[os.select { |k, v| ["name", "major", "minor"].include? k }]
42
- os["media_names"] = os["media"].collect{|m| m["name"] } rescue []
43
- os["architecture_names"] = os["architectures"].collect{|m| m["name"] } rescue []
44
- os["ptable_names"] = os["ptables"].collect{|m| m["name"] } rescue []
45
- os["config_template_names"] = os["config_templates"].collect{|m| m["name"] } rescue []
46
- os["parameters"] = HammerCLIForeman::Parameter.get_parameters(resource_config, :operatingsystem, os)
47
- os
48
- end
49
-
50
- apipie_options
39
+ build_options
51
40
  end
52
41
 
53
42
 
54
43
  class CreateCommand < HammerCLIForeman::CreateCommand
55
44
 
56
- #FIXME: replace with apipie_options when they are added to the api docs
45
+ #FIXME: replace with build_options when they are added to the api docs
57
46
  option "--architecture-ids", "ARCH_IDS", _("set associated architectures"),
58
47
  :format => HammerCLI::Options::Normalizers::List.new
59
48
  option "--config-template-ids", "CONFIG_TPL_IDS", _("set associated templates"),
@@ -75,13 +64,12 @@ module HammerCLIForeman
75
64
  params
76
65
  end
77
66
 
78
- apipie_options
67
+ build_options
79
68
  end
80
69
 
81
70
 
82
71
  class UpdateCommand < HammerCLIForeman::UpdateCommand
83
-
84
- #FIXME: replace with apipie_options when they are added to the api docs
72
+ #FIXME: replace with build_options when they are added to the api docs
85
73
  option "--architecture-ids", "ARCH_IDS", _("set associated architectures"),
86
74
  :format => HammerCLI::Options::Normalizers::List.new
87
75
  option "--config-template-ids", "CONFIG_TPL_IDS", _("set associated templates"),
@@ -91,8 +79,6 @@ module HammerCLIForeman
91
79
  option "--ptable-ids", "PTABLE_IDS", _("set associated partition tables"),
92
80
  :format => HammerCLI::Options::Normalizers::List.new
93
81
 
94
- identifiers :id
95
-
96
82
  success_message _("Operating system updated")
97
83
  failure_message _("Could not update the operating system")
98
84
 
@@ -105,72 +91,152 @@ module HammerCLIForeman
105
91
  params
106
92
  end
107
93
 
108
- apipie_options
94
+ build_options
109
95
  end
110
96
 
111
97
 
112
98
  class DeleteCommand < HammerCLIForeman::DeleteCommand
113
-
114
- identifiers :id
115
-
116
99
  success_message _("Operating system deleted")
117
100
  failure_message _("Could not delete the operating system")
118
101
 
119
- apipie_options
102
+ build_options
120
103
  end
121
104
 
122
- class SetParameterCommand < HammerCLIForeman::Parameter::SetCommand
123
-
124
- resource :parameters
125
105
 
106
+ class SetParameterCommand < HammerCLIForeman::Parameter::SetCommand
126
107
  desc _("Create or update parameter for an operating system.")
127
108
 
128
- #FIXME: add option --os-label when api supports it
129
- option "--os-id", "OS_ID", _("id of the operating system the parameter is being set for")
130
-
131
109
  success_message_for :update, _("Operating system parameter updated")
132
110
  success_message_for :create, _("New operating system parameter created")
133
111
  failure_message _("Could not set operating system parameter")
134
112
 
135
113
  def validate_options
136
114
  super
137
- validator.any(:option_os_id).required
115
+ validator.any(:option_operatingsystem_id).required
138
116
  end
139
117
 
140
- def base_action_params
141
- {
142
- "operatingsystem_id" => option_os_id
143
- }
144
- end
118
+ build_options
145
119
  end
146
120
 
147
121
 
148
122
  class DeleteParameterCommand < HammerCLIForeman::Parameter::DeleteCommand
149
-
150
- resource :parameters
151
-
152
123
  desc _("Delete parameter for an operating system.")
153
124
 
154
- #FIXME: add option --os-label when api supports it
155
- option "--os-id", "OS_ID", _("id of the operating system the parameter is being deleted for")
156
125
  success_message _("operating system parameter deleted")
157
126
 
158
127
  def validate_options
159
128
  super
160
- validator.any(:option_os_id).required
129
+ validator.any(:option_operatingsystem_id).required
130
+ end
131
+
132
+ build_options
133
+ end
134
+
135
+
136
+ class SetOsDefaultTemplate < HammerCLIForeman::Command
137
+ command_name "set-default-template"
138
+ resource :os_default_templates
139
+
140
+ option "--id", "OS ID", _("operatingsystem id"), :required => true
141
+ option "--config-template-id", "TPL ID", _("config template id to be set"), :required => true
142
+
143
+
144
+ success_message _("[%{config_template_name}] was set as default %{template_kind_name} template")
145
+ failure_message _("Could not set the os default template")
146
+
147
+ def option_type_name
148
+ tpl = HammerCLIForeman.collection_to_common_format(
149
+ HammerCLIForeman.foreman_resource(:config_templates).call(:show, {"id" => option_config_template_id}))
150
+ tpl[0]["template_kind_name"]
151
+ end
152
+
153
+ def base_action_params
154
+ {"operatingsystem_id" => option_id}
155
+ end
156
+
157
+ def template_exist?(tpl_kind_name)
158
+ templates = HammerCLIForeman.collection_to_common_format(resource.call(:index, base_action_params))
159
+ templates.find { |p| p["template_kind_name"] == tpl_kind_name}
160
+ end
161
+
162
+ def update_default_template(tpl)
163
+ params = {
164
+ "id" => tpl["id"],
165
+ "os_default_template" => {
166
+ "config_template_id" => option_config_template_id,
167
+ "template_kind_id" => tpl["template_kind_id"]
168
+ }
169
+ }.merge base_action_params
170
+
171
+ HammerCLIForeman.record_to_common_format(resource.call(:update, params))
172
+ end
173
+
174
+ def create_default_template(tpl_kind_name)
175
+ params = {
176
+ "os_default_template" => {
177
+ "config_template_id" => option_config_template_id,
178
+ "template_kind_name" => tpl_kind_name
179
+ }
180
+ }.merge base_action_params
181
+
182
+ HammerCLIForeman.record_to_common_format(resource.call(:create, params))
183
+ end
184
+
185
+ def execute
186
+ tpl_kind_name = option_type_name
187
+ tpl = template_exist? tpl_kind_name
188
+ if tpl
189
+ update_default_template tpl
190
+ print_message(success_message, tpl) if success_message
191
+ else
192
+ tpl = create_default_template tpl_kind_name
193
+ print_message(success_message, tpl) if success_message
194
+ end
195
+ HammerCLI::EX_OK
196
+ end
197
+
198
+ build_options :without => [:template_kind_id, :type]
199
+ end
200
+
201
+
202
+ class DeleteOsDefaultTemplate < HammerCLIForeman::Command
203
+ command_name "delete-default-template"
204
+ resource :os_default_templates
205
+
206
+ option "--id", "OS ID", _("operatingsystem id"), :required => true
207
+ option "--type", "TPL TYPE", _("Type of the config template"), :required => true
208
+
209
+ success_message _("Default template deleted")
210
+ failure_message _("Could not delete the default template")
211
+
212
+ def execute
213
+ templates = HammerCLIForeman.collection_to_common_format(resource.call(:index, base_action_params))
214
+ tpl = templates.find { |p| p["template_kind_name"] == option_type }
215
+
216
+ if tpl.nil?
217
+ raise RuntimeError.new(_("Default template of type #{option_type} not found"))
218
+ end
219
+
220
+ params = {
221
+ "id" => tpl["id"]
222
+ }.merge base_action_params
223
+
224
+ HammerCLIForeman.record_to_common_format(resource.call(:destroy, params))
225
+ print_message success_message if success_message
226
+ HammerCLI::EX_OK
161
227
  end
162
228
 
163
229
  def base_action_params
164
- {
165
- "operatingsystem_id" => option_os_id
166
- }
230
+ {"operatingsystem_id" => option_id}
167
231
  end
232
+
233
+ build_options
168
234
  end
169
235
 
170
236
 
171
- include HammerCLIForeman::AssociatingCommands::Architecture
172
- include HammerCLIForeman::AssociatingCommands::ConfigTemplate
173
- include HammerCLIForeman::AssociatingCommands::PartitionTable
237
+ HammerCLIForeman::AssociatingCommands::Architecture.extend_command(self)
238
+ HammerCLIForeman::AssociatingCommands::ConfigTemplate.extend_command(self)
239
+ HammerCLIForeman::AssociatingCommands::PartitionTable.extend_command(self)
174
240
 
175
241
 
176
242
  autoload_subcommands