hammer_cli_foreman 0.1.4 → 0.2.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.
- checksums.yaml +4 -4
- data/config/foreman.yml +16 -0
- data/doc/host_create.md +102 -54
- data/doc/release_notes.md +20 -0
- data/lib/hammer_cli_foreman.rb +8 -0
- data/lib/hammer_cli_foreman/commands.rb +33 -9
- data/lib/hammer_cli_foreman/compute_resource.rb +13 -2
- data/lib/hammer_cli_foreman/domain.rb +24 -1
- data/lib/hammer_cli_foreman/environment.rb +1 -2
- data/lib/hammer_cli_foreman/host.rb +131 -73
- data/lib/hammer_cli_foreman/hostgroup.rb +18 -8
- data/lib/hammer_cli_foreman/i18n.rb +2 -6
- data/lib/hammer_cli_foreman/id_resolver.rb +41 -6
- data/lib/hammer_cli_foreman/interface.rb +165 -0
- data/lib/hammer_cli_foreman/output/fields.rb +7 -0
- data/lib/hammer_cli_foreman/output/formatters.rb +3 -5
- data/lib/hammer_cli_foreman/puppet_class.rb +16 -2
- data/lib/hammer_cli_foreman/settings.rb +37 -0
- data/lib/hammer_cli_foreman/smart_class_parameter.rb +75 -11
- data/lib/hammer_cli_foreman/smart_variable.rb +146 -0
- data/lib/hammer_cli_foreman/user.rb +9 -3
- data/lib/hammer_cli_foreman/version.rb +1 -1
- data/locale/Makefile +9 -17
- data/locale/de/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/de/hammer-cli-foreman.edit.po +2403 -0
- data/locale/de/hammer-cli-foreman.po +302 -355
- data/locale/de/hammer-cli-foreman.po.time_stamp +0 -0
- data/locale/en/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/en/hammer-cli-foreman.edit.po +2260 -0
- data/locale/en/hammer-cli-foreman.po +946 -823
- data/locale/en/hammer-cli-foreman.po.time_stamp +0 -0
- data/locale/en_GB/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/en_GB/hammer-cli-foreman.edit.po +2267 -0
- data/locale/en_GB/hammer-cli-foreman.po +297 -351
- data/locale/en_GB/hammer-cli-foreman.po.time_stamp +0 -0
- data/locale/es/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/es/hammer-cli-foreman.edit.po +2427 -0
- data/locale/es/hammer-cli-foreman.po +301 -354
- data/locale/es/hammer-cli-foreman.po.time_stamp +0 -0
- data/locale/fr/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/fr/hammer-cli-foreman.edit.po +2427 -0
- data/locale/fr/hammer-cli-foreman.po +299 -353
- data/locale/fr/hammer-cli-foreman.po.time_stamp +0 -0
- data/locale/hammer-cli-foreman.pot +1413 -1112
- data/locale/it/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/it/hammer-cli-foreman.edit.po +2402 -0
- data/locale/it/hammer-cli-foreman.po +299 -353
- data/locale/it/hammer-cli-foreman.po.time_stamp +0 -0
- data/locale/ja/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/ja/hammer-cli-foreman.edit.po +2401 -0
- data/locale/ja/hammer-cli-foreman.po +338 -391
- data/locale/ja/hammer-cli-foreman.po.time_stamp +0 -0
- data/locale/ko/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/ko/hammer-cli-foreman.edit.po +2401 -0
- data/locale/ko/hammer-cli-foreman.po +299 -353
- data/locale/ko/hammer-cli-foreman.po.time_stamp +0 -0
- data/locale/pt_BR/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/pt_BR/hammer-cli-foreman.edit.po +2417 -0
- data/locale/pt_BR/hammer-cli-foreman.po +312 -365
- data/locale/pt_BR/hammer-cli-foreman.po.time_stamp +0 -0
- data/locale/ru/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/ru/hammer-cli-foreman.edit.po +2401 -0
- data/locale/ru/hammer-cli-foreman.po +300 -354
- data/locale/ru/hammer-cli-foreman.po.time_stamp +0 -0
- data/locale/zh_CN/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/zh_CN/hammer-cli-foreman.edit.po +2400 -0
- data/locale/zh_CN/hammer-cli-foreman.po +299 -353
- data/locale/zh_CN/hammer-cli-foreman.po.time_stamp +0 -0
- data/locale/zh_TW/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/zh_TW/hammer-cli-foreman.edit.po +2400 -0
- data/locale/zh_TW/hammer-cli-foreman.po +299 -353
- data/locale/zh_TW/hammer-cli-foreman.po.time_stamp +0 -0
- data/test/unit/apipie_resource_mock.rb +7 -0
- data/test/unit/commands_test.rb +42 -0
- data/test/unit/data/1.7/foreman_api.json +1 -0
- data/test/unit/dependency_resolver_test.rb +4 -2
- data/test/unit/environment_test.rb +2 -2
- data/test/unit/host_test.rb +50 -27
- data/test/unit/hostgroup_test.rb +19 -3
- data/test/unit/media_test.rb +2 -2
- data/test/unit/puppet_class_test.rb +17 -2
- data/test/unit/smart_class_parameter_test.rb +26 -2
- data/test/unit/smart_variable_test.rb +134 -0
- data/test/unit/test_helper.rb +1 -1
- metadata +36 -4
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
require 'hammer_cli_foreman/fact'
|
|
1
2
|
require 'hammer_cli_foreman/report'
|
|
2
3
|
require 'hammer_cli_foreman/puppet_class'
|
|
3
4
|
require 'hammer_cli_foreman/smart_class_parameter'
|
|
5
|
+
require 'hammer_cli_foreman/smart_variable'
|
|
6
|
+
require 'hammer_cli_foreman/interface'
|
|
4
7
|
|
|
5
8
|
require 'highline/import'
|
|
6
9
|
|
|
@@ -52,7 +55,7 @@ module HammerCLIForeman
|
|
|
52
55
|
:provision_method, :capabilities, :flavour_ref, :image_ref, :start,
|
|
53
56
|
:network, :cpus, :memory, :provider, :type, :tenant_id, :image_id,
|
|
54
57
|
# ----------------------------------------------------------------------------------
|
|
55
|
-
:puppet_class_ids, :host_parameters_attributes]
|
|
58
|
+
:puppet_class_ids, :host_parameters_attributes, :interfaces_attributes]
|
|
56
59
|
end
|
|
57
60
|
|
|
58
61
|
def self.ask_password
|
|
@@ -62,29 +65,37 @@ module HammerCLIForeman
|
|
|
62
65
|
|
|
63
66
|
def request_params
|
|
64
67
|
params = super
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
params['host']['
|
|
68
|
-
|
|
68
|
+
|
|
69
|
+
owner_id = get_resource_id(HammerCLIForeman.foreman_resource(:users), :required => false, :scoped => true)
|
|
70
|
+
params['host']['owner_id'] ||= owner_id unless owner_id.nil?
|
|
71
|
+
|
|
72
|
+
puppet_proxy_id = proxy_id(option_puppet_proxy)
|
|
73
|
+
params['host']['puppet_proxy_id'] ||= puppet_proxy_id unless puppet_proxy_id.nil?
|
|
74
|
+
|
|
75
|
+
puppet_ca_proxy_id = proxy_id(option_puppet_ca_proxy)
|
|
76
|
+
params['host']['puppet_ca_proxy_id'] ||= puppet_ca_proxy_id unless puppet_ca_proxy_id.nil?
|
|
77
|
+
|
|
78
|
+
puppetclass_ids = option_puppetclass_ids || puppet_class_ids(option_puppet_classes)
|
|
79
|
+
params['host']['puppetclass_ids'] = puppetclass_ids unless puppetclass_ids.nil?
|
|
69
80
|
|
|
70
81
|
params['host']['build'] = option_build unless option_build.nil?
|
|
71
82
|
params['host']['managed'] = option_managed unless option_managed.nil?
|
|
72
83
|
params['host']['enabled'] = option_enabled unless option_enabled.nil?
|
|
84
|
+
|
|
73
85
|
params['host']['host_parameters_attributes'] = parameter_attributes
|
|
74
86
|
params['host']['compute_attributes'] = option_compute_attributes || {}
|
|
75
87
|
params['host']['compute_attributes']['volumes_attributes'] = nested_attributes(option_volume_list)
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
params['host']['interfaces_attributes'] = nested_attributes(option_interface_list)
|
|
81
|
-
end
|
|
88
|
+
params['host']['interfaces_attributes'] = interfaces_attributes
|
|
89
|
+
|
|
90
|
+
# check primary and provision interfaces, only for create
|
|
91
|
+
check_mandatory_interfaces(params['host']['interfaces_attributes']) if params['id'].nil?
|
|
82
92
|
|
|
83
93
|
params['host']['root_pass'] = option_root_password unless option_root_password.nil?
|
|
84
94
|
|
|
85
95
|
if option_ask_root_password
|
|
86
96
|
params['host']['root_pass'] = HammerCLIForeman::CommonHostUpdateOptions::ask_password
|
|
87
97
|
end
|
|
98
|
+
|
|
88
99
|
params
|
|
89
100
|
end
|
|
90
101
|
|
|
@@ -115,6 +126,30 @@ module HammerCLIForeman
|
|
|
115
126
|
nested_hash
|
|
116
127
|
end
|
|
117
128
|
|
|
129
|
+
def interfaces_attributes
|
|
130
|
+
# move each attribute starting with "compute_" to compute_attributes
|
|
131
|
+
nic_list = option_interface_list.collect do |nic|
|
|
132
|
+
compute_attributes = {}
|
|
133
|
+
nic.keys.each do |key|
|
|
134
|
+
if key.start_with? 'compute_'
|
|
135
|
+
compute_attributes[key.gsub('compute_', '')] = nic.delete(key)
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
nic['compute_attributes'] = compute_attributes unless compute_attributes.empty?
|
|
139
|
+
nic
|
|
140
|
+
end
|
|
141
|
+
nested_attributes(nic_list)
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def check_mandatory_interfaces(nics)
|
|
145
|
+
unless nics.any? { |key, nic| nic['primary'] == 'true' }
|
|
146
|
+
signal_usage_error _('At least one interface must be set as primary')
|
|
147
|
+
end
|
|
148
|
+
unless nics.any? { |key, nic| nic['provision'] == 'true' }
|
|
149
|
+
signal_usage_error _('At least one interface must be set as provision')
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
118
153
|
end
|
|
119
154
|
|
|
120
155
|
|
|
@@ -140,15 +175,18 @@ module HammerCLIForeman
|
|
|
140
175
|
class InfoCommand < HammerCLIForeman::InfoCommand
|
|
141
176
|
|
|
142
177
|
def extend_data(host)
|
|
178
|
+
host['compute_resource_name'] ||= _('Bare Metal')
|
|
179
|
+
host['image_file'] = nil if host['image_file'].empty?
|
|
180
|
+
host['interfaces'] = host['interfaces'].map do |nic|
|
|
181
|
+
nic['_type'] = HammerCLIForeman::Interface.format_type(nic)
|
|
182
|
+
nic
|
|
183
|
+
end if host['interfaces']
|
|
184
|
+
|
|
143
185
|
# FIXME: temporary fetching parameters until the api gets fixed.
|
|
144
186
|
# Noramlly they should come in the host's json.
|
|
145
187
|
# http://projects.theforeman.org/issues/5820
|
|
146
|
-
host[
|
|
188
|
+
host['parameters'] = get_parameters(host["id"])
|
|
147
189
|
|
|
148
|
-
host["_bmc_interfaces"] =
|
|
149
|
-
host["interfaces"].select{|intfs| intfs["type"] == "Nic::BMC" } rescue []
|
|
150
|
-
host["_managed_interfaces"] =
|
|
151
|
-
host["interfaces"].select{|intfs| intfs["type"] == "Nic::Managed" } rescue []
|
|
152
190
|
host
|
|
153
191
|
end
|
|
154
192
|
|
|
@@ -157,70 +195,73 @@ module HammerCLIForeman
|
|
|
157
195
|
HammerCLIForeman.collection_to_common_format(params)
|
|
158
196
|
end
|
|
159
197
|
|
|
160
|
-
output ListCommand.output_definition do
|
|
161
|
-
field :uuid, _("UUID")
|
|
162
|
-
field :certname, _("Cert name")
|
|
163
198
|
|
|
199
|
+
output do
|
|
200
|
+
field :id, _("Id")
|
|
201
|
+
field :uuid, _("UUID"), Fields::Field, :hide_blank => true
|
|
202
|
+
field :name, _("Name")
|
|
203
|
+
field nil, _("Organization"), Fields::SingleReference, :key => :organization, :hide_blank => true
|
|
204
|
+
field nil, _("Location"), Fields::SingleReference, :key => :location, :hide_blank => true
|
|
205
|
+
field nil, _("Host Group"), Fields::SingleReference, :key => :hostgroup
|
|
206
|
+
field nil, _("Compute Resource"), Fields::SingleReference, :key => :compute_resource
|
|
207
|
+
field nil, _("Compute Profile"), Fields::SingleReference, :key => :compute_profile, :hide_blank => true
|
|
164
208
|
field nil, _("Environment"), Fields::SingleReference, :key => :environment
|
|
165
|
-
|
|
166
|
-
field :
|
|
167
|
-
field :
|
|
168
|
-
field :
|
|
169
|
-
|
|
170
|
-
field :use_image, _("Use image")
|
|
171
|
-
field :disk, _("Disk")
|
|
172
|
-
field :image_file, _("Image file")
|
|
173
|
-
|
|
174
|
-
field :sp_name, _("SP Name")
|
|
175
|
-
field :sp_ip, _("SP IP")
|
|
176
|
-
field :sp_mac, _("SP MAC")
|
|
177
|
-
|
|
178
|
-
field nil, _("SP Subnet"), Fields::SingleReference, :key => :sp_subnet
|
|
209
|
+
field :puppet_ca_proxy_id, _("Puppet CA Id")
|
|
210
|
+
field :puppet_proxy_id, _("Puppet Master Id")
|
|
211
|
+
field :certname, _("Cert name")
|
|
212
|
+
field :managed, _("Managed"), Fields::Boolean
|
|
179
213
|
|
|
180
214
|
field :installed_at, _("Installed at"), Fields::Date
|
|
181
215
|
field :last_report, _("Last report"), Fields::Date
|
|
182
216
|
|
|
183
|
-
|
|
184
|
-
field nil, _("Medium"), Fields::SingleReference, :key => :medium
|
|
185
|
-
field nil, _("Model"), Fields::SingleReference, :key => :model
|
|
186
|
-
field :owner_id, _("Owner Id")
|
|
187
|
-
field nil, _("Subnet"), Fields::SingleReference, :key => :subnet
|
|
188
|
-
field nil, _("Domain"), Fields::SingleReference, :key => :domain
|
|
189
|
-
field :puppet_proxy_id, _("Puppet Proxy Id")
|
|
190
|
-
field :owner_type, _("Owner Type")
|
|
191
|
-
field nil, _("Partition Table"), Fields::SingleReference, :key => :ptable
|
|
192
|
-
field nil, _("Architecture"), Fields::SingleReference, :key => :architecture
|
|
193
|
-
field nil, _("Image"), Fields::SingleReference, :key => :image
|
|
194
|
-
field nil, _("Compute Resource"), Fields::SingleReference, :key => :compute_resource
|
|
195
|
-
|
|
196
|
-
field :comment, _("Comment")
|
|
197
|
-
|
|
198
|
-
collection :_bmc_interfaces, _("BMC Network Interfaces"), :hide_blank => true do
|
|
199
|
-
field :id, _("Id")
|
|
200
|
-
field :name, _("Name")
|
|
217
|
+
label _("Network") do
|
|
201
218
|
field :ip, _("IP")
|
|
202
219
|
field :mac, _("MAC")
|
|
203
|
-
field
|
|
204
|
-
field
|
|
205
|
-
field
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
220
|
+
field nil, _("Subnet"), Fields::SingleReference, :key => :subnet
|
|
221
|
+
field nil, _("Domain"), Fields::SingleReference, :key => :domain
|
|
222
|
+
field nil, _("Service provider"), Fields::Label, :hide_blank => true do
|
|
223
|
+
field :sp_name, _("SP Name"), Fields::Field, :hide_blank => true
|
|
224
|
+
field :sp_ip, _("SP IP"), Fields::Field, :hide_blank => true
|
|
225
|
+
field :sp_mac, _("SP MAC"), Fields::Field, :hide_blank => true
|
|
226
|
+
field nil, _("SP Subnet"), Fields::SingleReference, :key => :sp_subnet, :hide_blank => true
|
|
227
|
+
end
|
|
209
228
|
end
|
|
210
229
|
|
|
211
|
-
collection :
|
|
212
|
-
field :id, _(
|
|
213
|
-
field :
|
|
214
|
-
field :
|
|
215
|
-
field :mac, _(
|
|
216
|
-
field :
|
|
217
|
-
field :
|
|
218
|
-
|
|
219
|
-
|
|
230
|
+
collection :interfaces, _("Network interfaces") do
|
|
231
|
+
field :id, _('Id')
|
|
232
|
+
field :identifier, _('Identifier')
|
|
233
|
+
field :_type, _('Type')
|
|
234
|
+
field :mac, _('MAC address')
|
|
235
|
+
field :ip, _('IP address')
|
|
236
|
+
field :fqdn, _('FQDN')
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
label _("Operating system") do
|
|
240
|
+
field nil, _("Architecture"), Fields::SingleReference, :key => :architecture
|
|
241
|
+
field nil, _("Operating System"), Fields::SingleReference, :key => :operatingsystem
|
|
242
|
+
# provision_method
|
|
243
|
+
# for network based
|
|
244
|
+
field :build, _("Build"), Fields::Boolean
|
|
245
|
+
field nil, _("Medium"), Fields::SingleReference, :key => :medium
|
|
246
|
+
field nil, _("Partition Table"), Fields::SingleReference, :key => :ptable
|
|
247
|
+
field :disk, _("Custom partition table"), Fields::LongText
|
|
248
|
+
# image
|
|
249
|
+
# for image based
|
|
250
|
+
field nil, _("Image"), Fields::SingleReference, :key => :image, :hide_blank => true
|
|
251
|
+
field :image_file, _("Image file"), Fields::Field, :hide_blank => true
|
|
252
|
+
field :use_image, _("Use image"), Fields::Boolean, :hide_blank => true
|
|
220
253
|
end
|
|
221
254
|
|
|
222
255
|
HammerCLIForeman::References.parameters(self)
|
|
223
|
-
|
|
256
|
+
|
|
257
|
+
# additional info
|
|
258
|
+
label _("Additional info") do
|
|
259
|
+
field :owner_id, _("Owner Id")
|
|
260
|
+
field :owner_type, _("Owner Type")
|
|
261
|
+
field :enabled, _("Enabled"), Fields::Boolean
|
|
262
|
+
field nil, _("Model"), Fields::SingleReference, :key => :model, :hide_blank => true
|
|
263
|
+
field :comment, _("Comment"), Fields::LongText
|
|
264
|
+
end
|
|
224
265
|
end
|
|
225
266
|
|
|
226
267
|
build_options
|
|
@@ -294,10 +335,9 @@ module HammerCLIForeman
|
|
|
294
335
|
end
|
|
295
336
|
|
|
296
337
|
|
|
297
|
-
class PuppetClassesCommand < HammerCLIForeman::
|
|
338
|
+
class PuppetClassesCommand < HammerCLIForeman::ListCommand
|
|
298
339
|
command_name "puppet-classes"
|
|
299
|
-
resource :puppetclasses
|
|
300
|
-
parent_resource :hosts
|
|
340
|
+
resource :puppetclasses
|
|
301
341
|
|
|
302
342
|
output HammerCLIForeman::PuppetClass::ListCommand.output_definition
|
|
303
343
|
|
|
@@ -305,7 +345,10 @@ module HammerCLIForeman
|
|
|
305
345
|
HammerCLIForeman::PuppetClass::ListCommand.unhash_classes(super)
|
|
306
346
|
end
|
|
307
347
|
|
|
308
|
-
build_options
|
|
348
|
+
build_options do |o|
|
|
349
|
+
o.without(:hostgroup_id, :environment_id)
|
|
350
|
+
o.expand.only(:hosts)
|
|
351
|
+
end
|
|
309
352
|
end
|
|
310
353
|
|
|
311
354
|
|
|
@@ -462,11 +505,26 @@ module HammerCLIForeman
|
|
|
462
505
|
end
|
|
463
506
|
|
|
464
507
|
class SCParamsCommand < HammerCLIForeman::SmartClassParametersList
|
|
465
|
-
|
|
466
|
-
|
|
508
|
+
build_options_for :hosts
|
|
509
|
+
|
|
510
|
+
def validate_options
|
|
511
|
+
super
|
|
512
|
+
validator.any(:option_host_name, :option_host_id).required
|
|
513
|
+
end
|
|
514
|
+
end
|
|
515
|
+
|
|
516
|
+
class SmartVariablesCommand < HammerCLIForeman::SmartVariablesList
|
|
517
|
+
build_options_for :hosts
|
|
518
|
+
|
|
519
|
+
def validate_options
|
|
520
|
+
super
|
|
521
|
+
validator.any(:option_host_name, :option_host_id).required
|
|
522
|
+
end
|
|
467
523
|
end
|
|
468
524
|
|
|
469
525
|
autoload_subcommands
|
|
526
|
+
|
|
527
|
+
subcommand 'interface', HammerCLIForeman::Interface.desc, HammerCLIForeman::Interface
|
|
470
528
|
end
|
|
471
529
|
|
|
472
530
|
end
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'hammer_cli_foreman/smart_class_parameter'
|
|
2
|
+
require 'hammer_cli_foreman/smart_variable'
|
|
2
3
|
require 'hammer_cli_foreman/puppet_class'
|
|
3
4
|
|
|
4
5
|
module HammerCLIForeman
|
|
@@ -115,13 +116,10 @@ module HammerCLIForeman
|
|
|
115
116
|
HammerCLIForeman::PuppetClass::ListCommand.unhash_classes(super)
|
|
116
117
|
end
|
|
117
118
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
params
|
|
119
|
+
build_options do |o|
|
|
120
|
+
o.without(:host_id, :environment_id)
|
|
121
|
+
o.expand.only(:hostgroups)
|
|
122
122
|
end
|
|
123
|
-
|
|
124
|
-
build_options
|
|
125
123
|
end
|
|
126
124
|
|
|
127
125
|
|
|
@@ -145,10 +143,22 @@ module HammerCLIForeman
|
|
|
145
143
|
end
|
|
146
144
|
|
|
147
145
|
class SCParamsCommand < HammerCLIForeman::SmartClassParametersList
|
|
148
|
-
|
|
149
|
-
|
|
146
|
+
build_options_for :hostgroups
|
|
147
|
+
|
|
148
|
+
def validate_options
|
|
149
|
+
super
|
|
150
|
+
validator.any(:option_hostgroup_name, :option_hostgroup_id).required
|
|
151
|
+
end
|
|
150
152
|
end
|
|
151
153
|
|
|
154
|
+
class SmartVariablesCommand < HammerCLIForeman::SmartVariablesList
|
|
155
|
+
build_options_for :hostgroups
|
|
156
|
+
|
|
157
|
+
def validate_options
|
|
158
|
+
super
|
|
159
|
+
validator.any(:option_hostgroup_name, :option_hostgroup_id).required
|
|
160
|
+
end
|
|
161
|
+
end
|
|
152
162
|
|
|
153
163
|
autoload_subcommands
|
|
154
164
|
end
|
|
@@ -24,14 +24,10 @@ module HammerCLIForeman
|
|
|
24
24
|
'/usr/share/locale'
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
-
def domain_name
|
|
28
|
-
"#{super}@system"
|
|
29
|
-
end
|
|
30
|
-
|
|
31
27
|
end
|
|
32
28
|
|
|
33
29
|
end
|
|
34
30
|
end
|
|
35
31
|
|
|
36
|
-
|
|
37
|
-
HammerCLI::I18n.add_domain(
|
|
32
|
+
domain = [HammerCLIForeman::I18n::LocaleDomain.new, HammerCLIForeman::I18n::SystemLocaleDomain.new].find { |d| d.available? }
|
|
33
|
+
HammerCLI::I18n.add_domain(domain) if domain
|
|
@@ -40,23 +40,27 @@ module HammerCLIForeman
|
|
|
40
40
|
:fact_value => [],
|
|
41
41
|
:filter => [],
|
|
42
42
|
:host => [ s_name(_("Host name")) ],
|
|
43
|
-
:hostgroup => [ s_name(_("Hostgroup name")) ],
|
|
43
|
+
:hostgroup => [ s_name(_("Hostgroup name")), s("title", _("Hostgroup title"),:editable => false) ],
|
|
44
44
|
# :image => [],
|
|
45
|
+
:interface => [],
|
|
45
46
|
:location => [ s_name(_("Location name")) ],
|
|
46
47
|
:medium => [ s_name(_("Medium name")) ],
|
|
47
48
|
:model => [ s_name(_("Model name")) ],
|
|
48
49
|
:organization => [ s_name(_("Organization name")) ],
|
|
49
50
|
:operatingsystem => [ s("title", _("Operating system title"), :editable => false) ],
|
|
51
|
+
:override_value => [],
|
|
50
52
|
:ptable => [ s_name(_("Partition table name")) ],
|
|
51
53
|
:proxy => [ s_name(_("Proxy name")) ],
|
|
52
54
|
:puppetclass => [ s_name(_("Puppet class name")) ],
|
|
53
55
|
:report => [ s_name(_("Report name")) ],
|
|
54
56
|
:role => [ s_name(_("User role name")) ],
|
|
57
|
+
:setting => [ s_name(_("Setting name"), :editable => false) ],
|
|
55
58
|
:subnet => [ s_name(_("Subnet name")) ],
|
|
56
59
|
:template => [],
|
|
57
60
|
:user => [ s("login", _("User's login to search by")) ],
|
|
58
61
|
:common_parameter => [ s_name(_("Common parameter name")) ],
|
|
59
|
-
:smart_class_parameter => [ s_name(_("Smart class parameter name")) ]
|
|
62
|
+
:smart_class_parameter => [ s_name(_("Smart class parameter name")) ],
|
|
63
|
+
:smart_variable => [ s_name(_("Smart variable name")) ]
|
|
60
64
|
}
|
|
61
65
|
DEFAULT_SEARCHABLES = [ s_name(_("Name to search by")) ]
|
|
62
66
|
|
|
@@ -127,11 +131,11 @@ module HammerCLIForeman
|
|
|
127
131
|
|
|
128
132
|
self.class.send(:define_method, method_name) do |options|
|
|
129
133
|
get_id(resource.name, options)
|
|
130
|
-
end unless respond_to?(method_name)
|
|
134
|
+
end unless respond_to?(method_name, true)
|
|
131
135
|
|
|
132
136
|
self.class.send(:define_method, plural_method_name) do |options|
|
|
133
137
|
get_ids(resource.name, options)
|
|
134
|
-
end unless respond_to?(plural_method_name)
|
|
138
|
+
end unless respond_to?(plural_method_name, true)
|
|
135
139
|
end
|
|
136
140
|
end
|
|
137
141
|
|
|
@@ -151,11 +155,16 @@ module HammerCLIForeman
|
|
|
151
155
|
end
|
|
152
156
|
|
|
153
157
|
def find_resource(resource_name, options)
|
|
158
|
+
results = find_resource_raw(resource_name, options)
|
|
154
159
|
resource = @api.resource(resource_name)
|
|
155
|
-
results = resolved_call(resource_name, :index, options)
|
|
156
160
|
pick_result(results, resource)
|
|
157
161
|
end
|
|
158
162
|
|
|
163
|
+
def find_resource_raw(resource_name, options)
|
|
164
|
+
resolved_call(resource_name, :index, options)
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
|
|
159
168
|
def resolved_call(resource_name, action_name, options)
|
|
160
169
|
resource = @api.resource(resource_name)
|
|
161
170
|
action = resource.action(action_name)
|
|
@@ -195,7 +204,7 @@ module HammerCLIForeman
|
|
|
195
204
|
|
|
196
205
|
def search_options(options, resource)
|
|
197
206
|
method = "create_#{resource.name}_search_options"
|
|
198
|
-
search_options = if respond_to?(method)
|
|
207
|
+
search_options = if respond_to?(method, true)
|
|
199
208
|
send(method, options)
|
|
200
209
|
else
|
|
201
210
|
create_search_options(options, resource)
|
|
@@ -221,6 +230,32 @@ module HammerCLIForeman
|
|
|
221
230
|
0
|
|
222
231
|
end
|
|
223
232
|
|
|
233
|
+
# puppet class search results are in non-standard format
|
|
234
|
+
# and needs to be un-hashed first
|
|
235
|
+
def puppetclass_id(options)
|
|
236
|
+
return options[HammerCLI.option_accessor_name("id")] if options[HammerCLI.option_accessor_name("id")]
|
|
237
|
+
resource = @api.resource(:puppetclasses)
|
|
238
|
+
results = find_resource_raw(:puppetclasses, options)
|
|
239
|
+
require('hammer_cli_foreman/puppet_class')
|
|
240
|
+
results = HammerCLIForeman::PuppetClass::ListCommand.unhash_classes(results)
|
|
241
|
+
pick_result(results, resource)['id']
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
def create_smart_class_parameters_search_options(options)
|
|
245
|
+
search_options = {}
|
|
246
|
+
value = options[HammerCLI.option_accessor_name('name')]
|
|
247
|
+
search_options[:search] = "key = \"#{value}\""
|
|
248
|
+
search_options[:puppetclass_id] = puppetclass_id(scoped_options("puppetclass", options))
|
|
249
|
+
search_options
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
def create_smart_variables_search_options(options)
|
|
253
|
+
search_options = {}
|
|
254
|
+
value = options[HammerCLI.option_accessor_name('name')]
|
|
255
|
+
search_options[:search] = "key = \"#{value}\""
|
|
256
|
+
search_options
|
|
257
|
+
end
|
|
258
|
+
|
|
224
259
|
def create_search_options(options, resource)
|
|
225
260
|
searchables(resource).each do |s|
|
|
226
261
|
value = options[HammerCLI.option_accessor_name(s.name.to_s)]
|