Class: HammerCLIForeman::OperatingSystem::SetOsDefaultTemplate

Inherits:
Command
  • Object
show all
Defined in:
lib/hammer_cli_foreman/operating_system.rb

Instance Method Summary collapse

Methods inherited from Command

alias_name_for_resource, build_options, connection_name, create_option_builder, #customized_options, #dependency_resolver, dependency_resolver, #exception_handler_class, #get_identifier, #get_resource_id, #get_resource_ids, #request_params, resolver, #resolver, resource_alias_name_mapping, resource_config, resource_name_mapping, #searchables, searchables, #send_request, #transform_format

Instance Method Details

#base_action_paramsObject



114
115
116
# File 'lib/hammer_cli_foreman/operating_system.rb', line 114

def base_action_params
  {"operatingsystem_id" => option_id}
end

#create_default_template(tpl_kind_name) ⇒ Object



135
136
137
138
139
140
141
142
143
144
# File 'lib/hammer_cli_foreman/operating_system.rb', line 135

def create_default_template(tpl_kind_name)
  params = {
    "os_default_template" => {
      "provisioning_template_id" => option_provisioning_template_id,
      "template_kind_name" => tpl_kind_name
    }
  }.merge base_action_params

  HammerCLIForeman.record_to_common_format(resource.call(:create, params))
end

#executeObject



146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/hammer_cli_foreman/operating_system.rb', line 146

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_nameObject



108
109
110
111
112
# File 'lib/hammer_cli_foreman/operating_system.rb', line 108

def option_type_name
  tpl = HammerCLIForeman.collection_to_common_format(
    HammerCLIForeman.foreman_resource!(:provisioning_templates).call(:show, {"id" => option_provisioning_template_id}))
  tpl[0]["template_kind_name"]
end

#template_exist?(tpl_kind_name) ⇒ Boolean

Returns:

  • (Boolean)


118
119
120
121
# File 'lib/hammer_cli_foreman/operating_system.rb', line 118

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



123
124
125
126
127
128
129
130
131
132
133
# File 'lib/hammer_cli_foreman/operating_system.rb', line 123

def update_default_template(tpl)
  params = {
    "id" => tpl["id"],
    "os_default_template" => {
      "provisioning_template_id" => option_provisioning_template_id,
      "template_kind_id" => tpl["template_kind_id"]
    }
  }.merge base_action_params

  HammerCLIForeman.record_to_common_format(resource.call(:update, params))
end