Class: HammerCLIForeman::OperatingSystem::SetOsDefaultTemplate
- Inherits:
-
Command
- Object
- HammerCLI::Apipie::Command
- Command
- HammerCLIForeman::OperatingSystem::SetOsDefaultTemplate
show all
- Defined in:
- lib/hammer_cli_foreman/operating_system.rb
Instance Method Summary
collapse
Methods inherited from Command
build_options, connection_name, create_option_builder, #customized_options, #dependency_resolver, dependency_resolver, #get_identifier, #get_resource_id, #request_params, #resolver, resolver, resource_config, resource_name_mapping, searchables, #searchables, #send_request
Instance Method Details
#base_action_params ⇒ Object
153
154
155
|
# File 'lib/hammer_cli_foreman/operating_system.rb', line 153
def base_action_params
{"operatingsystem_id" => option_id}
end
|
#create_default_template(tpl_kind_name) ⇒ Object
174
175
176
177
178
179
180
181
182
183
|
# File 'lib/hammer_cli_foreman/operating_system.rb', line 174
def create_default_template(tpl_kind_name)
params = {
"os_default_template" => {
"config_template_id" => option_config_template_id,
"template_kind_name" => tpl_kind_name
}
}.merge base_action_params
HammerCLIForeman.record_to_common_format(resource.call(:create, params))
end
|
#execute ⇒ Object
185
186
187
188
189
190
191
192
193
194
195
196
|
# File 'lib/hammer_cli_foreman/operating_system.rb', line 185
def execute
tpl_kind_name = option_type_name
tpl = template_exist? tpl_kind_name
if tpl
update_default_template tpl
print_message(success_message, tpl) if success_message
else
tpl = create_default_template tpl_kind_name
print_message(success_message, tpl) if success_message
end
HammerCLI::EX_OK
end
|
#option_type_name ⇒ Object
#template_exist?(tpl_kind_name) ⇒ Boolean
157
158
159
160
|
# File 'lib/hammer_cli_foreman/operating_system.rb', line 157
def template_exist?(tpl_kind_name)
templates = HammerCLIForeman.collection_to_common_format(resource.call(:index, base_action_params))
templates.find { |p| p["template_kind_name"] == tpl_kind_name}
end
|
#update_default_template(tpl) ⇒ Object
162
163
164
165
166
167
168
169
170
171
172
|
# File 'lib/hammer_cli_foreman/operating_system.rb', line 162
def update_default_template(tpl)
params = {
"id" => tpl["id"],
"os_default_template" => {
"config_template_id" => option_config_template_id,
"template_kind_id" => tpl["template_kind_id"]
}
}.merge base_action_params
HammerCLIForeman.record_to_common_format(resource.call(:update, params))
end
|