Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #13500 - Pxe-less reprovision with remote execution #159

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module ForemanRemoteExecution
module HostsControllerExtensions
extend ActiveSupport::Concern
include Foreman::Renderer

included do
alias_method_chain(:action_permission, :remote_execution)
end

def reprovision
find_resource
script_template = @host.provisioning_template(:kind => 'script')
if script_template.nil?
process_error :redirect => :back, :error_msg => _("No script provisioning template available")
return
end
@host.setBuild
script = unattended_render(script_template.template, @template_name)
composer = JobInvocationComposer.for_feature(:reprovision, @host, :script => script)
composer.save!
composer.trigger
process_success :success_msg => _("Reprovision job started. The host should reboot soon."), :success_redirect => :back
end

private

def action_permission_with_remote_execution
case params[:action]
when 'reprovision'
:edit_host
else
action_permission_without_remote_execution
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ def multiple_actions_with_remote_execution
multiple_actions_without_remote_execution + [[_('Run Job'), new_job_invocation_path, false]]
end

def host_title_actions_with_run_button(*args)
title_actions(button_group(link_to(_('Run Job'), new_job_invocation_path(:host_ids => [args.first.id]), :id => :run_button)))
host_title_actions_without_run_button(*args)
def host_title_actions_with_run_button(host)
links = [link_to(_('Run Job'), new_job_invocation_path(:host_ids => [host.id]), :id => :run_button)]
if RemoteExecutionFeature.feature(:reprovision).job_template && @host.provisioning_template(:kind => 'script')
links << link_to(_('Reprovision'), reprovision_host_path(host.id), { :method => :post, :disabled => @host.build })
end
title_actions(button_group(*links))
host_title_actions_without_run_button(host)
end
end
end
16 changes: 16 additions & 0 deletions app/views/templates/reprovision.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<%#
kind: job_template
name: Reprovision - SSH Default
job_category: Power
description_format: 'Reprovision host'
feature: reprovision
provider_type: SSH
template_inputs:
- name: script
description: script to configure the bootloader to provision on next boot
input_type: user
required: true
%>

<%= input('script') %>
<%= render_template("Power Action - SSH Default", :action => "restart") %>
6 changes: 6 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
Rails.application.routes.draw do
resources :hosts, :only => [] do
member do
post 'reprovision', :method => :post
end
end

resources :job_templates, :except => [:show] do
member do
get 'clone_template'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ChangeTemplateInvocationInputValuesValue < ActiveRecord::Migration
def change
change_column :template_invocation_input_values, :value, :text
end
end
7 changes: 7 additions & 0 deletions lib/foreman_remote_execution/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ class Engine < ::Rails::Engine
register_custom_status HostStatus::ExecutionStatus
# add dashboard widget
# widget 'foreman_remote_execution_widget', name: N_('Foreman plugin template widget'), sizex: 4, sizey: 1

RemoteExecutionFeature.register(:reprovision, N_("Reprovision"),
:description => "Reprovision the host via a script",
:provided_inputs => ['script'])
end
end

Expand Down Expand Up @@ -133,6 +137,9 @@ class Engine < ::Rails::Engine
# Template.reflect_on_association :template_inputs # => <#Association...
# ProvisioningTemplate.reflect_on_association :template_inputs # => nil
require_dependency 'job_template'

HostsController.send(:include, ForemanRemoteExecution::HostsControllerExtensions)

(Template.descendants + [Template]).each { |klass| klass.send(:include, ForemanRemoteExecution::TemplateExtensions) }

(Taxonomy.descendants + [Taxonomy]).each { |klass| klass.send(:include, ForemanRemoteExecution::TaxonomyExtensions) }
Expand Down