foreman_wreckingball 2.0.0 → 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/README.md +1 -0
- data/app/assets/javascripts/foreman_wreckingball/modal.js +42 -0
- data/app/controllers/foreman_wreckingball/hosts_controller.rb +25 -6
- data/app/lib/actions/foreman_wreckingball/host/remediate_vmware_operatingsystem.rb +5 -0
- data/app/models/foreman_wreckingball/operatingsystem_status.rb +4 -0
- data/app/views/foreman_wreckingball/hosts/_status_row.html.erb +3 -4
- data/app/views/foreman_wreckingball/hosts/schedule_remediate.html.erb +35 -0
- data/app/views/foreman_wreckingball/hosts/status_dashboard.html.erb +11 -0
- data/config/routes.rb +2 -1
- data/lib/foreman_wreckingball/engine.rb +2 -2
- data/lib/foreman_wreckingball/version.rb +1 -1
- data/test/controllers/foreman_wreckingball/hosts_controller_test.rb +27 -5
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91f8e9b4e8ec69fe49517364365ff0ea5e46435998461cd967718539c9e69546
|
4
|
+
data.tar.gz: 444176c10728b0457d50ab41adf8a923d66d30f383bb0564e9b172973bace129
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21d17ab1949782bf8a6b0f2c0f2e5d7d4fa43d8c25d93112b3ac3e1412f16b5418357b82c05643248fff7c57671bbbe31bdfc04c11559b34db5d7351f90e6514
|
7
|
+
data.tar.gz: 489a9097ef263bc2e1eb4cff7d0ae695e1e53fd7462066ad8f06be48efc7aedadc5b013287198a4350f9c22908c1d99f9abe78ba46dd11bd254b8d3b9b545bd0
|
data/README.md
CHANGED
@@ -0,0 +1,42 @@
|
|
1
|
+
$(function() {
|
2
|
+
$('#confirmation-modal .secondary').click(function(){
|
3
|
+
$('#confirmation-modal').modal('hide');
|
4
|
+
});
|
5
|
+
});
|
6
|
+
|
7
|
+
function submit_modal_form() {
|
8
|
+
$('#confirmation-modal form').submit();
|
9
|
+
$('#confirmation-modal').modal('hide');
|
10
|
+
}
|
11
|
+
|
12
|
+
function show_modal(element, url) {
|
13
|
+
if (!url) {
|
14
|
+
url = $(element).attr('href');
|
15
|
+
}
|
16
|
+
var title = $(element).attr('data-title');
|
17
|
+
if (title) {
|
18
|
+
$('#confirmation-modal .modal-title').text(title);
|
19
|
+
}
|
20
|
+
$('#confirmation-modal .modal-body')
|
21
|
+
.empty()
|
22
|
+
.append('<div class="modal-spinner spinner spinner-lg"></div>');
|
23
|
+
$('#confirmation-modal').modal();
|
24
|
+
$('#confirmation-modal .modal-body').load(url + ' #content',
|
25
|
+
function(response, status, xhr) {
|
26
|
+
$('#confirmation-modal .form-actions').remove();
|
27
|
+
|
28
|
+
var submit_button = $('#confirmation-modal button[data-action="submit"]');
|
29
|
+
if ($(element).attr('data-submit-class')) {
|
30
|
+
submit_button.attr('class', 'btn ' + $(element).attr('data-submit-class'));
|
31
|
+
} else {
|
32
|
+
submit_button.attr('class', 'btn btn-primary');
|
33
|
+
}
|
34
|
+
|
35
|
+
$('#confirmation-modal a[rel="popover"]').popover();
|
36
|
+
|
37
|
+
trigger_form_selector_binds('schedule_remediate_form', url);
|
38
|
+
$('#loading').hide();
|
39
|
+
});
|
40
|
+
return false;
|
41
|
+
}
|
42
|
+
|
@@ -2,8 +2,9 @@
|
|
2
2
|
|
3
3
|
module ForemanWreckingball
|
4
4
|
class HostsController < ::HostsController
|
5
|
-
|
6
|
-
before_action :
|
5
|
+
include ::ForemanTasks::Concerns::Parameters::Triggering
|
6
|
+
before_action :find_resource, :only => [:submit_remediate, :schedule_remediate]
|
7
|
+
before_action :find_status, :only => [:submit_remediate, :schedule_remediate]
|
7
8
|
|
8
9
|
def status_dashboard
|
9
10
|
statuses = [
|
@@ -42,17 +43,35 @@ module ForemanWreckingball
|
|
42
43
|
redirect_to(foreman_tasks_task_path(task.id))
|
43
44
|
end
|
44
45
|
|
45
|
-
def
|
46
|
+
def schedule_remediate
|
47
|
+
@triggering = ForemanTasks::Triggering.new(mode: :immediate)
|
48
|
+
end
|
49
|
+
|
50
|
+
def submit_remediate
|
46
51
|
raise Foreman::Exception, 'VMware Status can not be remediated.' unless @status.class.respond_to?(:supports_remediate?) && @status.class.supports_remediate?
|
47
|
-
flash[:success] = _('Remediate VM task for %s was successfully scheduled.') % @host
|
48
52
|
task = User.as_anonymous_admin do
|
49
|
-
::ForemanTasks.
|
53
|
+
triggering = ::ForemanTasks::Triggering.new_from_params(triggering_params)
|
54
|
+
if triggering.future?
|
55
|
+
triggering.parse_start_at!
|
56
|
+
triggering.parse_start_before!
|
57
|
+
else
|
58
|
+
triggering.start_at ||= Time.zone.now
|
59
|
+
end
|
60
|
+
|
61
|
+
triggering.trigger(@status.class.remediate_action, @host)
|
50
62
|
end
|
63
|
+
flash[:success] = _('Remediate VM task for %s was successfully scheduled.') % @host
|
51
64
|
redirect_to(foreman_tasks_task_path(task.id))
|
52
65
|
end
|
53
66
|
|
54
67
|
private
|
55
68
|
|
69
|
+
def triggering_params
|
70
|
+
%i[triggering foreman_tasks_triggering].inject({}) do |result, param_name|
|
71
|
+
result.merge(self.class.triggering_params_filter.filter_params(params, parameter_filter_context, param_name))
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
56
75
|
def find_status
|
57
76
|
@status = HostStatus::Status.find_by!(:id => params[:status_id], :host_id => @host.id)
|
58
77
|
end
|
@@ -63,7 +82,7 @@ module ForemanWreckingball
|
|
63
82
|
'view'
|
64
83
|
when 'refresh_status_dashboard'
|
65
84
|
'refresh_vmware_status'
|
66
|
-
when '
|
85
|
+
when 'schedule_remediate', 'submit_remediate'
|
67
86
|
'remediate_vmware_status'
|
68
87
|
else
|
69
88
|
super
|
@@ -6,6 +6,11 @@ module Actions
|
|
6
6
|
class RemediateVmwareOperatingsystem < Actions::EntryAction
|
7
7
|
middleware.use Actions::Middleware::KeepCurrentUser
|
8
8
|
|
9
|
+
def delay(delay_options, host)
|
10
|
+
action_subject(host)
|
11
|
+
super(delay_options, host)
|
12
|
+
end
|
13
|
+
|
9
14
|
def plan(host)
|
10
15
|
action_subject(host)
|
11
16
|
plan_self
|
@@ -85,10 +85,9 @@
|
|
85
85
|
action_buttons(
|
86
86
|
display_link_if_authorized(
|
87
87
|
_('Remediate'),
|
88
|
-
|
89
|
-
:data => { :
|
90
|
-
:
|
91
|
-
:target => :blank
|
88
|
+
hash_for_schedule_remediate_host_path(:id => host, :status_id => host.public_send(status).id).merge(:auth_object => host, :permission => 'remediate_vmware_status_hosts'),
|
89
|
+
:data => { :title => _('Remediate Host OS'), :submit_class => 'btn-danger' },
|
90
|
+
:onclick => 'show_modal(this); return false;'
|
92
91
|
)
|
93
92
|
)
|
94
93
|
%>
|
@@ -0,0 +1,35 @@
|
|
1
|
+
<% title _('Remediate %s') % @host %>
|
2
|
+
<% javascript 'foreman_tasks/trigger_form' %>
|
3
|
+
<% stylesheet 'foreman_tasks/trigger_form' %>
|
4
|
+
|
5
|
+
|
6
|
+
<% if @status.class.respond_to?(:dangerous_remediate?) && @status.class.dangerous_remediate? -%>
|
7
|
+
<%= alert(:text => _('This will cause a service interruption.'), :class => 'alert-warning', :close => false) %>
|
8
|
+
<% end -%>
|
9
|
+
|
10
|
+
<%= form_for @triggering, :url => submit_remediate_host_path(:id => @host.id, :status_id => @status), :html => { :class => 'form-horizontal', :id => 'schedule_remediate_form' } do |f| %>
|
11
|
+
<%= javascript_tag do %>
|
12
|
+
$(function() { trigger_form_selector_binds('<%= f.options[:html][:id] %>','<%= f.object_name %>') });
|
13
|
+
<% end %>
|
14
|
+
<div class="form-group">
|
15
|
+
<label class="col-md-2 control-label"><%= _('Schedule') %></label>
|
16
|
+
<div class="col-md-8">
|
17
|
+
<%= fields_for :triggering, @triggering do |trigger_fields| %>
|
18
|
+
<%= radio_button_f trigger_fields, :mode, :class => 'trigger_mode_selector', :value => 'immediate', :text => _("Execute now") %>
|
19
|
+
<%= radio_button_f trigger_fields, :mode, :class => 'trigger_mode_selector', :value => 'future', :text => _("Schedule future execution") %>
|
20
|
+
</div>
|
21
|
+
</div>
|
22
|
+
|
23
|
+
<div class="trigger_fields">
|
24
|
+
<%= content_tag(:fieldset, nil, :id => 'trigger_mode_future', :class => "trigger_mode_form #{'hidden' unless @triggering.future?}") do
|
25
|
+
safe_join([
|
26
|
+
text_f(f, :start_at_raw, :label => _('Start at'), :placeholder => 'YYYY-mm-dd HH:MM'),
|
27
|
+
text_f(f, :start_before_raw, :label => _('Start before'), :placeholder => 'YYYY-mm-dd HH:MM',
|
28
|
+
:label_help => _('Indicates that the action should be cancelled if it cannot be started before this time.'))
|
29
|
+
])
|
30
|
+
end %>
|
31
|
+
</div>
|
32
|
+
<% end %>
|
33
|
+
|
34
|
+
<%= submit_or_cancel f, false, :cancel_path => { :controller => :'foreman_wreckingball/hosts', :action => :status_dashboard } %>
|
35
|
+
<% end %>
|
@@ -1,4 +1,7 @@
|
|
1
1
|
<% title _('VMware Status Overview') %>
|
2
|
+
<% javascript 'foreman_wreckingball/modal' %>
|
3
|
+
<% javascript 'foreman_tasks/trigger_form' %>
|
4
|
+
<% stylesheet 'foreman_tasks/trigger_form' %>
|
2
5
|
|
3
6
|
<%=
|
4
7
|
if @newest_data
|
@@ -7,3 +10,11 @@
|
|
7
10
|
render 'status_dashboard_empty'
|
8
11
|
end
|
9
12
|
%>
|
13
|
+
<%= render :partial => 'common/modal', :locals => {
|
14
|
+
:id => 'confirmation-modal',
|
15
|
+
:title => _('Please Confirm'),
|
16
|
+
:buttons => [
|
17
|
+
button_tag(_('Cancel'), :class => 'btn btn-default', :data => { :dismiss => 'modal' }, :type => 'button'),
|
18
|
+
button_tag(_('Submit'), :class => 'btn btn-primary', :data => { :action => 'submit' }, :onclick => 'submit_modal_form()')
|
19
|
+
]
|
20
|
+
} %>
|
data/config/routes.rb
CHANGED
@@ -5,7 +5,8 @@ Rails.application.routes.draw do
|
|
5
5
|
constraints(:id => /[^\/]+/) do
|
6
6
|
resources :hosts, controller: 'foreman_wreckingball/hosts', only: [] do
|
7
7
|
member do
|
8
|
-
|
8
|
+
get :schedule_remediate
|
9
|
+
post :submit_remediate
|
9
10
|
end
|
10
11
|
collection do
|
11
12
|
get :status_dashboard
|
@@ -25,14 +25,14 @@ module ForemanWreckingball
|
|
25
25
|
|
26
26
|
initializer 'foreman_wreckingball.register_plugin', :before => :finisher_hook do |_app|
|
27
27
|
Foreman::Plugin.register :foreman_wreckingball do
|
28
|
-
requires_foreman '>= 1.
|
28
|
+
requires_foreman '>= 1.18'
|
29
29
|
|
30
30
|
security_block :foreman_wreckingball do
|
31
31
|
permission :refresh_vmware_status_hosts, {
|
32
32
|
:'foreman_wreckingball/hosts' => [:refresh_status_dashboard]
|
33
33
|
}, :resource_type => 'Host'
|
34
34
|
permission :remediate_vmware_status_hosts, {
|
35
|
-
:'foreman_wreckingball/hosts' => [:
|
35
|
+
:'foreman_wreckingball/hosts' => [:schedule_remediate, :submit_remediate]
|
36
36
|
}, :resource_type => 'Host'
|
37
37
|
end
|
38
38
|
|
@@ -34,14 +34,36 @@ module ForemanWreckingball
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
describe '#
|
37
|
+
describe '#schedule_remediate' do
|
38
|
+
let(:host) do
|
39
|
+
FactoryBot.create(:host, :with_wreckingball_statuses)
|
40
|
+
end
|
41
|
+
|
42
|
+
test 'shows a remediation schedule page' do
|
43
|
+
get :schedule_remediate, params: { status_id: host.vmware_operatingsystem_status_object.id, id: host.id }, session: set_session_user
|
44
|
+
assert_response :success
|
45
|
+
end
|
46
|
+
|
47
|
+
test 'returns not found when host id is invalid' do
|
48
|
+
get :schedule_remediate, params: { status_id: nil, id: 'invalid' }, session: set_session_user
|
49
|
+
assert_response :not_found
|
50
|
+
end
|
51
|
+
|
52
|
+
test 'returns not found when status id is invalid' do
|
53
|
+
FactoryBot.create(:host, :with_wreckingball_statuses)
|
54
|
+
get :schedule_remediate, params: { status_id: 'invalid', id: host.id }, session: set_session_user
|
55
|
+
assert_response :not_found
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '#submit_remediate' do
|
38
60
|
let(:host) do
|
39
61
|
FactoryBot.create(:host, :with_wreckingball_statuses)
|
40
62
|
end
|
41
63
|
|
42
64
|
test 'redirects to scheduled task' do
|
43
65
|
ForemanTasks.expects(:async_task).returns(fake_task)
|
44
|
-
|
66
|
+
post :submit_remediate, params: { status_id: host.vmware_operatingsystem_status_object.id, id: host.id }, session: set_session_user
|
45
67
|
assert_response :redirect
|
46
68
|
assert_includes flash[:success], 'successfully scheduled'
|
47
69
|
assert_redirected_to foreman_tasks_task_path(123)
|
@@ -50,18 +72,18 @@ module ForemanWreckingball
|
|
50
72
|
test 'raises error when status can not be remediated' do
|
51
73
|
FactoryBot.create(:host, :with_wreckingball_statuses)
|
52
74
|
assert_raises Foreman::Exception do
|
53
|
-
|
75
|
+
post :submit_remediate, params: { status_id: host.vmware_tools_status_object.id, id: host.id }, session: set_session_user
|
54
76
|
end
|
55
77
|
end
|
56
78
|
|
57
79
|
test 'returns not found when host id is invalid' do
|
58
|
-
|
80
|
+
post :submit_remediate, params: { status_id: nil, id: 'invalid' }, session: set_session_user
|
59
81
|
assert_response :not_found
|
60
82
|
end
|
61
83
|
|
62
84
|
test 'returns not found when status id is invalid' do
|
63
85
|
FactoryBot.create(:host, :with_wreckingball_statuses)
|
64
|
-
|
86
|
+
post :submit_remediate, params: { status_id: 'invalid', id: host.id }, session: set_session_user
|
65
87
|
assert_response :not_found
|
66
88
|
end
|
67
89
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman_wreckingball
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Timo Goebel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: foreman-tasks
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.13.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.13.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rdoc
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- LICENSE
|
63
63
|
- README.md
|
64
64
|
- Rakefile
|
65
|
+
- app/assets/javascripts/foreman_wreckingball/modal.js
|
65
66
|
- app/controllers/foreman_wreckingball/hosts_controller.rb
|
66
67
|
- app/helpers/concerns/foreman_wreckingball/hosts_helper_extensions.rb
|
67
68
|
- app/jobs/update_hosts_vmware_facets.rb
|
@@ -90,6 +91,7 @@ files:
|
|
90
91
|
- app/views/foreman_wreckingball/hosts/_status_dashboard_content.erb
|
91
92
|
- app/views/foreman_wreckingball/hosts/_status_dashboard_empty.erb
|
92
93
|
- app/views/foreman_wreckingball/hosts/_status_row.html.erb
|
94
|
+
- app/views/foreman_wreckingball/hosts/schedule_remediate.html.erb
|
93
95
|
- app/views/foreman_wreckingball/hosts/status_dashboard.html.erb
|
94
96
|
- config/routes.rb
|
95
97
|
- db/migrate/20171106155000_create_vmware_facets.rb
|