foreman_dlm 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +619 -0
- data/README.md +84 -0
- data/Rakefile +47 -0
- data/app/controllers/api/v2/dlmlocks_controller.rb +157 -0
- data/app/controllers/concerns/foreman/controller/parameters/dlmlocks.rb +15 -0
- data/app/controllers/concerns/foreman_dlm/find_host_by_client_cert.rb +63 -0
- data/app/controllers/concerns/foreman_dlm/find_host_by_ip.rb +54 -0
- data/app/controllers/dlmlocks_controller.rb +13 -0
- data/app/helpers/foreman_dlm/dlmlock_helper.rb +15 -0
- data/app/models/concerns/foreman_dlm/host_extensions.rb +14 -0
- data/app/models/concerns/foreman_dlm/host_monitoring_extensions.rb +36 -0
- data/app/models/dlmlock/update.rb +5 -0
- data/app/models/dlmlock.rb +79 -0
- data/app/views/api/v2/dlmlocks/acquire.json.rabl +3 -0
- data/app/views/api/v2/dlmlocks/base.json.rabl +3 -0
- data/app/views/api/v2/dlmlocks/create.json.rabl +3 -0
- data/app/views/api/v2/dlmlocks/index.json.rabl +3 -0
- data/app/views/api/v2/dlmlocks/main.json.rabl +7 -0
- data/app/views/api/v2/dlmlocks/release.json.rabl +3 -0
- data/app/views/api/v2/dlmlocks/show.json.rabl +8 -0
- data/app/views/api/v2/dlmlocks/update.json.rabl +3 -0
- data/app/views/api/v2/errors/precondition_failed.json.rabl +5 -0
- data/app/views/dlmlocks/_details.html.erb +35 -0
- data/app/views/dlmlocks/_list.html.erb +45 -0
- data/app/views/dlmlocks/index.html.erb +2 -0
- data/app/views/dlmlocks/show.html.erb +7 -0
- data/app/views/dlmlocks/welcome.html.erb +14 -0
- data/config/routes.rb +25 -0
- data/db/migrate/20170824084100_add_dlmlock.foreman_dlm.rb +12 -0
- data/lib/foreman_dlm/engine.rb +76 -0
- data/lib/foreman_dlm/version.rb +3 -0
- data/lib/foreman_dlm.rb +4 -0
- data/lib/tasks/foreman_dlm_tasks.rake +37 -0
- data/locale/Makefile +60 -0
- data/locale/en/foreman_dlm.po +19 -0
- data/locale/foreman_dlm.pot +19 -0
- data/locale/gemspec.rb +2 -0
- data/test/controllers/api/v2/dlmlocks_controller_test.rb +367 -0
- data/test/controllers/dlmlocks_test.rb +24 -0
- data/test/controllers/find_host_by_client_cert_test.rb +91 -0
- data/test/factories/dlmlock.rb +6 -0
- data/test/models/dlmlock_test.rb +201 -0
- data/test/models/host_monitoring_test.rb +42 -0
- data/test/test_plugin_helper.rb +9 -0
- metadata +124 -0
@@ -0,0 +1,45 @@
|
|
1
|
+
<table class="<%= table_css_classes('table-fixed') %>">
|
2
|
+
<thead>
|
3
|
+
<tr>
|
4
|
+
<th><%= sort :name, :as => _("Name") %></th>
|
5
|
+
<th><%= sort :host, :as => _("Owner") %></th>
|
6
|
+
<th><%= sort :type, :as => _("Type") %></th>
|
7
|
+
<th><%= sort :enabled, :as => _("Enabled") %></th>
|
8
|
+
</tr>
|
9
|
+
</thead>
|
10
|
+
<tbody>
|
11
|
+
<% for lock in @dlmlocks %>
|
12
|
+
<tr class="<%= lock.enabled? ? '' : 'warning' %>">
|
13
|
+
<td>
|
14
|
+
<%= icon_text(dlmlock_status_icon_class(lock),
|
15
|
+
link_to_if_authorized(lock.name, hash_for_dlmlock_path(:id => lock)),
|
16
|
+
kind: 'fa',
|
17
|
+
class: "#{dlmlock_status_icon_color_class(lock)} fa-lg")
|
18
|
+
%>
|
19
|
+
</td>
|
20
|
+
<td>
|
21
|
+
<% if lock.host.present? %>
|
22
|
+
<%= icon_text('server',
|
23
|
+
link_to_if_authorized(
|
24
|
+
lock.host,
|
25
|
+
hash_for_host_path(:id => lock.host),
|
26
|
+
:title => lock.host.name
|
27
|
+
),
|
28
|
+
kind: 'pficon') %>
|
29
|
+
<% end %>
|
30
|
+
</td>
|
31
|
+
<td>
|
32
|
+
<%= lock.humanized_type %>
|
33
|
+
</td>
|
34
|
+
<td>
|
35
|
+
<% if lock.enabled? %>
|
36
|
+
<%= icon_text('toggle-on', 'Enabled', {kind: 'fa', class: 'center text-success fa-lg', title: _('Enabled')}) %>
|
37
|
+
<% else %>
|
38
|
+
<%= icon_text('toggle-off', 'Disabled', {kind: 'fa', class: 'center fa-lg', title: _('Disabled')}) %>
|
39
|
+
<% end %>
|
40
|
+
</td>
|
41
|
+
</tr>
|
42
|
+
<% end %>
|
43
|
+
</tbody>
|
44
|
+
</table>
|
45
|
+
<%= will_paginate_with_info @dlmlocks %>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<div class="blank-slate-pf">
|
2
|
+
<div class="blank-slate-pf-icon">
|
3
|
+
<%= icon_text('lock', '', :kind => 'fa') %>
|
4
|
+
</div>
|
5
|
+
<h1><%= _('Locks') %></h1>
|
6
|
+
<p>
|
7
|
+
<%= _('You don\'t seem to have any locks.') %></br>
|
8
|
+
<%= _('The distributed lock manager allows you to automatically schedule system updates across a cluster of hosts.') %>
|
9
|
+
<%= link_to _('Learn more about this in the documentation.'), 'https://github.com/timogoebel/foreman_dlm', :rel => "external" %>.
|
10
|
+
</p>
|
11
|
+
<div class="blank-slate-pf-main-action">
|
12
|
+
<%= link_to _('Documentation'), 'https://github.com/timogoebel/foreman_dlm', :rel => 'external', :class => 'btn btn-primary btn-lg' %>
|
13
|
+
</div>
|
14
|
+
</div>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Rails.application.routes.draw do
|
2
|
+
namespace :api, :defaults => { :format => 'json' } do
|
3
|
+
scope '(:apiv)', :module => :v2,
|
4
|
+
:defaults => { :apiv => 'v2' },
|
5
|
+
:apiv => /v1|v2/,
|
6
|
+
:constraints => ApiConstraints.new(:version => 2, :default => true) do
|
7
|
+
constraints(id: /[^\/]+/) do
|
8
|
+
resources :dlmlocks, only: [:index, :show, :update, :destroy] do
|
9
|
+
get :lock, on: :member, action: :show, controller: 'dlmlocks'
|
10
|
+
put :lock, on: :member, action: :acquire, controller: 'dlmlocks'
|
11
|
+
delete :lock, on: :member, action: :release, controller: 'dlmlocks'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
resources :dlmlocks, only: [:create]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
scope '/foreman_dlm' do
|
19
|
+
resources :dlmlocks, only: [:index, :show] do
|
20
|
+
collection do
|
21
|
+
get 'auto_complete_search'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class AddDlmlock < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :dlmlocks do |t|
|
4
|
+
t.string :name, null: false, unique: true
|
5
|
+
t.string :type, index: true
|
6
|
+
t.boolean :enabled, null: false, default: true, index: true
|
7
|
+
t.integer :host_id, index: true
|
8
|
+
|
9
|
+
t.timestamps
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module ForemanDlm
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
engine_name 'foreman_dlm'
|
4
|
+
|
5
|
+
config.autoload_paths += Dir["#{config.root}/app/controllers/concerns"]
|
6
|
+
config.autoload_paths += Dir["#{config.root}/app/models/concerns"]
|
7
|
+
|
8
|
+
# Add any db migrations
|
9
|
+
initializer 'foreman_dlm.load_app_instance_data' do |app|
|
10
|
+
ForemanDlm::Engine.paths['db/migrate'].existent.each do |path|
|
11
|
+
app.config.paths['db/migrate'] << path
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
initializer 'foreman_dlm.register_plugin', :before => :finisher_hook do |_app|
|
16
|
+
Foreman::Plugin.register :foreman_dlm do
|
17
|
+
requires_foreman '>= 1.15'
|
18
|
+
|
19
|
+
apipie_documented_controllers ["#{ForemanDlm::Engine.root}/app/controllers/api/v2/*.rb"]
|
20
|
+
|
21
|
+
# Add permissions
|
22
|
+
security_block :foreman_dlm do
|
23
|
+
permission :view_dlmlocks, {
|
24
|
+
:dlmlocks => [:index, :show, :auto_complete_search],
|
25
|
+
:'api/v2/dlmlocks' => [:index, :show]
|
26
|
+
}, :resource_type => 'Dlmlock'
|
27
|
+
|
28
|
+
permission :create_dlmlocks, {
|
29
|
+
:'api/v2/dlmlocks' => [:create]
|
30
|
+
}, :resource_type => 'Dlmlock'
|
31
|
+
|
32
|
+
permission :edit_dlmlocks, {
|
33
|
+
:'api/v2/dlmlocks' => [:update, :acquire, :release]
|
34
|
+
}, :resource_type => 'Dlmlock'
|
35
|
+
|
36
|
+
permission :destroy_dlmlocks, {
|
37
|
+
:'api/v2/dlmlocks' => [:destroy]
|
38
|
+
}, :resource_type => 'Dlmlock'
|
39
|
+
end
|
40
|
+
|
41
|
+
# Add a new role called 'Distributed Lock Manager' if it doesn't exist
|
42
|
+
role 'Distributed Lock Manager', [:view_dlmlocks, :create_dlmlocks, :edit_dlmlocks, :destroy_dlmlocks]
|
43
|
+
|
44
|
+
# add menu entry
|
45
|
+
menu :top_menu, :distributed_locks,
|
46
|
+
url_hash: { controller: :'dlmlocks', action: :index },
|
47
|
+
caption: N_('Distributed Locks'),
|
48
|
+
parent: :monitor_menu,
|
49
|
+
after: :audits
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Include concerns in this config.to_prepare block
|
54
|
+
config.to_prepare do
|
55
|
+
begin
|
56
|
+
Host::Managed.send(:include, ForemanDlm::HostExtensions)
|
57
|
+
|
58
|
+
if ForemanDlm.with_monitoring?
|
59
|
+
Host::Managed.send(:include, ForemanDlm::HostMonitoringExtensions)
|
60
|
+
end
|
61
|
+
rescue => e
|
62
|
+
Rails.logger.warn "ForemanDlm: skipping engine hook (#{e})"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
initializer 'foreman_dlm.register_gettext', after: :load_config_initializers do |_app|
|
67
|
+
locale_dir = File.join(File.expand_path('../../..', __FILE__), 'locale')
|
68
|
+
locale_domain = 'foreman_dlm'
|
69
|
+
Foreman::Gettext::Support.add_text_domain locale_domain, locale_dir
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.with_monitoring?
|
74
|
+
(ForemanMonitoring rescue false) ? true : false
|
75
|
+
end
|
76
|
+
end
|
data/lib/foreman_dlm.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'rake/testtask'
|
2
|
+
|
3
|
+
# Tests
|
4
|
+
namespace :test do
|
5
|
+
desc 'Test ForemanDlm'
|
6
|
+
Rake::TestTask.new(:foreman_dlm) do |t|
|
7
|
+
test_dir = File.join(File.dirname(__FILE__), '../..', 'test')
|
8
|
+
t.libs << ['test', test_dir]
|
9
|
+
t.pattern = "#{test_dir}/**/*_test.rb"
|
10
|
+
t.verbose = true
|
11
|
+
t.warning = false
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
namespace :foreman_dlm do
|
16
|
+
task :rubocop do
|
17
|
+
begin
|
18
|
+
require 'rubocop/rake_task'
|
19
|
+
RuboCop::RakeTask.new(:rubocop_foreman_dlm) do |task|
|
20
|
+
task.patterns = ["#{ForemanDlm::Engine.root}/app/**/*.rb",
|
21
|
+
"#{ForemanDlm::Engine.root}/lib/**/*.rb",
|
22
|
+
"#{ForemanDlm::Engine.root}/test/**/*.rb"]
|
23
|
+
end
|
24
|
+
rescue
|
25
|
+
puts 'Rubocop not loaded.'
|
26
|
+
end
|
27
|
+
|
28
|
+
Rake::Task['rubocop_foreman_dlm'].invoke
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
Rake::Task[:test].enhance ['test:foreman_dlm']
|
33
|
+
|
34
|
+
load 'tasks/jenkins.rake'
|
35
|
+
if Rake::Task.task_defined?(:'jenkins:unit')
|
36
|
+
Rake::Task['jenkins:unit'].enhance ['test:foreman_dlm', 'foreman_dlm:rubocop']
|
37
|
+
end
|
data/locale/Makefile
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
#
|
2
|
+
# Makefile for PO merging and MO generation. More info in the README.
|
3
|
+
#
|
4
|
+
# make all-mo (default) - generate MO files
|
5
|
+
# make check - check translations using translate-tool
|
6
|
+
# make tx-update - download and merge translations from Transifex
|
7
|
+
# make clean - clean everything
|
8
|
+
#
|
9
|
+
DOMAIN = foreman_dlm
|
10
|
+
VERSION = $(shell ruby -e 'require "rubygems";spec = Gem::Specification::load(Dir.glob("../*.gemspec")[0]);puts spec.version')
|
11
|
+
POTFILE = $(DOMAIN).pot
|
12
|
+
MOFILE = $(DOMAIN).mo
|
13
|
+
POFILES = $(shell find . -name '$(DOMAIN).po')
|
14
|
+
MOFILES = $(patsubst %.po,%.mo,$(POFILES))
|
15
|
+
POXFILES = $(patsubst %.po,%.pox,$(POFILES))
|
16
|
+
EDITFILES = $(patsubst %.po,%.edit.po,$(POFILES))
|
17
|
+
|
18
|
+
%.mo: %.po
|
19
|
+
mkdir -p $(shell dirname $@)/LC_MESSAGES
|
20
|
+
msgfmt -o $(shell dirname $@)/LC_MESSAGES/$(MOFILE) $<
|
21
|
+
|
22
|
+
# Generate MO files from PO files
|
23
|
+
all-mo: $(MOFILES)
|
24
|
+
|
25
|
+
# Check for malformed strings
|
26
|
+
%.pox: %.po
|
27
|
+
msgfmt -c $<
|
28
|
+
pofilter --nofuzzy -t variables -t blank -t urls -t emails -t long -t newlines \
|
29
|
+
-t endwhitespace -t endpunc -t puncspacing -t options -t printf -t validchars --gnome $< > $@
|
30
|
+
cat $@
|
31
|
+
! grep -q msgid $@
|
32
|
+
|
33
|
+
%.edit.po:
|
34
|
+
touch $@
|
35
|
+
|
36
|
+
check: $(POXFILES)
|
37
|
+
|
38
|
+
# Unify duplicate translations
|
39
|
+
uniq-po:
|
40
|
+
for f in $(shell find ./ -name "*.po") ; do \
|
41
|
+
msguniq $$f -o $$f ; \
|
42
|
+
done
|
43
|
+
|
44
|
+
tx-pull: $(EDITFILES)
|
45
|
+
tx pull -f
|
46
|
+
for f in $(EDITFILES) ; do \
|
47
|
+
sed -i 's/^\("Project-Id-Version: \).*$$/\1$(DOMAIN) $(VERSION)\\n"/' $$f; \
|
48
|
+
done
|
49
|
+
|
50
|
+
tx-update: tx-pull
|
51
|
+
@echo
|
52
|
+
@echo Run rake plugin:gettext[$(DOMAIN)] from the Foreman installation, then make -C locale mo-files to finish
|
53
|
+
@echo
|
54
|
+
|
55
|
+
mo-files: $(MOFILES)
|
56
|
+
git add $(POFILES) $(POTFILE) ../locale/*/LC_MESSAGES
|
57
|
+
git commit -m "i18n - pulling from tx"
|
58
|
+
@echo
|
59
|
+
@echo Changes commited!
|
60
|
+
@echo
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# foreman_dlm
|
2
|
+
#
|
3
|
+
# This file is distributed under the same license as foreman_dlm.
|
4
|
+
#
|
5
|
+
#, fuzzy
|
6
|
+
msgid ""
|
7
|
+
msgstr ""
|
8
|
+
"Project-Id-Version: version 0.0.1\n"
|
9
|
+
"Report-Msgid-Bugs-To: \n"
|
10
|
+
"POT-Creation-Date: 2014-08-20 08:46+0100\n"
|
11
|
+
"PO-Revision-Date: 2014-08-20 08:54+0100\n"
|
12
|
+
"Last-Translator: Foreman Team <foreman-dev@googlegroups.com>\n"
|
13
|
+
"Language-Team: Foreman Team <foreman-dev@googlegroups.com>\n"
|
14
|
+
"Language: \n"
|
15
|
+
"MIME-Version: 1.0\n"
|
16
|
+
"Content-Type: text/plain; charset=UTF-8\n"
|
17
|
+
"Content-Transfer-Encoding: 8bit\n"
|
18
|
+
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
19
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# foreman_dlm
|
2
|
+
#
|
3
|
+
# This file is distributed under the same license as foreman_dlm.
|
4
|
+
#
|
5
|
+
#, fuzzy
|
6
|
+
msgid ""
|
7
|
+
msgstr ""
|
8
|
+
"Project-Id-Version: version 0.0.1\n"
|
9
|
+
"Report-Msgid-Bugs-To: \n"
|
10
|
+
"POT-Creation-Date: 2014-08-20 08:46+0100\n"
|
11
|
+
"PO-Revision-Date: 2014-08-20 08:46+0100\n"
|
12
|
+
"Last-Translator: Foreman Team <foreman-dev@googlegroups.com>\n"
|
13
|
+
"Language-Team: Foreman Team <foreman-dev@googlegroups.com>\n"
|
14
|
+
"Language: \n"
|
15
|
+
"MIME-Version: 1.0\n"
|
16
|
+
"Content-Type: text/plain; charset=UTF-8\n"
|
17
|
+
"Content-Transfer-Encoding: 8bit\n"
|
18
|
+
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
|
19
|
+
|
data/locale/gemspec.rb
ADDED