hammer_cli_foreman 0.16.0 → 0.17.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 (70) hide show
  1. checksums.yaml +5 -5
  2. data/doc/release_notes.md +13 -0
  3. data/lib/hammer_cli_foreman.rb +4 -0
  4. data/lib/hammer_cli_foreman/common_parameter.rb +4 -0
  5. data/lib/hammer_cli_foreman/compute_attribute.rb +318 -0
  6. data/lib/hammer_cli_foreman/compute_profile.rb +61 -0
  7. data/lib/hammer_cli_foreman/compute_resource.rb +29 -13
  8. data/lib/hammer_cli_foreman/compute_resource/base.rb +12 -0
  9. data/lib/hammer_cli_foreman/compute_resource/ec2.rb +24 -0
  10. data/lib/hammer_cli_foreman/compute_resource/gce.rb +23 -0
  11. data/lib/hammer_cli_foreman/compute_resource/help_utils.rb +34 -0
  12. data/lib/hammer_cli_foreman/compute_resource/libvirt.rb +49 -0
  13. data/lib/hammer_cli_foreman/compute_resource/openstack.rb +25 -0
  14. data/lib/hammer_cli_foreman/compute_resource/ovirt.rb +47 -0
  15. data/lib/hammer_cli_foreman/compute_resource/rackspace.rb +22 -0
  16. data/lib/hammer_cli_foreman/compute_resource/register_compute_resources.rb +20 -0
  17. data/lib/hammer_cli_foreman/compute_resource/vmware.rb +68 -0
  18. data/lib/hammer_cli_foreman/host.rb +4 -11
  19. data/lib/hammer_cli_foreman/hostgroup.rb +9 -0
  20. data/lib/hammer_cli_foreman/hosts/common_update_help.rb +1 -7
  21. data/lib/hammer_cli_foreman/hosts/common_update_options.rb +1 -1
  22. data/lib/hammer_cli_foreman/id_resolver.rb +3 -1
  23. data/lib/hammer_cli_foreman/parameter.rb +7 -0
  24. data/lib/hammer_cli_foreman/references.rb +8 -0
  25. data/lib/hammer_cli_foreman/report_template.rb +79 -0
  26. data/lib/hammer_cli_foreman/smart_variable.rb +1 -2
  27. data/lib/hammer_cli_foreman/version.rb +1 -1
  28. data/locale/ca/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  29. data/locale/de/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  30. data/locale/en/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  31. data/locale/en_GB/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  32. data/locale/es/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  33. data/locale/fr/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  34. data/locale/it/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  35. data/locale/ja/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  36. data/locale/ko/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  37. data/locale/pt_BR/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  38. data/locale/ru/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  39. data/locale/zh_CN/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  40. data/locale/zh_TW/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  41. data/test/data/1.21/foreman_api.json +1 -0
  42. data/test/data/1.22/foreman_api.json +1 -0
  43. data/test/functional/compute_attribute_test.rb +654 -0
  44. data/test/functional/compute_profile_test.rb +99 -0
  45. data/test/functional/compute_resource_test.rb +42 -18
  46. data/test/functional/location_test.rb +6 -5
  47. data/test/functional/organization_test.rb +6 -5
  48. data/test/functional/report_template_test.rb +107 -7
  49. data/test/test_helper.rb +1 -1
  50. data/test/unit/common_parameter_test.rb +17 -5
  51. data/test/unit/domain_test.rb +2 -0
  52. data/test/unit/host_test.rb +1 -0
  53. data/test/unit/hostgroup_test.rb +14 -1
  54. data/test/unit/operating_system_test.rb +1 -0
  55. metadata +25 -20
  56. data/lib/hammer_cli_foreman/compute_resources/all.rb +0 -7
  57. data/lib/hammer_cli_foreman/compute_resources/ec2.rb +0 -9
  58. data/lib/hammer_cli_foreman/compute_resources/ec2/host_help_extenstion.rb +0 -23
  59. data/lib/hammer_cli_foreman/compute_resources/gce.rb +0 -9
  60. data/lib/hammer_cli_foreman/compute_resources/gce/host_help_extenstion.rb +0 -22
  61. data/lib/hammer_cli_foreman/compute_resources/libvirt.rb +0 -9
  62. data/lib/hammer_cli_foreman/compute_resources/libvirt/host_help_extenstion.rb +0 -35
  63. data/lib/hammer_cli_foreman/compute_resources/openstack.rb +0 -9
  64. data/lib/hammer_cli_foreman/compute_resources/openstack/host_help_extenstion.rb +0 -23
  65. data/lib/hammer_cli_foreman/compute_resources/ovirt.rb +0 -9
  66. data/lib/hammer_cli_foreman/compute_resources/ovirt/host_help_extenstion.rb +0 -36
  67. data/lib/hammer_cli_foreman/compute_resources/rackspace.rb +0 -9
  68. data/lib/hammer_cli_foreman/compute_resources/rackspace/host_help_extenstion.rb +0 -20
  69. data/lib/hammer_cli_foreman/compute_resources/vmware.rb +0 -9
  70. data/lib/hammer_cli_foreman/compute_resources/vmware/host_help_extenstion.rb +0 -66
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c8e1d9e2bdf020465f92034a08e8348496fe4b4f
4
- data.tar.gz: 8e5b33da07245341c8a0b8df40662736f5c4c83d
2
+ SHA256:
3
+ metadata.gz: 879dc32762958668d6e95ffb5ff7ba04222b42be763aad77bd00045763074d45
4
+ data.tar.gz: 75334fc224d49d58d2b0f3ff9b420db02fa25d84df2f8595736e4fe92872fdcf
5
5
  SHA512:
6
- metadata.gz: b4262e878d4e0cd9254cccf99ed75827559b525b55e42a402da594331d85df2ce8e1e23c7cc439271cb8649bbca14dfe4063b4913e99e01b7e88251adcf9feb2
7
- data.tar.gz: 959f424ddfc94a4a60ca5da344945cb4859005e4529fdd14bcce61ff5ca5beb17bab7b937d308356cc73e969dd8bc36012642d94bc1e0a38296af4d446ac9c3d
6
+ metadata.gz: 6e0f879c792cadf51b3a53fcac50297f5620a203b1a7e2d0c85df655926f29da00f5452734a79e79f000fb3ab030ff3058cf569e3339c5991d942a2fb2145d20
7
+ data.tar.gz: 46800432d77b3cea0c324995b5cd4ba3a49d69bde6f6d4ba2fc6bd0e1b7c2a69f7ed6148f3489ba3a7912f2742396844a31666a29ea71076598f956349ccafa6
@@ -1,5 +1,18 @@
1
1
  Release notes
2
2
  =============
3
+ ### 0.17.0 (2019-04-24)
4
+ * Add public key option in create compute resource CLI ([#25491](http://projects.theforeman.org/issues/25491))
5
+ * Background template rendering ([PR #414](https://github.com/theforeman/hammer-cli-foreman/pull/414)) ([#26355](http://projects.theforeman.org/issues/26355))
6
+ * Parameter type to parameter commands ([#26008](http://projects.theforeman.org/issues/26008))
7
+ * New API data that needed for parameter_type fix ([#26008](http://projects.theforeman.org/issues/26008))
8
+ * parameter_type option to parameter commands ([#26008](http://projects.theforeman.org/issues/26008))
9
+ * Move compute resource validation to their class ([#26234](http://projects.theforeman.org/issues/26234))
10
+ * Improve documentation of id fields in ovirt ([#26334](http://projects.theforeman.org/issues/26334))
11
+ * Add rebuild-config subcommand for hostgroups ([#26129](http://projects.theforeman.org/issues/26129))
12
+ * Add compute profile commands ([PR #398](https://github.com/theforeman/hammer-cli-foreman/pull/398)) ([#20538](http://projects.theforeman.org/issues/20538))
13
+ * Display uptime ([#26019](http://projects.theforeman.org/issues/26019))
14
+ * Hammer host update and set-parameters need clarification ([#25964](http://projects.theforeman.org/issues/25964))
15
+
3
16
  ### 0.16.0 (2019-01-16)
4
17
  * Use make targets for translations from core ([#25724](http://projects.theforeman.org/issues/25724))
5
18
  * Allow mixing option sources and validations ([PR #402](https://github.com/theforeman/hammer-cli-foreman/pull/402)) ([#22253](http://projects.theforeman.org/issues/22253))
@@ -45,6 +45,10 @@ module HammerCLIForeman
45
45
  'HammerCLIForeman::Audit', 'hammer_cli_foreman/audit'
46
46
  )
47
47
 
48
+ HammerCLI::MainCommand.lazy_subcommand('compute-profile', _("Manipulate compute profiles"),
49
+ 'HammerCLIForeman::ComputeProfile', 'hammer_cli_foreman/compute_profile'
50
+ )
51
+
48
52
  HammerCLI::MainCommand.lazy_subcommand('compute-resource', _("Manipulate compute resources"),
49
53
  'HammerCLIForeman::ComputeResource', 'hammer_cli_foreman/compute_resource'
50
54
  )
@@ -11,6 +11,7 @@ module HammerCLIForeman
11
11
  output do
12
12
  field :name, _("Name")
13
13
  field :value, _("Value")
14
+ field :parameter_type, _("Type")
14
15
  end
15
16
 
16
17
  build_options
@@ -27,6 +28,9 @@ module HammerCLIForeman
27
28
  option "--name", "NAME", _("Parameter name"), :required => true
28
29
  option "--value", "VALUE", _("Parameter value"), :required => true
29
30
  option "--hidden-value", "HIDDEN_VALUE", _("Should the value be hidden"), :format => HammerCLI::Options::Normalizers::Bool.new
31
+ option "--parameter-type", "PARAMETER_TYPE", _("Type of the parameter"),
32
+ :default => 'string',
33
+ :format => HammerCLI::Options::Normalizers::Enum.new(Parameter::KEY_TYPES)
30
34
 
31
35
  def action
32
36
  @action ||= parameter_exist? ? :update : :create
@@ -0,0 +1,318 @@
1
+ require 'hammer_cli_foreman/image'
2
+ require 'hammer_cli_foreman/compute_resource/register_compute_resources'
3
+ require 'hammer_cli_foreman/compute_resource/help_utils'
4
+
5
+ module HammerCLIForeman
6
+ class ComputeAttribute < HammerCLIForeman::Command
7
+ resource :compute_attributes
8
+
9
+ def self.get_params(options)
10
+ params = {}
11
+ params['compute_attribute'] = {}
12
+ profile = HammerCLIForeman.record_to_common_format(
13
+ HammerCLIForeman.foreman_resource(:compute_profiles).call(:show, 'id' => options['option_compute_profile_id'] )
14
+ )
15
+ params['compute_attribute'] = profile['compute_attributes'].select { |hash| hash['compute_resource_id'] == options['option_compute_resource_id']}[0] || {}
16
+ params['compute_attribute'].delete('attributes') if params['compute_attribute']['attributes']
17
+ params
18
+ end
19
+
20
+ def self.attribute_hash(attribute_list)
21
+ attribute_list.size.times.map { |idx| idx.to_s }.zip(attribute_list).to_h
22
+ end
23
+
24
+ class Create < HammerCLIForeman::CreateCommand
25
+ desc _('Create compute profile set of values')
26
+
27
+ option '--compute-attributes', 'COMPUTE_ATTRS', _('Compute resource attributes'),
28
+ :format => HammerCLI::Options::Normalizers::KeyValueList.new
29
+ option '--interface', 'INTERFACE', _('Interface parameters, should be comma separated list of values'),
30
+ :format => HammerCLI::Options::Normalizers::KeyValueList.new, :multivalued => true
31
+ option '--volume', 'VOLUME', _('Volume parameters, should be comma separated list of values'),
32
+ :format => HammerCLI::Options::Normalizers::KeyValueList.new, :multivalued => true
33
+
34
+ extend_help do |h|
35
+ ::HammerCLIForeman::ComputeResources.extend_help(h, :all)
36
+ end
37
+
38
+ validate_options do
39
+ any(:option_compute_profile_id, :option_compute_profile_name ).required
40
+ any(:option_compute_resource_id, :option_compute_resource_name).required
41
+ end
42
+
43
+ def request_params
44
+ params = super
45
+ compute_resource_name = HammerCLIForeman.record_to_common_format(HammerCLIForeman.foreman_resource(:compute_resources).call(:show, 'id' => options["option_compute_resource_id"] ))["provider_friendly_name"].downcase
46
+ interfaces_attr_name = ::HammerCLIForeman.compute_resources[compute_resource_name].interfaces_attrs_name
47
+ params['compute_attribute']['vm_attrs'] = option_compute_attributes || {}
48
+ params['compute_attribute']['vm_attrs'][interfaces_attr_name]= HammerCLIForeman::ComputeAttribute.attribute_hash(option_interface_list) unless option_interface_list.empty?
49
+ params['compute_attribute']['vm_attrs']['volumes_attributes'] = HammerCLIForeman::ComputeAttribute.attribute_hash(option_volume_list) unless option_volume_list.empty?
50
+ params
51
+ end
52
+
53
+ success_message _('Compute profile attributes are set.')
54
+ failure_message _('Could not set the compute profile attributes')
55
+ build_options
56
+ end
57
+
58
+ class Update < HammerCLIForeman::UpdateCommand
59
+ desc _('Update compute profile values')
60
+
61
+ option '--compute-attributes', 'COMPUTE_ATTRS', _('Compute resource attributes, should be comma separated list of values'),
62
+ :format => HammerCLI::Options::Normalizers::KeyValueList.new
63
+ option '--interface', 'INTERFACE', _('Interface parameters, should be comma separated list of values'),
64
+ :format => HammerCLI::Options::Normalizers::KeyValueList.new, :multivalued => true
65
+ option '--volume', 'VOLUME', _('Volume parameters, should be comma separated list of values'),
66
+ :format => HammerCLI::Options::Normalizers::KeyValueList.new, :multivalued => true
67
+
68
+ extend_help do |h|
69
+ ::HammerCLIForeman::ComputeResources.extend_help(h, :all)
70
+ end
71
+
72
+ validate_options do
73
+ any(:option_compute_profile_id, :option_compute_profile_name ).required
74
+ any(:option_compute_resource_id, :option_compute_resource_name).required
75
+ end
76
+
77
+
78
+ def request_params
79
+
80
+ params = HammerCLIForeman::ComputeAttribute.get_params(options)
81
+ compute_resource_name = HammerCLIForeman.record_to_common_format(HammerCLIForeman.foreman_resource(:compute_resources).call(:show, 'id' => options["option_compute_resource_id"] ))["provider_friendly_name"].downcase
82
+ interfaces_attr_name = ::HammerCLIForeman.compute_resources[compute_resource_name].interfaces_attrs_name
83
+
84
+ raise ArgumentError, "Compute profile value to update does not exist yet; it needs to be created first" if !params['compute_attribute'].key?('id')
85
+ params['id'] = params['compute_attribute']['id']
86
+ vm_attrs = params['compute_attribute']['vm_attrs']
87
+ original_volumes = vm_attrs['volumes_attributes'] || {}
88
+ original_interfaces = vm_attrs[interfaces_attr_name] || {}
89
+
90
+ if options['option_compute_attributes']
91
+ vm_attrs = options['option_compute_attributes']
92
+ vm_attrs['volumes_attributes'] ||= original_volumes
93
+ vm_attrs[interfaces_attr_name] ||= original_interfaces
94
+ end
95
+ vm_attrs[interfaces_attr_name] = HammerCLIForeman::ComputeAttribute.attribute_hash(options['option_interface_list']) unless options['option_interface_list'].empty?
96
+ vm_attrs['volumes_attributes'] = HammerCLIForeman::ComputeAttribute.attribute_hash(options['option_volume_list']) unless options['option_volume_list'].empty?
97
+ params['compute_attribute']['vm_attrs'] = vm_attrs
98
+ params
99
+
100
+ end
101
+ success_message _('Compute profile attributes updated.')
102
+ failure_message _('Could not update the compute profile attributes')
103
+
104
+ build_options :without => :id
105
+ end
106
+
107
+ # Using the Update command because adding a new interface is done by modifying existing compute_attribute
108
+ class AddInterface < HammerCLIForeman::UpdateCommand
109
+ command_name 'add-interface'
110
+ desc _('Add interface for Compute Profile')
111
+ option '--interface', 'SET_VALUES', _('Interface parameters, should be comma separated list of values'),
112
+ :format => HammerCLI::Options::Normalizers::KeyValueList.new, :required => true
113
+
114
+ extend_help do |h|
115
+ ::HammerCLIForeman::ComputeResources.extend_help(h, :interface)
116
+ end
117
+
118
+ def validate_options
119
+ super
120
+ validator.any(:option_compute_profile_id,:option_compute_profile_name).required
121
+ validator.any(:option_compute_resource_id,:option_compute_resource_name).required
122
+ end
123
+
124
+ def request_params
125
+ params = HammerCLIForeman::ComputeAttribute.get_params(options)
126
+
127
+ raise ArgumentError, "Compute profile value to update does not exist yet; it needs to be created first" if !params['compute_attribute'].key?('id')
128
+ compute_resource_name = HammerCLIForeman.record_to_common_format(HammerCLIForeman.foreman_resource(:compute_resources).call(:show, 'id' => options["option_compute_resource_id"] ))["provider_friendly_name"].downcase
129
+
130
+
131
+ interfaces_attr_name = ::HammerCLIForeman.compute_resources[compute_resource_name].interfaces_attrs_name
132
+ interface_attr = params['compute_attribute']['vm_attrs'][interfaces_attr_name] || {}
133
+ new_interface_id = (interface_attr.keys.max.to_i + 1 ).to_s if interface_attr.any?
134
+ new_interface_id ||= "0"
135
+ params['id'] = params['compute_attribute']['id']
136
+
137
+ params['compute_attribute']['vm_attrs'][interfaces_attr_name] ||= {}
138
+ params['compute_attribute']['vm_attrs'][interfaces_attr_name][new_interface_id] = option_interface
139
+ params
140
+ end
141
+
142
+ success_message _('Interface was created.')
143
+ failure_message _('Could not create interface')
144
+
145
+ build_options :without => :id
146
+ end
147
+
148
+ class UpdateInterface < HammerCLIForeman::UpdateCommand
149
+ command_name 'update-interface'
150
+
151
+ desc _('Update compute profile interface')
152
+
153
+ option '--interface', 'SET_VALUES', _('Interface parameters, should be comma separated list of values'),
154
+ :required => true,
155
+ :format => HammerCLI::Options::Normalizers::KeyValueList.new
156
+ option '--interface-id', 'INTERFACE_ID', _('Interface id'),
157
+ :required => true,
158
+ :format => HammerCLI::Options::Normalizers::Number.new
159
+
160
+ extend_help do |h|
161
+ ::HammerCLIForeman::ComputeResources.extend_help(h, :interface)
162
+ end
163
+
164
+ def validate_options
165
+ super
166
+ validator.any(:option_compute_profile_id, :option_compute_profile_name).required
167
+ validator.any(:option_compute_resource_id, :option_compute_resource_name).required
168
+ end
169
+
170
+ def request_params
171
+ params = HammerCLIForeman::ComputeAttribute.get_params(options)
172
+ raise ArgumentError, "Compute profile value to update does not exist yet; it needs to be created first" if !params['compute_attribute'].key?('id')
173
+ compute_resource_name = HammerCLIForeman.record_to_common_format(HammerCLIForeman.foreman_resource(:compute_resources).call(:show, 'id' => options["option_compute_resource_id"] ))["provider_friendly_name"].downcase
174
+ interfaces_attr_name = ::HammerCLIForeman.compute_resources[compute_resource_name].interfaces_attrs_name
175
+ params['id'] = params['compute_attribute']['id']
176
+ params['compute_attribute']['vm_attrs'][interfaces_attr_name] ||= {}
177
+ params['compute_attribute']['vm_attrs'][interfaces_attr_name][option_interface_id] = option_interface
178
+ params
179
+ end
180
+ success_message _('Interface was updated.')
181
+ failure_message _('Could not update interface')
182
+ build_options :without => :id
183
+ end
184
+
185
+ # Using the Update command because removing an interface is done by modifying existing compute_attribute
186
+ class RemoveInterface < HammerCLIForeman::UpdateCommand
187
+ command_name 'remove-interface'
188
+ desc _('Remove compute profile interface')
189
+ option '--interface-id', 'INTERFACE ID', _('Interface id'),
190
+ :format => HammerCLI::Options::Normalizers::Number.new , :required => true
191
+
192
+ def validate_options
193
+ super
194
+ validator.any(:option_compute_profile_id, :option_compute_profile_name).required
195
+ validator.any(:option_compute_resource_id, :option_compute_resource_name).required
196
+ end
197
+
198
+ def request_params
199
+ params = HammerCLIForeman::ComputeAttribute.get_params(options)
200
+ raise ArgumentError, "Compute profile value to update does not exist yet; it needs to be created first" if !params['compute_attribute'].key?('id')
201
+ compute_resource_name = HammerCLIForeman.record_to_common_format(HammerCLIForeman.foreman_resource(:compute_resources).call(:show, 'id' => options["option_compute_resource_id"] ))["provider_friendly_name"].downcase
202
+ interfaces_attr_name = ::HammerCLIForeman.compute_resources[compute_resource_name].interfaces_attrs_name
203
+ params['id'] = params['compute_attribute']['id']
204
+ if params['compute_attribute']['vm_attrs'][interfaces_attr_name].has_key?(option_interface_id.to_s)
205
+ params['compute_attribute']['vm_attrs'][interfaces_attr_name].delete(option_interface_id.to_s)
206
+ else
207
+ signal_usage_error _('unknown interface id')
208
+ end
209
+ params
210
+ end
211
+ success_message _('Interface was removed.')
212
+ failure_message _('Could not remove interface')
213
+ build_options :without => :id
214
+ end
215
+
216
+ # Using the Update command because adding a new volume is done by modifying existing compute_attribute
217
+ class AddVolume < HammerCLIForeman::UpdateCommand
218
+ command_name 'add-volume'
219
+ desc _('Add volume for Compute Profile')
220
+
221
+ option '--volume', 'VOLUME', _('Volume parameters, should be comma separated list of values'),
222
+ :format => HammerCLI::Options::Normalizers::KeyValueList.new, :required => true
223
+
224
+ extend_help do |h|
225
+ ::HammerCLIForeman::ComputeResources.extend_help(h, :volume)
226
+ end
227
+
228
+ def validate_options
229
+ super
230
+ validator.any(:option_compute_profile_id, :option_compute_profile_name).required
231
+ validator.any(:option_compute_resource_id, :option_compute_resource_name).required
232
+ end
233
+
234
+ def request_params
235
+ params = HammerCLIForeman::ComputeAttribute.get_params(options)
236
+ raise ArgumentError, "Compute profile value to update does not exist yet; it needs to be created first" if !params['compute_attribute'].key?('id')
237
+ volume_attr = params['compute_attribute']['vm_attrs']['volumes_attributes'] || {}
238
+ new_volume_id = (volume_attr.keys.max.to_i + 1 ).to_s if volume_attr.any?
239
+ new_volume_id ||= "0"
240
+ params['id'] = params['compute_attribute']['id']
241
+ params['compute_attribute']['vm_attrs']['volumes_attributes'] ||= {}
242
+ params['compute_attribute']['vm_attrs']['volumes_attributes'][new_volume_id] = option_volume
243
+ params
244
+ end
245
+
246
+ success_message _('Volume was created.')
247
+ failure_message _('Could not create volume')
248
+ build_options :without => :id
249
+ end
250
+
251
+ class UpdateVolume < HammerCLIForeman::UpdateCommand
252
+ command_name 'update-volume'
253
+ desc _('Update compute profile volume')
254
+
255
+ option '--volume', 'VOLUME', _('Volume parameters, should be comma separated list of values'),
256
+ :required => true,
257
+ :format => HammerCLI::Options::Normalizers::KeyValueList.new
258
+ option '--volume-id', 'VOLUME_ID', _('Volume id'),
259
+ :required => true,
260
+ :format => HammerCLI::Options::Normalizers::Number.new
261
+
262
+ extend_help do |h|
263
+ ::HammerCLIForeman::ComputeResources.extend_help(h, :volume)
264
+ end
265
+
266
+
267
+ def validate_options
268
+ super
269
+ validator.any(:option_compute_profile_id, :option_compute_profile_name).required
270
+ validator.any(:option_compute_resource_id, :option_compute_resource_name).required
271
+ end
272
+
273
+ def request_params
274
+ params = HammerCLIForeman::ComputeAttribute.get_params(options)
275
+ raise ArgumentError, "Compute profile value to update does not exist yet; it needs to be created first" if !params['compute_attribute'].key?('id')
276
+ params['id'] = params['compute_attribute']['id']
277
+ params['compute_attribute']['vm_attrs']['volumes_attributes'] ||= {}
278
+ params['compute_attribute']['vm_attrs']['volumes_attributes'][option_volume_id] = option_volume
279
+ params
280
+ end
281
+ success_message _('Volume was updated.')
282
+ failure_message _('Could not update volume')
283
+ build_options :without => :id
284
+ end
285
+
286
+ # Using the Update command because removing a volume is done by modifying existing compute_attribute
287
+ class RemoveVolume < HammerCLIForeman::UpdateCommand
288
+ command_name 'remove-volume'
289
+ resource :compute_attributes
290
+ desc _('Remove compute profile volume')
291
+ option '--volume-id', 'VOLUME_ID', _('Volume id'),
292
+ :format => HammerCLI::Options::Normalizers::Number.new, :required=> true
293
+
294
+ def validate_options
295
+ super
296
+ validator.any(:option_compute_profile_id, :option_compute_profile_name).required
297
+ validator.any(:option_compute_resource_id, :option_compute_resource_name).required
298
+ end
299
+
300
+ def request_params
301
+ params = HammerCLIForeman::ComputeAttribute.get_params(options)
302
+ raise ArgumentError, "Compute profile value to update does not exist yet; it needs to be created first" if !params['compute_attribute'].key?('id')
303
+ params['id'] = params['compute_attribute']['id']
304
+ if params['compute_attribute']['vm_attrs']['volumes_attributes'].has_key?(option_volume_id.to_s)
305
+ params['compute_attribute']['vm_attrs']['volumes_attributes'].delete(option_volume_id.to_s)
306
+ else
307
+ signal_usage_error _('unknown volume id')
308
+ end
309
+ params
310
+ end
311
+ success_message _('Volume was removed.')
312
+ failure_message _('Could not remove volume')
313
+ build_options :without => :id
314
+ end
315
+
316
+ autoload_subcommands
317
+ end
318
+ end
@@ -0,0 +1,61 @@
1
+ require 'hammer_cli_foreman/image'
2
+
3
+ module HammerCLIForeman
4
+ class ComputeProfile < HammerCLIForeman::Command
5
+ resource :compute_profiles
6
+
7
+ class ListCommand < HammerCLIForeman::ListCommand
8
+ output do
9
+ field :id, _('Id')
10
+ field :name, _('Name')
11
+ end
12
+ build_options
13
+ end
14
+
15
+ class InfoCommand < HammerCLIForeman::InfoCommand
16
+ output ListCommand.output_definition do
17
+
18
+ HammerCLIForeman::References.taxonomies(self)
19
+ HammerCLIForeman::References.timestamps(self)
20
+
21
+ collection :compute_attributes, _('Compute attributes') do
22
+ field :id, _('Id')
23
+ field :name, _('Name')
24
+ field nil, _('Compute Resource'), Fields::SingleReference, :key => :compute_resource
25
+ field :vm_attrs, _('VM attributes')
26
+ end
27
+ end
28
+ build_options
29
+ end
30
+
31
+ class CreateCommand < HammerCLIForeman::CreateCommand
32
+ success_message _('Compute profile created.')
33
+ failure_message _('Could not create a compute profile')
34
+ build_options
35
+ end
36
+
37
+ class UpdateCommand < HammerCLIForeman::UpdateCommand
38
+ success_message _('Compute profile updated.')
39
+ failure_message _('Could not update the compute profile')
40
+ validate_options do
41
+ any(:option_name,:option_id).required
42
+ end
43
+ build_options
44
+ end
45
+
46
+ class DeleteCommand < HammerCLIForeman::DeleteCommand
47
+ success_message _('Compute profile deleted.')
48
+ failure_message _('Could not delete the Compute profile')
49
+ validate_options do
50
+ any(:option_name,:option_id).required
51
+ end
52
+ build_options
53
+ end
54
+
55
+ lazy_subcommand('values', _("Create update and delete Compute profile values"),
56
+ 'HammerCLIForeman::ComputeAttribute', 'hammer_cli_foreman/compute_attribute'
57
+ )
58
+
59
+ autoload_subcommands
60
+ end
61
+ end
@@ -1,4 +1,6 @@
1
1
  require 'hammer_cli_foreman/image'
2
+ require 'hammer_cli_foreman/compute_resource/register_compute_resources'
3
+
2
4
 
3
5
  module HammerCLIForeman
4
6
 
@@ -69,34 +71,48 @@ module HammerCLIForeman
69
71
 
70
72
 
71
73
  class CreateCommand < HammerCLIForeman::CreateCommand
74
+ option "--public-key-path", "PUBLIC_KEY_PATH", _("Path to a file that contains oVirt public key (For oVirt only)"),
75
+ :format => HammerCLI::Options::Normalizers::File.new
72
76
 
73
- VALIDATION_PER_PROVIDER = {
74
- 'libvirt' => [:option_url],
75
- 'ovirt' => [:option_url, :option_user, :option_password, :option_datacenter],
76
- 'openstack' => [:option_url, :option_user, :option_password],
77
- 'racksapce' => [:option_url],
78
- 'ec2' => [:option_region, :option_user, :option_password],
79
- 'vmware' => [:option_user, :option_password, :option_datacenter, :option_server]
80
- }
81
77
 
82
78
  success_message _("Compute resource created.")
83
79
  failure_message _("Could not create the compute resource")
84
80
 
85
81
  build_options
86
82
 
87
- validate_options do
88
- required_options = (VALIDATION_PER_PROVIDER[
89
- option(:option_provider).value.to_s.downcase
90
- ] || []).unshift(:option_name, :option_provider).uniq
83
+ def request_params
84
+ params = super
85
+ params['compute_resource']['public_key'] = option_public_key_path if option_public_key_path
86
+ params
87
+ end
91
88
 
92
- all(*required_options).required
89
+ validate_options do
90
+ if option(:option_provider).value.nil? || option(:option_name).value.nil?
91
+ all(:option_name, :option_provider).required
92
+ else
93
+ provider = ::HammerCLIForeman.compute_resources[option(:option_provider).value.to_s.downcase]
94
+ if provider
95
+ required_options = provider.mandatory_resource_options.map { |attr| "option_#{attr}".to_sym }
96
+ all(*required_options).required
97
+ else
98
+ raise ArgumentError, "incorrect/invalid --provider option"
99
+ end
100
+ end
93
101
  end
94
102
  end
95
103
 
96
104
  class UpdateCommand < HammerCLIForeman::UpdateCommand
105
+ option "--public-key-path", "PUBLIC_KEY_PATH", _("Path to a file that contains oVirt public key (For oVirt only)"),
106
+ :format => HammerCLI::Options::Normalizers::File.new
107
+
97
108
  success_message _("Compute resource updated.")
98
109
  failure_message _("Could not update the compute resource")
99
110
 
111
+ def request_params
112
+ params = super
113
+ params['compute_resource']['public_key'] = option_public_key_path if option_public_key_path
114
+ params
115
+ end
100
116
  build_options :without => :name
101
117
  end
102
118