-
Notifications
You must be signed in to change notification settings - Fork 96
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 #10756, #13500 - developer api and PXE-less reprovisioning #144
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do this 3-step dance in a lot of places, we don't have to change it now, but any reason not to just save and trigger in one step for this and other controllers? Something like JobInvocationComposer.trigger_for_feature!(:reprovision, @host, :script => script) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so there would be both There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea, that would work. It's really not a big deal, I just noticed we keep making minor changes to how this gets called and figured maybe it could be DRYer. |
||
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class RemoteExecutionFeaturesController < ::ApplicationController | ||
before_filter :find_resource, :only => [:show, :update] | ||
|
||
def index | ||
@remote_execution_features = resource_base.all | ||
end | ||
|
||
def show | ||
end | ||
|
||
def update | ||
if @remote_execution_feature.update_attributes(params[:remote_execution_feature]) | ||
process_success :object => @remote_execution_feature | ||
else | ||
process_error :object => @remote_execution_feature | ||
end | ||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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).template && @host.provisioning_template(:kind => 'script') | ||
links << link_to(_('Reprovision'), reprovision_host_path(host.id), { :method => :post, :disabled => @host.build }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we somehow add this to the build button as a dropdown? I would guess maybe not easy to extend from plugin. I only wonder because the host actions can get quite big if you install a lot of plugins, and this is really related to the build. |
||
end | ||
title_actions(button_group(*links)) | ||
host_title_actions_without_run_button(host) | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,7 +50,7 @@ def remote_execution_proxies(provider) | |
proxy_scope = ::SmartProxy | ||
end | ||
|
||
proxies[:global] = proxy_scope.authorized.with_features(provider) | ||
proxies[:global] = proxy_scope.with_features(provider) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had to do this in order to ssh keys snippet to work with global proxy, I will probably open a separate PR and issue for this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
end | ||
|
||
proxies | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
class RemoteExecutionFeature < ActiveRecord::Base | ||
attr_accessible :label, :name, :provided_input_names, :description, :template_id | ||
|
||
validate :label, :name, :presence => true, :unique => true | ||
|
||
belongs_to :template | ||
|
||
extend FriendlyId | ||
friendly_id :label | ||
|
||
def provided_input_names | ||
self.provided_inputs.to_s.split(',').map(&:chomp) | ||
end | ||
|
||
def provided_input_names=(values) | ||
self.provided_inputs = Array(values).join(',') | ||
end | ||
|
||
class << self | ||
def feature(label) | ||
self.find_by_label(label) || raise(::Foreman::Exception.new(N_("Unknown remote execution feature %s"), label)) | ||
end | ||
|
||
def register(label, name, options = {}) | ||
return false unless RemoteExecutionFeature.table_exists? | ||
options.assert_valid_keys(:provided_inputs, :description) | ||
feature = self.find_by_label(label) | ||
if feature.nil? | ||
feature = self.create!(:label => label, :name => name, :provided_input_names => options[:provided_inputs], :description => options[:description]) | ||
else | ||
feature.update_attributes!(:name => name, :provided_input_names => options[:provided_inputs], :description => options[:description]) | ||
end | ||
return feature | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<%= form_for @remote_execution_feature do |f| %> | ||
<div class="row"> | ||
<%= field(f, :name) { @remote_execution_feature.name } %> | ||
</div> | ||
<div class="row"> | ||
<%= field(f, :label) { @remote_execution_feature.label } %> | ||
</div> | ||
<div class="row"> | ||
<%= field(f, :description) { @remote_execution_feature.description } %> | ||
</div> | ||
<div class="row"> | ||
<%= field(f, :provided_inputs) { @remote_execution_feature.provided_inputs } %> | ||
</div> | ||
<div class="row"> | ||
<%= selectable_f f, :template_id, JobTemplate.all.map { |t| [ t.name, t.id ] }, { :include_blank => true }, :class => 'input_type_selector' %> | ||
</div> | ||
<%= submit_or_cancel f %> | ||
<% end %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<% title _('Remote Execution Features') %> | ||
|
||
<table class="table table-bordered table-striped table-condensed"> | ||
<thead> | ||
<tr> | ||
<th><%= sort :label, :as => _('Label') %></th> | ||
<th><%= sort :name, :as => _('Name') %></th> | ||
<th><%= sort :description, :as => _('Description') %></th> | ||
</tr> | ||
</thead> | ||
|
||
<tbody> | ||
<% @remote_execution_features.each do |feature| %> | ||
<tr> | ||
<td><%= link_to_if_authorized feature.label, hash_for_remote_execution_feature_path(feature).merge(:auth_object => feature, :permission => :view_remote_execution_feature) %></td> | ||
<td><%= feature.name %></td> | ||
<td><%= feature.description %></td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<% title _("Edit Remote Execution Feature") %> | ||
|
||
<%= render :partial => 'form' %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<%# | ||
kind: job_template | ||
name: Power Action - SSH Default | ||
job_category: Power | ||
description_format: '%{action} host' | ||
provider_type: SSH | ||
template_inputs: | ||
- name: action | ||
description: Action to perform on the service | ||
input_type: user | ||
options: "restart\nshutdown" | ||
required: true | ||
%> | ||
|
||
echo <%= input('action') %> host && sleep 3 | ||
<%= case input('action') | ||
when 'restart' | ||
'reboot' | ||
else | ||
'shutdown -h now' | ||
end %> | ||
|
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") %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Single quote string literals (and in a bunch of other places) 😄 rubocop can fix all of these.