hammer_cli_foreman 2.3.2 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/doc/release_notes.md +33 -3
- data/lib/hammer_cli_foreman.rb +3 -21
- data/lib/hammer_cli_foreman/associating_commands.rb +0 -24
- data/lib/hammer_cli_foreman/bookmark.rb +1 -1
- data/lib/hammer_cli_foreman/combination.rb +3 -13
- data/lib/hammer_cli_foreman/command_extensions.rb +1 -2
- data/lib/hammer_cli_foreman/command_extensions/ping.rb +21 -2
- data/lib/hammer_cli_foreman/command_extensions/status.rb +1 -1
- data/lib/hammer_cli_foreman/command_extensions/update_common.rb +14 -0
- data/lib/hammer_cli_foreman/commands.rb +16 -9
- data/lib/hammer_cli_foreman/compute_resource.rb +22 -0
- data/lib/hammer_cli_foreman/compute_resource/ovirt.rb +2 -1
- data/lib/hammer_cli_foreman/config_report.rb +2 -0
- data/lib/hammer_cli_foreman/filter.rb +2 -2
- data/lib/hammer_cli_foreman/host.rb +1 -47
- data/lib/hammer_cli_foreman/hostgroup.rb +2 -53
- data/lib/hammer_cli_foreman/hosts/common_update_options.rb +7 -28
- data/lib/hammer_cli_foreman/id_resolver.rb +0 -61
- data/lib/hammer_cli_foreman/location.rb +0 -6
- data/lib/hammer_cli_foreman/operating_system.rb +2 -1
- data/lib/hammer_cli_foreman/option_builders.rb +6 -5
- data/lib/hammer_cli_foreman/option_sources.rb +0 -1
- data/lib/hammer_cli_foreman/option_sources/id_params.rb +27 -10
- data/lib/hammer_cli_foreman/option_sources/ids_params.rb +25 -6
- data/lib/hammer_cli_foreman/organization.rb +0 -6
- data/lib/hammer_cli_foreman/ping.rb +6 -1
- data/lib/hammer_cli_foreman/references.rb +0 -16
- data/lib/hammer_cli_foreman/registration.rb +18 -0
- data/lib/hammer_cli_foreman/smart_proxy.rb +0 -52
- data/lib/hammer_cli_foreman/version.rb +1 -1
- data/lib/minitest/coverage_reporter.rb +1 -1
- data/locale/ca/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/de/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/en/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/en_GB/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/es/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/fr/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/it/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/ja/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/ko/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/pt_BR/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/ru/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/zh_CN/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/zh_TW/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/test/data/2.4/foreman_api.json +1 -0
- data/test/data/2.5/foreman_api.json +1 -0
- data/test/functional/architecture_test.rb +81 -0
- data/test/functional/bookmark_test.rb +24 -1
- data/test/functional/compute_profile_test.rb +56 -0
- data/test/functional/compute_resource_test.rb +37 -0
- data/test/functional/filter_test.rb +115 -47
- data/test/functional/host_test.rb +94 -13
- data/test/functional/hostgroup/create_test.rb +0 -117
- data/test/functional/hostgroup/update_test.rb +0 -79
- data/test/functional/http_proxy_test.rb +12 -0
- data/test/functional/location_test.rb +13 -3
- data/test/functional/mail_notification_test.rb +22 -0
- data/test/functional/media_test.rb +11 -0
- data/test/functional/model_test.rb +52 -0
- data/test/functional/operating_system_test.rb +53 -0
- data/test/functional/ping_test.rb +33 -0
- data/test/functional/realm_test.rb +11 -0
- data/test/functional/registration_test.rb +8 -0
- data/test/functional/report_template_test.rb +11 -0
- data/test/functional/settings_test.rb +21 -0
- data/test/functional/status_test.rb +79 -13
- data/test/functional/template_test.rb +16 -37
- data/test/functional/user_test.rb +11 -0
- data/test/functional/usergroup_test.rb +53 -0
- data/test/test_helper.rb +1 -1
- data/test/unit/apipie_resource_mock.rb +22 -39
- data/test/unit/architecture_test.rb +10 -1
- data/test/unit/bookmark_test.rb +95 -0
- data/test/unit/compute_profile_test.rb +87 -0
- data/test/unit/config_report_test.rb +1 -0
- data/test/unit/helpers/command.rb +0 -8
- data/test/unit/host_test.rb +14 -61
- data/test/unit/hostgroup_test.rb +7 -26
- data/test/unit/id_resolver_test.rb +0 -28
- data/test/unit/mail_notification_test.rb +53 -0
- data/test/unit/model_test.rb +47 -37
- data/test/unit/operating_system_test.rb +10 -3
- data/test/unit/option_sources/id_params_test.rb +9 -0
- data/test/unit/option_sources/ids_params_test.rb +9 -0
- data/test/unit/settings_test.rb +4 -0
- data/test/unit/smart_proxy_test.rb +0 -12
- data/test/unit/usergroup_test.rb +10 -0
- metadata +76 -73
- data/lib/hammer_cli_foreman/command_extensions/puppet_environment.rb +0 -29
- data/lib/hammer_cli_foreman/command_extensions/puppet_environments.rb +0 -29
- data/lib/hammer_cli_foreman/config_group.rb +0 -45
- data/lib/hammer_cli_foreman/option_sources/puppet_environment_params.rb +0 -59
- data/lib/hammer_cli_foreman/puppet_class.rb +0 -61
- data/lib/hammer_cli_foreman/puppet_environment.rb +0 -65
- data/lib/hammer_cli_foreman/smart_class_parameter.rb +0 -189
- data/test/functional/proxy_test.rb +0 -86
- data/test/functional/smart_class_parameter_test.rb +0 -97
- data/test/unit/config_group_test.rb +0 -72
- data/test/unit/puppet_class_test.rb +0 -72
- data/test/unit/puppet_environment_test.rb +0 -114
- data/test/unit/smart_class_parameter_test.rb +0 -113
@@ -1,25 +1,12 @@
|
|
1
|
-
require 'hammer_cli_foreman/smart_class_parameter'
|
2
|
-
require 'hammer_cli_foreman/puppet_class'
|
3
|
-
|
4
1
|
module HammerCLIForeman
|
5
2
|
|
6
3
|
module HostgroupUpdateCreateCommons
|
7
4
|
|
8
5
|
def self.included(base)
|
9
|
-
base.option "--puppet-class-ids", "PUPPETCLASS_IDS", _("List of puppetclass ids"),
|
10
|
-
:format => HammerCLI::Options::Normalizers::List.new,
|
11
|
-
:attribute_name => :option_puppetclass_ids
|
12
|
-
base.option "--puppet-classes", "PUPPET_CLASS_NAMES", "",
|
13
|
-
:format => HammerCLI::Options::Normalizers::List.new,
|
14
|
-
:attribute_name => :option_puppetclass_names
|
15
|
-
base.option "--puppet-ca-proxy", "PUPPET_CA_PROXY_NAME", _("Name of puppet CA proxy")
|
16
|
-
base.option "--puppet-proxy", "PUPPET_PROXY_NAME", _("Name of puppet proxy")
|
17
6
|
base.option "--parent", "PARENT_NAME", _("Name of parent hostgroup")
|
18
|
-
base.option ["--root-password"
|
19
|
-
deprecated: { '--root-pass' => _("Use --root-password instead") }
|
7
|
+
base.option ["--root-password"], "ROOT_PASSWORD", _("Root password")
|
20
8
|
base.option ["--ask-root-password", "--ask-root-pass"], "ASK_ROOT_PW", "",
|
21
|
-
format: HammerCLI::Options::Normalizers::Bool.new
|
22
|
-
deprecated: { '--ask-root-pass' => _("Use --ask-root-password instead") }
|
9
|
+
format: HammerCLI::Options::Normalizers::Bool.new
|
23
10
|
base.option "--subnet6", "SUBNET6_NAME", _("Subnet IPv6 name")
|
24
11
|
|
25
12
|
base.build_options without: %i[root_pass]
|
@@ -33,8 +20,6 @@ module HammerCLIForeman
|
|
33
20
|
def request_params
|
34
21
|
params = super
|
35
22
|
params['hostgroup']["parent_id"] ||= resolver.hostgroup_id('option_name' => option_parent) if option_parent
|
36
|
-
params['hostgroup']["puppet_proxy_id"] ||= proxy_id(option_puppet_proxy) if option_puppet_proxy
|
37
|
-
params['hostgroup']["puppet_ca_proxy_id"] ||= proxy_id(option_puppet_ca_proxy) if option_puppet_ca_proxy
|
38
23
|
|
39
24
|
params['hostgroup']['root_pass'] = option_root_password if option_root_password
|
40
25
|
params['hostgroup']['root_pass'] = HammerCLIForeman::HostgroupUpdateCreateCommons::ask_password if option_ask_root_password
|
@@ -61,7 +46,6 @@ module HammerCLIForeman
|
|
61
46
|
field :name, _("Name")
|
62
47
|
field :title, _("Title")
|
63
48
|
field nil, _("Operating System"), Fields::SingleReference, :key => :operatingsystem
|
64
|
-
field nil, _("Puppet Environment"), Fields::SingleReference, :key => :environment
|
65
49
|
field nil, _("Model"), Fields::SingleReference, :key => :model
|
66
50
|
end
|
67
51
|
|
@@ -75,13 +59,10 @@ module HammerCLIForeman
|
|
75
59
|
field :id, _("Id")
|
76
60
|
field :name, _("Name")
|
77
61
|
field :title, _("Title")
|
78
|
-
field nil, _("Puppet Environment"), Fields::SingleReference, :key => :environment
|
79
62
|
field nil, _("Model"), Fields::SingleReference, :key => :model
|
80
63
|
|
81
64
|
field :description, _("Description"), Fields::LongText, :hide_blank => true
|
82
65
|
field nil, _("Parent"), Fields::SingleReference, :key => :parent, :hide_blank => true
|
83
|
-
field nil, _("Puppet CA Proxy"), Fields::SingleReference, :key => :puppet_ca_proxy
|
84
|
-
field nil, _("Puppet Master Proxy"), Fields::SingleReference, :key => :puppet_proxy
|
85
66
|
field nil, _("Compute Profile"), Fields::SingleReference, :key => :compute_profile
|
86
67
|
field nil, _("Compute Resource"), Fields::SingleReference, :key => :compute_resource
|
87
68
|
label _('Network') do
|
@@ -97,7 +78,6 @@ module HammerCLIForeman
|
|
97
78
|
field nil, _("Partition Table"), Fields::SingleReference, :key => :ptable
|
98
79
|
field :pxe_loader, _("PXE Loader"), Fields::Field, :hide_blank => true
|
99
80
|
end
|
100
|
-
HammerCLIForeman::References.puppetclasses(self)
|
101
81
|
HammerCLIForeman::References.parameters(self)
|
102
82
|
HammerCLIForeman::References.taxonomies(self)
|
103
83
|
end
|
@@ -111,8 +91,6 @@ module HammerCLIForeman
|
|
111
91
|
|
112
92
|
success_message _("Hostgroup created.")
|
113
93
|
failure_message _("Could not create the hostgroup")
|
114
|
-
|
115
|
-
extend_with(HammerCLIForeman::CommandExtensions::PuppetEnvironment.new)
|
116
94
|
end
|
117
95
|
|
118
96
|
|
@@ -121,8 +99,6 @@ module HammerCLIForeman
|
|
121
99
|
|
122
100
|
success_message _("Hostgroup updated.")
|
123
101
|
failure_message _("Could not update the hostgroup")
|
124
|
-
|
125
|
-
extend_with(HammerCLIForeman::CommandExtensions::PuppetEnvironment.new)
|
126
102
|
end
|
127
103
|
|
128
104
|
|
@@ -133,24 +109,6 @@ module HammerCLIForeman
|
|
133
109
|
build_options
|
134
110
|
end
|
135
111
|
|
136
|
-
|
137
|
-
class PuppetClassesCommand < HammerCLIForeman::ListCommand
|
138
|
-
command_name "puppet-classes"
|
139
|
-
resource :puppetclasses
|
140
|
-
|
141
|
-
output HammerCLIForeman::PuppetClass::ListCommand.output_definition
|
142
|
-
|
143
|
-
def send_request
|
144
|
-
HammerCLIForeman::PuppetClass::ListCommand.unhash_classes(super)
|
145
|
-
end
|
146
|
-
|
147
|
-
build_options do |o|
|
148
|
-
o.without(:host_id, :environment_id)
|
149
|
-
o.expand.only(:hostgroups)
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
|
154
112
|
class SetParameterCommand < HammerCLIForeman::Parameter::SetCommand
|
155
113
|
desc _("Create or update parameter for a hostgroup")
|
156
114
|
|
@@ -170,15 +128,6 @@ module HammerCLIForeman
|
|
170
128
|
build_options
|
171
129
|
end
|
172
130
|
|
173
|
-
class SCParamsCommand < HammerCLIForeman::SmartClassParametersList
|
174
|
-
build_options_for :hostgroups
|
175
|
-
|
176
|
-
def validate_options
|
177
|
-
super
|
178
|
-
validator.any(:option_hostgroup_name, :option_hostgroup_id).required
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
131
|
class RebuildConfigCommand < HammerCLIForeman::SingleResourceCommand
|
183
132
|
action :rebuild_config
|
184
133
|
command_name "rebuild-config"
|
@@ -6,7 +6,7 @@ module HammerCLIForeman
|
|
6
6
|
base.option "--owner", "OWNER_LOGIN", _("Login of the owner"),
|
7
7
|
:attribute_name => :option_user_login
|
8
8
|
base.option "--owner-id", "OWNER_ID", _("ID of the owner"),
|
9
|
-
:attribute_name => :
|
9
|
+
:attribute_name => :option_owner_id
|
10
10
|
|
11
11
|
base.option "--root-password", "ROOT_PW",
|
12
12
|
_("Required if host is managed and value is not inherited from host group or default password in settings")
|
@@ -14,22 +14,6 @@ module HammerCLIForeman
|
|
14
14
|
base.option "--ask-root-password", "ASK_ROOT_PW", " ",
|
15
15
|
:format => HammerCLI::Options::Normalizers::Bool.new
|
16
16
|
|
17
|
-
base.option '--puppet-proxy', 'PUPPET_PROXY_NAME', '',
|
18
|
-
referenced_resource: 'puppet_proxy',
|
19
|
-
aliased_resource: 'puppet_proxy'
|
20
|
-
base.option '--puppet-ca-proxy', 'PUPPET_CA_PROXY_NAME', '',
|
21
|
-
referenced_resource: 'puppet_ca_proxy',
|
22
|
-
aliased_resource: 'puppet_ca_proxy'
|
23
|
-
base.option_family(
|
24
|
-
format: HammerCLI::Options::Normalizers::List.new,
|
25
|
-
aliased_resource: 'puppet-class',
|
26
|
-
description: 'Names/Ids of associated puppet classes'
|
27
|
-
) do
|
28
|
-
parent '--puppet-class-ids', 'PUPPET_CLASS_IDS', '',
|
29
|
-
attribute_name: :option_puppetclass_ids
|
30
|
-
child '--puppet-classes', 'PUPPET_CLASS_NAMES', '',
|
31
|
-
attribute_name: :option_puppetclass_names
|
32
|
-
end
|
33
17
|
bme_options = {}
|
34
18
|
bme_options[:default] = 'true' if base.action.to_sym == :create
|
35
19
|
|
@@ -56,7 +40,7 @@ module HammerCLIForeman
|
|
56
40
|
:capabilities, :flavour_ref, :image_ref, :start,
|
57
41
|
:network, :cpus, :memory, :provider, :type, :tenant_id, :image_id,
|
58
42
|
# ----------------------------------------------------------------------------------
|
59
|
-
:
|
43
|
+
:host_parameters_attributes, :interfaces_attributes, :root_pass]
|
60
44
|
end
|
61
45
|
|
62
46
|
def self.ask_password
|
@@ -69,12 +53,6 @@ module HammerCLIForeman
|
|
69
53
|
owner_id = owner_id(option_user_login, params['host']['owner_type'])
|
70
54
|
params['host']['owner_id'] ||= owner_id unless owner_id.nil?
|
71
55
|
|
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
56
|
if action == :create
|
79
57
|
params['host']['build'] = true if option_build.nil?
|
80
58
|
params['host']['managed'] = true if option_managed.nil?
|
@@ -134,13 +112,14 @@ module HammerCLIForeman
|
|
134
112
|
|
135
113
|
private
|
136
114
|
|
137
|
-
|
115
|
+
|
116
|
+
def owner_id(name, type)
|
138
117
|
return unless name
|
139
|
-
return resolver.
|
118
|
+
return resolver.usergroup_id('option_name' => name) if type == 'Usergroup'
|
140
119
|
|
141
|
-
resolver.
|
120
|
+
resolver.user_id('option_login' => name)
|
142
121
|
end
|
143
|
-
|
122
|
+
|
144
123
|
def proxy_id(name)
|
145
124
|
resolver.smart_proxy_id('option_name' => name) if name
|
146
125
|
end
|
@@ -42,8 +42,6 @@ module HammerCLIForeman
|
|
42
42
|
:compute_resource => [ s_name(_("Compute resource name")) ],
|
43
43
|
:compute_profile => [ s_name(_("Compute profile name")) ],
|
44
44
|
:domain => [ s_name(_("Domain name")) ],
|
45
|
-
:environment => [s_name(_('Puppet environment name'))],
|
46
|
-
:puppet_environment => [s_name(_('Puppet environment name'))],
|
47
45
|
:fact_value => [],
|
48
46
|
:filter => [],
|
49
47
|
:host => [ s_name(_("Host name")) ],
|
@@ -66,7 +64,6 @@ module HammerCLIForeman
|
|
66
64
|
:override_value => [],
|
67
65
|
:ptable => [ s_name(_("Partition table name")) ],
|
68
66
|
:proxy => [ s_name(_("Proxy name")) ],
|
69
|
-
:puppetclass => [ s_name(_("Puppet class name")) ],
|
70
67
|
:config_report => [],
|
71
68
|
:role => [ s_name(_("User role name")) ],
|
72
69
|
:setting => [ s_name(_("Setting name"), :editable => false) ],
|
@@ -74,7 +71,6 @@ module HammerCLIForeman
|
|
74
71
|
:template => [],
|
75
72
|
:user => [ s("login", _("User's login to search by")) ],
|
76
73
|
:common_parameter => [ s_name(_("Common parameter name")) ],
|
77
|
-
:smart_class_parameter => [ s_name(_("Smart class parameter name"), :editable => false) ],
|
78
74
|
:template_combination => [],
|
79
75
|
:compute_attribute => []
|
80
76
|
}
|
@@ -129,44 +125,6 @@ module HammerCLIForeman
|
|
129
125
|
scoped_options
|
130
126
|
end
|
131
127
|
|
132
|
-
def puppetclass_ids(options)
|
133
|
-
resource_name = :puppetclasses
|
134
|
-
resource = @api.resource(resource_name)
|
135
|
-
results = if (ids = options[HammerCLI.option_accessor_name("ids")])
|
136
|
-
ids
|
137
|
-
elsif (ids = nil_from_searchables(resource_name, options, :plural => true))
|
138
|
-
ids
|
139
|
-
elsif options_not_set?(resource, options)
|
140
|
-
raise MissingSearchOptions.new(_("Missing options to search %s") % resource.name, resource)
|
141
|
-
elsif options_empty?(resource, options)
|
142
|
-
[]
|
143
|
-
else
|
144
|
-
require('hammer_cli_foreman/puppet_class')
|
145
|
-
results = HammerCLIForeman::PuppetClass::ListCommand.unhash_classes(
|
146
|
-
resolved_call(resource_name, :index, options, :multi)
|
147
|
-
)
|
148
|
-
raise ResolverError.new(_("one of %s not found.") % resource.name, resource) if results.count < expected_record_count(options, resource, :multi)
|
149
|
-
|
150
|
-
results.map { |r| r['id'] }
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
def environment_id(options)
|
155
|
-
puppet_environment_id(options)
|
156
|
-
end
|
157
|
-
|
158
|
-
def puppet_environment_id(options)
|
159
|
-
get_id(:environments, options)
|
160
|
-
end
|
161
|
-
|
162
|
-
def environment_ids(options)
|
163
|
-
puppet_environment_ids(options)
|
164
|
-
end
|
165
|
-
|
166
|
-
def puppet_environment_ids(options)
|
167
|
-
get_ids(:environments, options)
|
168
|
-
end
|
169
|
-
|
170
128
|
def searchables(resource)
|
171
129
|
resource = @api.resource(resource) if resource.is_a? Symbol
|
172
130
|
@searchables.for(resource)
|
@@ -331,17 +289,6 @@ module HammerCLIForeman
|
|
331
289
|
0
|
332
290
|
end
|
333
291
|
|
334
|
-
# puppet class search results are in non-standard format
|
335
|
-
# and needs to be un-hashed first
|
336
|
-
def puppetclass_id(options)
|
337
|
-
return options[HammerCLI.option_accessor_name("id")] if options[HammerCLI.option_accessor_name("id")]
|
338
|
-
resource = @api.resource(:puppetclasses)
|
339
|
-
results = find_resource_raw(:puppetclasses, options)
|
340
|
-
require('hammer_cli_foreman/puppet_class')
|
341
|
-
results = HammerCLIForeman::PuppetClass::ListCommand.unhash_classes(results)
|
342
|
-
pick_result(results, resource)['id']
|
343
|
-
end
|
344
|
-
|
345
292
|
def options_empty?(resource, options)
|
346
293
|
searchables(resource).all? do |s|
|
347
294
|
values = options[HammerCLI.option_accessor_name(s.plural_name.to_s)]
|
@@ -356,14 +303,6 @@ module HammerCLIForeman
|
|
356
303
|
end
|
357
304
|
end
|
358
305
|
|
359
|
-
def create_smart_class_parameters_search_options(options, mode = nil)
|
360
|
-
search_options = {}
|
361
|
-
value = options[HammerCLI.option_accessor_name('name')]
|
362
|
-
search_options[:search] = "key = \"#{value}\""
|
363
|
-
search_options[:puppetclass_id] = puppetclass_id(scoped_options("puppetclass", options))
|
364
|
-
search_options
|
365
|
-
end
|
366
|
-
|
367
306
|
# @param mode [Symbol] mode in which ids are searched :single, :multi, nil for old beahvior
|
368
307
|
def create_search_options(options, resource, mode = nil)
|
369
308
|
searchables(resource).each do |s|
|
@@ -36,7 +36,6 @@ module HammerCLIForeman
|
|
36
36
|
HammerCLIForeman::References.partition_tables(self)
|
37
37
|
HammerCLIForeman::References.domains(self)
|
38
38
|
HammerCLIForeman::References.realms(self)
|
39
|
-
HammerCLIForeman::References.environments(self)
|
40
39
|
HammerCLIForeman::References.hostgroups(self)
|
41
40
|
HammerCLIForeman::References.parameters(self)
|
42
41
|
collection :organizations, _("Organizations"), :numbered => false, :hide_blank => true do
|
@@ -58,8 +57,6 @@ module HammerCLIForeman
|
|
58
57
|
failure_message _("Could not create the location")
|
59
58
|
|
60
59
|
build_options
|
61
|
-
|
62
|
-
extend_with(HammerCLIForeman::CommandExtensions::PuppetEnvironments.new)
|
63
60
|
end
|
64
61
|
|
65
62
|
|
@@ -72,8 +69,6 @@ module HammerCLIForeman
|
|
72
69
|
failure_message _("Could not update the location")
|
73
70
|
|
74
71
|
build_options
|
75
|
-
|
76
|
-
extend_with(HammerCLIForeman::CommandExtensions::PuppetEnvironments.new)
|
77
72
|
end
|
78
73
|
|
79
74
|
|
@@ -112,7 +107,6 @@ module HammerCLIForeman
|
|
112
107
|
end
|
113
108
|
|
114
109
|
HammerCLIForeman::AssociatingCommands::Hostgroup.extend_command(self)
|
115
|
-
HammerCLIForeman::AssociatingCommands::PuppetEnvironment.extend_command(self)
|
116
110
|
HammerCLIForeman::AssociatingCommands::Domain.extend_command(self)
|
117
111
|
HammerCLIForeman::AssociatingCommands::Medium.extend_command(self)
|
118
112
|
HammerCLIForeman::AssociatingCommands::Subnet.extend_command(self)
|
@@ -224,11 +224,11 @@ module HammerCLIForeman
|
|
224
224
|
resource_name = resource.singular_name
|
225
225
|
aliased_name = aliased(resource_name, resource_name_map)
|
226
226
|
types = searchables.map(&:name).push('id').map(&:capitalize).join('/')
|
227
|
-
associated_resource =
|
227
|
+
associated_resource = aliased_name.to_s.tr('_', ' ')
|
228
228
|
family = HammerCLI::Options::OptionFamily.new(
|
229
229
|
referenced_resource: resource_name,
|
230
230
|
aliased_resource: aliased_name,
|
231
|
-
description: _('
|
231
|
+
description: _('%{types} of associated %{resource}') % { types: types, resource: associated_resource }
|
232
232
|
)
|
233
233
|
|
234
234
|
unless searchables.empty?
|
@@ -256,7 +256,7 @@ module HammerCLIForeman
|
|
256
256
|
end
|
257
257
|
end
|
258
258
|
|
259
|
-
unless options.any? { |o| o.handles?("--#{aliased_name}-id") }
|
259
|
+
unless options.any? { |o| o.handles?(optionamize("--#{aliased_name}-id")) }
|
260
260
|
options << family.parent(
|
261
261
|
optionamize("--#{aliased_name}-id"),
|
262
262
|
"#{aliased_name}_id".upcase,
|
@@ -319,7 +319,7 @@ module HammerCLIForeman
|
|
319
319
|
end
|
320
320
|
end
|
321
321
|
|
322
|
-
unless options.any? { |o| o.handles?("--new-#{aliased_name}-id") }
|
322
|
+
unless options.any? { |o| o.handles?(optionamize("--new-#{aliased_name}-id")) }
|
323
323
|
options << family.parent(
|
324
324
|
optionamize("--new-#{aliased_name}-id"),
|
325
325
|
"new_#{aliased_name}_id".upcase,
|
@@ -347,7 +347,7 @@ module HammerCLIForeman
|
|
347
347
|
first = searchables[0]
|
348
348
|
remaining = searchables[1..-1] || []
|
349
349
|
types = searchables.map(&:plural_name).map(&:capitalize).join('/')
|
350
|
-
associated_resource =
|
350
|
+
associated_resource = aliased_plural_name.to_s.tr('_', ' ')
|
351
351
|
family = HammerCLI::Options::OptionFamily.new(
|
352
352
|
format: HammerCLI::Options::Normalizers::List.new,
|
353
353
|
referenced_resource: resource_name,
|
@@ -421,3 +421,4 @@ module HammerCLIForeman
|
|
421
421
|
end
|
422
422
|
|
423
423
|
end
|
424
|
+
|
@@ -3,6 +3,5 @@ require 'hammer_cli_foreman/option_sources/ids_params'
|
|
3
3
|
require 'hammer_cli_foreman/option_sources/self_param'
|
4
4
|
require 'hammer_cli_foreman/option_sources/user_params'
|
5
5
|
require 'hammer_cli_foreman/option_sources/fields_params'
|
6
|
-
require 'hammer_cli_foreman/option_sources/puppet_environment_params'
|
7
6
|
require 'hammer_cli_foreman/option_sources/new_params'
|
8
7
|
require 'hammer_cli_foreman/option_sources/referenced_resource_id_params'
|
@@ -13,22 +13,39 @@ module HammerCLIForeman
|
|
13
13
|
IdParamsFilter.new(:only_required => false).for_action(@command.resource.action(@command.action))
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
16
|
+
def needs_resolving?(param_option, param_resource, all_opts)
|
17
|
+
return false unless param_updatable?(param_resource)
|
18
|
+
|
19
|
+
searchables_set = @command.searchables.for(param_resource).any? do |s|
|
20
|
+
option = HammerCLI.option_accessor_name("#{param_resource.singular_name}_#{s.name}")
|
21
|
+
!all_opts[option].nil?
|
22
|
+
end
|
23
|
+
return all_opts[param_option].nil? unless searchables_set
|
24
|
+
|
25
|
+
# Remove set '<resource_name>_id' option to force resolving in case of
|
26
|
+
# '<resource_name>_[name|title]' was set
|
27
|
+
all_opts.delete(param_option)
|
28
|
+
true
|
29
|
+
end
|
30
|
+
|
31
|
+
def get_options(_defined_options, result)
|
17
32
|
# resolve all '<resource_name>_id' parameters if they are defined as options
|
18
33
|
# (they can be skipped using .without or .expand.except)
|
19
34
|
return result if @command.action.nil?
|
35
|
+
|
20
36
|
available_id_params.each do |api_param|
|
21
37
|
param_resource = HammerCLIForeman.param_to_resource(api_param.name)
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
38
|
+
param_option = HammerCLI.option_accessor_name(api_param.name)
|
39
|
+
next unless needs_resolving?(param_option, param_resource, result)
|
40
|
+
|
41
|
+
resource_id = @command.get_resource_id(
|
42
|
+
param_resource, scoped: true, required: api_param.required?, all_options: result
|
43
|
+
)
|
44
|
+
result[param_option] = resource_id if resource_id
|
26
45
|
end
|
27
46
|
result
|
28
|
-
|
29
47
|
rescue HammerCLIForeman::MissingSearchOptions => e
|
30
|
-
|
31
|
-
switches = @command.class.find_options(:referenced_resource => e.resource.singular_name).map(&:long_switch)
|
48
|
+
switches = @command.class.find_options(referenced_resource: e.resource.singular_name).map(&:long_switch)
|
32
49
|
|
33
50
|
if switches.empty?
|
34
51
|
error_message = _("Could not find %{resource}. Some search options were missing, please see --help.")
|
@@ -40,8 +57,8 @@ module HammerCLIForeman
|
|
40
57
|
|
41
58
|
raise MissingSearchOptions.new(
|
42
59
|
error_message % {
|
43
|
-
:
|
44
|
-
:
|
60
|
+
resource: e.resource.singular_name,
|
61
|
+
switches: switches.join(', ')
|
45
62
|
},
|
46
63
|
e.resource
|
47
64
|
)
|