hammer_cli_foreman 0.0.15 → 0.0.16

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 (38) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hammer_cli_foreman/architecture.rb +4 -6
  3. data/lib/hammer_cli_foreman/associating_commands.rb +26 -4
  4. data/lib/hammer_cli_foreman/commands.rb +17 -27
  5. data/lib/hammer_cli_foreman/common_parameter.rb +4 -3
  6. data/lib/hammer_cli_foreman/compute_resource.rb +3 -5
  7. data/lib/hammer_cli_foreman/domain.rb +8 -12
  8. data/lib/hammer_cli_foreman/environment.rb +2 -1
  9. data/lib/hammer_cli_foreman/exception_handler.rb +11 -2
  10. data/lib/hammer_cli_foreman/exceptions.rb +0 -2
  11. data/lib/hammer_cli_foreman/fact.rb +1 -5
  12. data/lib/hammer_cli_foreman/host.rb +47 -38
  13. data/lib/hammer_cli_foreman/hostgroup.rb +5 -8
  14. data/lib/hammer_cli_foreman/image.rb +11 -13
  15. data/lib/hammer_cli_foreman/location.rb +2 -5
  16. data/lib/hammer_cli_foreman/media.rb +2 -6
  17. data/lib/hammer_cli_foreman/model.rb +4 -5
  18. data/lib/hammer_cli_foreman/operating_system.rb +14 -18
  19. data/lib/hammer_cli_foreman/organization.rb +2 -5
  20. data/lib/hammer_cli_foreman/output.rb +2 -2
  21. data/lib/hammer_cli_foreman/parameter.rb +6 -8
  22. data/lib/hammer_cli_foreman/partition_table.rb +8 -11
  23. data/lib/hammer_cli_foreman/puppet_class.rb +2 -4
  24. data/lib/hammer_cli_foreman/report.rb +3 -4
  25. data/lib/hammer_cli_foreman/smart_class_parameter.rb +2 -6
  26. data/lib/hammer_cli_foreman/smart_proxy.rb +4 -7
  27. data/lib/hammer_cli_foreman/subnet.rb +2 -5
  28. data/lib/hammer_cli_foreman/template.rb +5 -6
  29. data/lib/hammer_cli_foreman/user.rb +2 -5
  30. data/lib/hammer_cli_foreman/version.rb +1 -1
  31. data/lib/hammer_cli_foreman.rb +7 -3
  32. data/test/unit/apipie_resource_mock.rb +9 -3
  33. data/test/unit/commands_test.rb +20 -0
  34. data/test/unit/exception_handler_test.rb +35 -1
  35. data/test/unit/helpers/command.rb +10 -2
  36. data/test/unit/host_test.rb +22 -0
  37. data/test/unit/partition_table_test.rb +4 -4
  38. metadata +6 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 61e7dc1e35e532761f9e2b59ec44b44a9f505fff
4
- data.tar.gz: e8c58306a33bc8dd3440fbaba31aa2e61656420e
3
+ metadata.gz: fcba3ecfc7d5f30eea296b370ff4ca1065a7043f
4
+ data.tar.gz: 5243fba92710c4586a9db6759d6df54a426a6adc
5
5
  SHA512:
6
- metadata.gz: 5a11f4290ab447ec0c6e2a85d45f7760fc8834d04993367c4497ecb89a693f4d72befe237d0f17e8b6fcbe3e46d00e54cd9ad4faa0f69c3922a582d6ca128b86
7
- data.tar.gz: 6e0865865ab755afcf98279c28382d4c903fc281bed04354ce1e5d17d72a6e842f162130b7a7fde7da156f376892cdbbbd336fc760ddd61f45c9ae849b172501
6
+ metadata.gz: ca0889415fc9bbfbf795e8c8fec86945170f63b9cf9223ede6a0f22687ed960fe587a8e966c320bd380b1b1d252213d857b038e31240378840a5ff9a17e1a34a
7
+ data.tar.gz: d03bd1d2a071979261b9e5397a6c55c330cea0c95f26be7f8c46fcff89473084afa5aa112baf4ce4469fbc7dbb1dc450128c04846f39c0bd2c6151e58859097c
@@ -1,8 +1,3 @@
1
- require 'hammer_cli'
2
- require 'foreman_api'
3
- require 'hammer_cli_foreman/commands'
4
- require 'hammer_cli_foreman/associating_commands'
5
-
6
1
  module HammerCLIForeman
7
2
 
8
3
  class Architecture < HammerCLI::Apipie::Command
@@ -28,6 +23,7 @@ module HammerCLIForeman
28
23
  field :updated_at, "Updated at", Fields::Date
29
24
  end
30
25
 
26
+ apipie_options
31
27
  end
32
28
 
33
29
 
@@ -42,6 +38,8 @@ module HammerCLIForeman
42
38
  class DeleteCommand < HammerCLIForeman::DeleteCommand
43
39
  success_message "Architecture deleted"
44
40
  failure_message "Could not delete the architecture"
41
+
42
+ apipie_options
45
43
  end
46
44
 
47
45
 
@@ -59,5 +57,5 @@ module HammerCLIForeman
59
57
 
60
58
  end
61
59
 
62
- HammerCLI::MainCommand.subcommand 'architecture', "Manipulate Foreman's architectures.", HammerCLIForeman::Architecture
60
+ HammerCLI::MainCommand.subcommand 'architecture', "Manipulate architectures.", HammerCLIForeman::Architecture
63
61
 
@@ -1,73 +1,82 @@
1
- require 'hammer_cli'
2
- require 'foreman_api'
3
- require 'hammer_cli_foreman/commands'
4
-
5
1
  module HammerCLIForeman
6
2
  module AssociatingCommands
7
3
 
8
4
  module Hostgroup
9
5
  class AddHostgroupCommand < HammerCLIForeman::AddAssociatedCommand
10
6
  associated_resource ForemanApi::Resources::Hostgroup
7
+ apipie_options
11
8
  end
12
9
 
13
10
  class RemoveHostgroupCommand < HammerCLIForeman::RemoveAssociatedCommand
14
11
  associated_resource ForemanApi::Resources::Hostgroup
12
+ apipie_options
15
13
  end
16
14
  end
17
15
 
18
16
  module Environment
19
17
  class AddEnvironmentCommand < HammerCLIForeman::AddAssociatedCommand
20
18
  associated_resource ForemanApi::Resources::Environment
19
+ apipie_options
21
20
  end
22
21
 
23
22
  class RemoveEnvironmentCommand < HammerCLIForeman::RemoveAssociatedCommand
24
23
  associated_resource ForemanApi::Resources::Environment
24
+ apipie_options
25
25
  end
26
26
  end
27
27
 
28
28
  module Domain
29
29
  class AddDomainCommand < HammerCLIForeman::AddAssociatedCommand
30
30
  associated_resource ForemanApi::Resources::Domain
31
+ apipie_options
31
32
  end
32
33
 
33
34
  class RemoveDomainCommand < HammerCLIForeman::RemoveAssociatedCommand
34
35
  associated_resource ForemanApi::Resources::Domain
36
+ apipie_options
35
37
  end
36
38
  end
37
39
 
38
40
  module Medium
39
41
  class AddMediumCommand < HammerCLIForeman::AddAssociatedCommand
40
42
  associated_resource ForemanApi::Resources::Medium
43
+ apipie_options
41
44
  end
42
45
 
43
46
  class RemoveMediumCommand < HammerCLIForeman::RemoveAssociatedCommand
44
47
  associated_resource ForemanApi::Resources::Medium
48
+ apipie_options
45
49
  end
46
50
  end
47
51
 
48
52
  module Subnet
49
53
  class AddSubnetCommand < HammerCLIForeman::AddAssociatedCommand
50
54
  associated_resource ForemanApi::Resources::Subnet
55
+ apipie_options
51
56
  end
52
57
 
53
58
  class RemoveSubnetCommand < HammerCLIForeman::RemoveAssociatedCommand
54
59
  associated_resource ForemanApi::Resources::Subnet
60
+ apipie_options
55
61
  end
56
62
  end
57
63
 
58
64
  module ComputeResource
59
65
  class AddComputeResourceCommand < HammerCLIForeman::AddAssociatedCommand
60
66
  associated_resource ForemanApi::Resources::ComputeResource
67
+ apipie_options
61
68
  end
62
69
 
63
70
  class RemoveComputeResourceCommand < HammerCLIForeman::RemoveAssociatedCommand
64
71
  associated_resource ForemanApi::Resources::ComputeResource
72
+ apipie_options
65
73
  end
66
74
  end
67
75
 
68
76
  module SmartProxy
69
77
  class AddSmartProxyCommand < HammerCLIForeman::AddAssociatedCommand
70
78
  associated_resource ForemanApi::Resources::SmartProxy
79
+ apipie_options
71
80
 
72
81
  def associated_resource_name
73
82
  "smart_proxy"
@@ -76,6 +85,7 @@ module HammerCLIForeman
76
85
 
77
86
  class RemoveSmartProxyCommand < HammerCLIForeman::RemoveAssociatedCommand
78
87
  associated_resource ForemanApi::Resources::SmartProxy
88
+ apipie_options
79
89
 
80
90
  def associated_resource_name
81
91
  "smart_proxy"
@@ -88,32 +98,38 @@ module HammerCLIForeman
88
98
  associated_identifiers :id
89
99
 
90
100
  associated_resource ForemanApi::Resources::User
101
+ apipie_options
91
102
  end
92
103
 
93
104
  class RemoveUserCommand < HammerCLIForeman::RemoveAssociatedCommand
94
105
  associated_identifiers :id
95
106
 
96
107
  associated_resource ForemanApi::Resources::User
108
+ apipie_options
97
109
  end
98
110
  end
99
111
 
100
112
  module ConfigTemplate
101
113
  class AddConfigTemplateCommand < HammerCLIForeman::AddAssociatedCommand
102
114
  associated_resource ForemanApi::Resources::ConfigTemplate
115
+ apipie_options
103
116
  end
104
117
 
105
118
  class RemoveConfigTemplateCommand < HammerCLIForeman::RemoveAssociatedCommand
106
119
  associated_resource ForemanApi::Resources::ConfigTemplate
120
+ apipie_options
107
121
  end
108
122
  end
109
123
 
110
124
  module Organization
111
125
  class AddOrganizationCommand < HammerCLIForeman::AddAssociatedCommand
112
126
  associated_resource ForemanApi::Resources::Organization
127
+ apipie_options
113
128
  end
114
129
 
115
130
  class RemoveOrganizationCommand < HammerCLIForeman::RemoveAssociatedCommand
116
131
  associated_resource ForemanApi::Resources::Organization
132
+ apipie_options
117
133
  end
118
134
  end
119
135
 
@@ -122,6 +138,7 @@ module HammerCLIForeman
122
138
  associated_resource ForemanApi::Resources::OperatingSystem
123
139
 
124
140
  associated_identifiers :id
141
+ apipie_options
125
142
 
126
143
  success_message "Operating system has been associated"
127
144
  failure_message "Could not associate the operating system"
@@ -132,6 +149,7 @@ module HammerCLIForeman
132
149
  associated_resource ForemanApi::Resources::OperatingSystem
133
150
 
134
151
  associated_identifiers :id
152
+ apipie_options
135
153
 
136
154
  success_message "Operating system has been disassociated"
137
155
  failure_message "Could not disassociate the operating system"
@@ -141,6 +159,7 @@ module HammerCLIForeman
141
159
  module Architecture
142
160
  class AddArchitectureCommand < HammerCLIForeman::AddAssociatedCommand
143
161
  associated_resource ForemanApi::Resources::Architecture
162
+ apipie_options
144
163
 
145
164
  success_message "Architecture has been associated"
146
165
  failure_message "Could not associate the architecture"
@@ -149,6 +168,7 @@ module HammerCLIForeman
149
168
 
150
169
  class RemoveArchitectureCommand < HammerCLIForeman::RemoveAssociatedCommand
151
170
  associated_resource ForemanApi::Resources::Architecture
171
+ apipie_options
152
172
 
153
173
  success_message "Architecture has been disassociated"
154
174
  failure_message "Could not disassociate the architecture"
@@ -158,6 +178,7 @@ module HammerCLIForeman
158
178
  module PartitionTable
159
179
  class AddPartitionTableCommand < HammerCLIForeman::AddAssociatedCommand
160
180
  associated_resource ForemanApi::Resources::Ptable
181
+ apipie_options
161
182
 
162
183
  success_message "Partition table has been associated"
163
184
  failure_message "Could not associate the partition table"
@@ -166,6 +187,7 @@ module HammerCLIForeman
166
187
 
167
188
  class RemovePartitionTableCommand < HammerCLIForeman::RemoveAssociatedCommand
168
189
  associated_resource ForemanApi::Resources::Ptable
190
+ apipie_options
169
191
 
170
192
  success_message "Partition table has been disassociated"
171
193
  failure_message "Could not disassociate the partition table"
@@ -1,5 +1,3 @@
1
- require 'hammer_cli'
2
-
3
1
  module HammerCLIForeman
4
2
 
5
3
  def self.collection_to_common_format(data)
@@ -30,8 +28,12 @@ module HammerCLIForeman
30
28
 
31
29
  class WriteCommand < HammerCLI::Apipie::WriteCommand
32
30
 
31
+ def request_headers
32
+ {}
33
+ end
34
+
33
35
  def send_request
34
- HammerCLIForeman.record_to_common_format(resource.call(action, request_params)[0])
36
+ HammerCLIForeman.record_to_common_format(resource.call(action, request_params, request_headers)[0])
35
37
  end
36
38
 
37
39
  end
@@ -115,10 +117,6 @@ module HammerCLIForeman
115
117
  {'id' => get_identifier[0]}
116
118
  end
117
119
 
118
- def self.apipie_options(options={})
119
- super({:without => declared_identifiers.keys}.merge(options))
120
- end
121
-
122
120
  def retrieve_data
123
121
  data = super
124
122
  record = HammerCLIForeman.record_to_common_format(data)
@@ -155,11 +153,11 @@ module HammerCLIForeman
155
153
  super(name) || "update"
156
154
  end
157
155
 
158
- identifiers :id, :name => :current_name
156
+ identifiers :id, :name => :option_current_name
159
157
 
160
- def setup_identifier_options
158
+ def self.setup_identifier_options
161
159
  super
162
- self.class.option "--new-name", "NEW_NAME", "new name for the resource", :attribute_name => :name if self.class.identifier? :name
160
+ option "--new-name", "NEW_NAME", "new name for the resource", :attribute_name => :option_name if identifier? :name
163
161
  end
164
162
 
165
163
  def request_params
@@ -168,10 +166,6 @@ module HammerCLIForeman
168
166
  params
169
167
  end
170
168
 
171
- def self.apipie_options(options={})
172
- super({:without => declared_identifiers.keys}.merge(options))
173
- end
174
-
175
169
  end
176
170
 
177
171
 
@@ -189,10 +183,6 @@ module HammerCLIForeman
189
183
  {'id' => get_identifier[0]}
190
184
  end
191
185
 
192
- def self.apipie_options(options={})
193
- super({:without => declared_identifiers.keys}.merge(options))
194
- end
195
-
196
186
  end
197
187
 
198
188
 
@@ -207,16 +197,16 @@ module HammerCLIForeman
207
197
  validator.any(*self.class.declared_identifiers.values).required
208
198
  end
209
199
 
210
- def initialize(*args)
211
- super
200
+ def self.apipie_options(options={})
212
201
  setup_associated_identifier_options
202
+ super
213
203
  end
214
204
 
215
- def setup_associated_identifier_options
205
+ def self.setup_associated_identifier_options
216
206
  name = associated_resource.name.to_s
217
207
  option_switch = "--"+name.gsub('_', '-')
218
- self.class.option option_switch, name.upcase, " ", :attribute_name => :associated_name if self.class.declared_associated_identifiers.include? :name
219
- self.class.option option_switch+"-id", name.upcase+"_ID", " ", :attribute_name => :associated_id if self.class.declared_associated_identifiers.include? :id
208
+ option option_switch, name.upcase, " ", :attribute_name => :associated_name if declared_associated_identifiers.include? :name
209
+ option option_switch+"-id", name.upcase+"_ID", " ", :attribute_name => :associated_id if declared_associated_identifiers.include? :id
220
210
  end
221
211
 
222
212
 
@@ -252,13 +242,13 @@ module HammerCLIForeman
252
242
  end
253
243
 
254
244
  def get_current_ids
255
- item = resource.call('show', {'id' => get_identifier[0]})[0]
256
- item[resource.name][associated_resource.name+'_ids'] || []
245
+ item = HammerCLIForeman.record_to_common_format(resource.call('show', {'id' => get_identifier[0]})[0])
246
+ item[associated_resource.name+'_ids'] || []
257
247
  end
258
248
 
259
249
  def get_required_id
260
- item = associated_resource.call('show', {'id' => associated_id || associated_name})[0]
261
- item[associated_resource.name]['id']
250
+ item = HammerCLIForeman.record_to_common_format(associated_resource.call('show', {'id' => associated_id || associated_name})[0])
251
+ item['id']
262
252
  end
263
253
 
264
254
  def request_params
@@ -41,12 +41,13 @@ module HammerCLIForeman
41
41
 
42
42
  def parameter_exist?
43
43
  params = resource.call(:index)[0]
44
- params.find { |p| p["common_parameter"]["name"] == name }
44
+ params = HammerCLIForeman.collection_to_common_format(params)
45
+ params.find { |p| p["name"] == option_name }
45
46
  end
46
47
 
47
48
  def request_params
48
49
  params = method_options
49
- params['id'] = name
50
+ params['id'] = option_name
50
51
  params
51
52
  end
52
53
 
@@ -68,4 +69,4 @@ module HammerCLIForeman
68
69
  end
69
70
  end
70
71
 
71
- HammerCLI::MainCommand.subcommand 'global_parameter', "Manipulate Foreman's global parameters.", HammerCLIForeman::CommonParameter
72
+ HammerCLI::MainCommand.subcommand 'global_parameter', "Manipulate global parameters.", HammerCLIForeman::CommonParameter
@@ -1,6 +1,3 @@
1
- require 'hammer_cli'
2
- require 'foreman_api'
3
- require 'hammer_cli_foreman/commands'
4
1
  require 'hammer_cli_foreman/image'
5
2
 
6
3
  module HammerCLIForeman
@@ -57,6 +54,7 @@ module HammerCLIForeman
57
54
  print_collection(output_definition, data)
58
55
  end
59
56
 
57
+ apipie_options
60
58
  end
61
59
 
62
60
 
@@ -68,7 +66,7 @@ module HammerCLIForeman
68
66
  apipie_options
69
67
 
70
68
  validate_options do
71
- all(:name, :url, :provider).required
69
+ all(:option_name, :option_url, :option_provider).required
72
70
  end
73
71
  end
74
72
 
@@ -97,6 +95,6 @@ module HammerCLIForeman
97
95
 
98
96
  end
99
97
 
100
- HammerCLI::MainCommand.subcommand 'compute_resource', "Manipulate Foreman's compute resources.", HammerCLIForeman::ComputeResource
98
+ HammerCLI::MainCommand.subcommand 'compute_resource', "Manipulate compute resources.", HammerCLIForeman::ComputeResource
101
99
 
102
100
 
@@ -1,8 +1,3 @@
1
- require 'hammer_cli'
2
- require 'foreman_api'
3
- require 'hammer_cli_foreman/commands'
4
- require 'hammer_cli_foreman/parameter'
5
-
6
1
  module HammerCLIForeman
7
2
 
8
3
  class Domain < HammerCLI::AbstractCommand
@@ -37,6 +32,7 @@ module HammerCLIForeman
37
32
  record
38
33
  end
39
34
 
35
+ apipie_options
40
36
  end
41
37
 
42
38
 
@@ -47,7 +43,7 @@ module HammerCLIForeman
47
43
  resource ForemanApi::Resources::Domain, "create"
48
44
 
49
45
  apipie_options :without => [:domain_parameters_attributes, :fullname]
50
- option "--description", "DESC", "Full name describing the domain", :attribute_name => :fullname
46
+ option "--description", "DESC", "Full name describing the domain", :attribute_name => :option_fullname
51
47
  end
52
48
 
53
49
 
@@ -58,7 +54,7 @@ module HammerCLIForeman
58
54
  resource ForemanApi::Resources::Domain, "update"
59
55
 
60
56
  apipie_options :without => [:domain_parameters_attributes, :name, :id, :fullname]
61
- option "--description", "DESC", "Full name describing the domain", :attribute_name => :fullname
57
+ option "--description", "DESC", "Full name describing the domain", :attribute_name => :option_fullname
62
58
  end
63
59
 
64
60
 
@@ -87,12 +83,12 @@ module HammerCLIForeman
87
83
 
88
84
  def validate_options
89
85
  super
90
- validator.any(:domain_name, :domain_id).required
86
+ validator.any(:option_domain_name, :option_domain_id).required
91
87
  end
92
88
 
93
89
  def base_action_params
94
90
  {
95
- "domain_id" => domain_id || domain_name
91
+ "domain_id" => option_domain_id || option_domain_name
96
92
  }
97
93
  end
98
94
  end
@@ -111,12 +107,12 @@ module HammerCLIForeman
111
107
 
112
108
  def validate_options
113
109
  super
114
- validator.any(:domain_name, :domain_id).required
110
+ validator.any(:option_domain_name, :option_domain_id).required
115
111
  end
116
112
 
117
113
  def base_action_params
118
114
  {
119
- "domain_id" => domain_id || domain_name
115
+ "domain_id" => option_domain_id || option_domain_name
120
116
  }
121
117
  end
122
118
  end
@@ -126,5 +122,5 @@ module HammerCLIForeman
126
122
 
127
123
  end
128
124
 
129
- HammerCLI::MainCommand.subcommand 'domain', "Manipulate Foreman's domains.", HammerCLIForeman::Domain
125
+ HammerCLI::MainCommand.subcommand 'domain', "Manipulate domains.", HammerCLIForeman::Domain
130
126
 
@@ -27,6 +27,7 @@ module HammerCLIForeman
27
27
  field :updated_at, "Updated at", Fields::Date
28
28
  end
29
29
 
30
+ apipie_options
30
31
  end
31
32
 
32
33
 
@@ -72,5 +73,5 @@ module HammerCLIForeman
72
73
 
73
74
  end
74
75
 
75
- HammerCLI::MainCommand.subcommand 'environment', "Manipulate Foreman's environments.", HammerCLIForeman::Environment
76
+ HammerCLI::MainCommand.subcommand 'environment', "Manipulate environments.", HammerCLIForeman::Environment
76
77
 
@@ -17,8 +17,7 @@ module HammerCLIForeman
17
17
 
18
18
  def handle_unprocessable_entity(e)
19
19
  response = JSON.parse(e.response)
20
- response = response[response.keys[0]]
21
-
20
+ response = HammerCLIForeman.record_to_common_format(response)
22
21
  print_error response["full_messages"]
23
22
  HammerCLI::EX_DATAERR
24
23
  end
@@ -44,6 +43,16 @@ module HammerCLIForeman
44
43
  HammerCLI::EX_UNAVAILABLE
45
44
  end
46
45
 
46
+
47
+ def handle_not_found(e)
48
+ response = JSON.parse(e.response)
49
+ message = response["message"] || e.message
50
+
51
+ print_error message
52
+ log_full_error e
53
+ HammerCLI::EX_NOT_FOUND
54
+ end
55
+
47
56
  end
48
57
  end
49
58
 
@@ -1,5 +1,3 @@
1
- require 'hammer_cli_foreman/exceptions'
2
-
3
1
  module HammerCLIForeman
4
2
 
5
3
  class OperationNotSupportedError < StandardError; end
@@ -1,7 +1,3 @@
1
- require 'hammer_cli'
2
- require 'foreman_api'
3
- require 'hammer_cli_foreman/commands'
4
-
5
1
  module HammerCLIForeman
6
2
 
7
3
  class Fact < HammerCLI::AbstractCommand
@@ -37,4 +33,4 @@ module HammerCLIForeman
37
33
 
38
34
  end
39
35
 
40
- HammerCLI::MainCommand.subcommand 'fact', "Search Foreman's facts.", HammerCLIForeman::Fact
36
+ HammerCLI::MainCommand.subcommand 'fact', "Search facts.", HammerCLIForeman::Fact