foreman_dlm 1.1.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 +8 -4
- data/Rakefile +4 -2
- data/app/controllers/api/v2/dlmlock_events_controller.rb +3 -0
- data/app/controllers/api/v2/dlmlocks_controller.rb +17 -13
- data/app/controllers/concerns/foreman/controller/parameters/dlmlocks.rb +2 -0
- data/app/controllers/concerns/foreman_dlm/find_host_by_client_cert.rb +6 -10
- data/app/controllers/concerns/foreman_dlm/find_host_by_ip.rb +2 -0
- data/app/controllers/concerns/foreman_dlm/update_checkin_time.rb +3 -0
- data/app/controllers/foreman_dlm/application_controller.rb +2 -0
- data/app/controllers/foreman_dlm/dlmlocks_controller.rb +4 -1
- data/app/helpers/foreman_dlm/dlmlock_helper.rb +4 -0
- data/app/jobs/foreman_dlm/refresh_dlmlock_status.rb +2 -0
- data/app/models/concerns/foreman_dlm/dlm_facet_host_extensions.rb +2 -0
- data/app/models/concerns/foreman_dlm/expirable.rb +3 -0
- data/app/models/concerns/foreman_dlm/host_extensions.rb +17 -8
- data/app/models/concerns/foreman_dlm/host_monitoring_extensions.rb +5 -1
- data/app/models/concerns/foreman_dlm/user_extensions.rb +6 -4
- data/app/models/foreman_dlm/dlm_facet.rb +2 -0
- data/app/models/foreman_dlm/dlmlock/update.rb +2 -0
- data/app/models/foreman_dlm/dlmlock.rb +14 -11
- data/app/models/foreman_dlm/dlmlock_event.rb +2 -0
- data/app/models/host_status/dlmlock_status.rb +2 -0
- data/app/views/api/v2/dlmlock_events/index.json.rabl +2 -0
- data/app/views/api/v2/dlmlocks/acquire.json.rabl +2 -0
- data/app/views/api/v2/dlmlocks/base.json.rabl +2 -0
- data/app/views/api/v2/dlmlocks/create.json.rabl +2 -0
- data/app/views/api/v2/dlmlocks/index.json.rabl +2 -0
- data/app/views/api/v2/dlmlocks/main.json.rabl +2 -0
- data/app/views/api/v2/dlmlocks/release.json.rabl +2 -0
- data/app/views/api/v2/dlmlocks/show.json.rabl +2 -0
- data/app/views/api/v2/dlmlocks/update.json.rabl +2 -0
- data/app/views/api/v2/errors/precondition_failed.json.rabl +2 -0
- data/app/views/foreman_dlm/api/v2/dlm_facets/base.json.rabl +2 -0
- data/app/views/foreman_dlm/api/v2/dlm_facets/base_with_root.json.rabl +2 -0
- data/app/views/foreman_dlm/api/v2/dlm_facets/show.json.rabl +2 -0
- data/app/views/foreman_dlm/dlmlocks/index.html.erb +1 -1
- data/app/views/foreman_dlm/dlmlocks/show.html.erb +1 -1
- data/app/views/foreman_dlm/dlmlocks/welcome.html.erb +2 -2
- data/app/views/hosts/_dlmlocks_tab.html.erb +3 -3
- data/config/routes.rb +2 -0
- data/db/migrate/20170824084100_add_dlmlock.foreman_dlm.rb +2 -0
- data/db/migrate/20180627150003_rename_dlmlock_sti_models.rb +2 -0
- data/db/migrate/20180704162345_add_dlmlock_events.rb +2 -0
- data/db/migrate/20180711090022_add_hosts_fk_to_dlmlocks.rb +2 -0
- data/db/migrate/20180711111903_create_dlm_facets.foreman_dlm.rb +2 -0
- data/db/migrate/20180713113208_update_permissions_for_scoped_models.rb +2 -0
- data/lib/foreman_dlm/engine.rb +37 -33
- data/lib/foreman_dlm/version.rb +3 -1
- data/lib/foreman_dlm.rb +2 -0
- data/lib/tasks/dlmlock_events.rake +2 -0
- data/lib/tasks/foreman_dlm_tasks.rake +2 -20
- data/locale/gemspec.rb +3 -1
- data/test/controllers/api/v2/dlmlocks_controller_test.rb +22 -20
- data/test/controllers/api/v2/dlmlocks_dlmlock_events_controller_test.rb +2 -0
- data/test/controllers/api/v2/hosts_controller_test.rb +2 -0
- data/test/controllers/find_host_by_client_cert_test.rb +5 -3
- data/test/controllers/foreman_dlm/dlmlocks_test.rb +4 -2
- data/test/controllers/hosts_controller_test.rb +3 -1
- data/test/factories/dlm_facets.rb +2 -0
- data/test/factories/dlmlock.rb +3 -1
- data/test/factories/dlmlock_events.rb +3 -1
- data/test/factories/host.rb +2 -0
- data/test/integration/foreman_dlm/dlmlocks_test.rb +29 -0
- data/test/jobs/refresh_dlmlock_status_test.rb +2 -0
- data/test/models/foreman_dlm/dlm_facet_test.rb +2 -0
- data/test/models/foreman_dlm/dlmlock_event_test.rb +2 -0
- data/test/models/foreman_dlm/dlmlock_test.rb +41 -31
- data/test/models/host_managed_test.rb +20 -0
- data/test/models/host_monitoring_test.rb +2 -0
- data/test/models/host_status/dlmlock_status_test.rb +4 -8
- data/test/models/user_test.rb +2 -0
- data/test/test_plugin_helper.rb +6 -0
- data/test/unit/foreman_dlm/access_permissions_test.rb +18 -0
- metadata +36 -29
- data/app/models/settings/dlm.rb +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cbea781adcb410612c6d6fde4e13f116f31f50f393ac518c55cdf8ff0bc0ab22
|
4
|
+
data.tar.gz: 201b1a484408da1971ebd7b33285d5738a1a707bd84ec06a04ed05510c85d065
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 961720c5a51b86f720e61f1463bc9b413419be9876d93d36070053d14961db07b9f42f0a82c99c0b917f621296b401da1caf49f123882402e943d8994228f734
|
7
|
+
data.tar.gz: c9cab6e1b37b3321ce4d862dc8599f9af2d8b9b5ce911eaa4141f28816364cfed1d29e372cbe5a1583df2876d47681b7c4c66c70c11dc5ef3164611965ccd99b
|
data/README.md
CHANGED
@@ -14,6 +14,8 @@ With this plugin servers can acquire a lock in Foreman to ensure only one server
|
|
14
14
|
| --------------- | -------------- |
|
15
15
|
| >= 1.15 | ~> 0.1 |
|
16
16
|
| >= 1.17 | ~> 1.0 |
|
17
|
+
| >= 3.0 | ~> 2.0 |
|
18
|
+
| >= 3.9 | ~> 3.0 |
|
17
19
|
|
18
20
|
## Installation
|
19
21
|
|
@@ -34,6 +36,7 @@ Use the HTTP method `GET` to show a lock, `PUT` to acquire a lock and `DELETE` t
|
|
34
36
|
Foreman will respond with the HTTP status code `200 OK` if the action was successful and `412 Precondition Failed` if the lock could not be acquired or release. This may happen, if the lock is taken by another host.
|
35
37
|
|
36
38
|
To process the HTTP status code in a bash script, you can do something like this:
|
39
|
+
|
37
40
|
```
|
38
41
|
curl --write-out %{http_code} -H 'Content-Type: application/json' -sS -o /dev/null -X PUT --key $(puppet config print hostprivkey) --cert $(puppet config print hostcert) https://foreman.example.com/api/dlmlocks/test/lock
|
39
42
|
```
|
@@ -59,17 +62,19 @@ $ brew link curl --force
|
|
59
62
|
```
|
60
63
|
|
61
64
|
After that `curl --version` changes from
|
65
|
+
|
62
66
|
```
|
63
67
|
$ curl --version
|
64
68
|
curl 7.54.0 (x86_64-apple-darwin16.0) libcurl/7.54.0 SecureTransport zlib/1.2.8
|
65
69
|
```
|
70
|
+
|
66
71
|
to
|
72
|
+
|
67
73
|
```
|
68
74
|
$ curl --version
|
69
75
|
curl 7.56.1 (x86_64-apple-darwin16.7.0) libcurl/7.56.1 OpenSSL/1.0.2m zlib/1.2.8
|
70
76
|
```
|
71
77
|
|
72
|
-
|
73
78
|
## Contributing
|
74
79
|
|
75
80
|
Fork and send a Pull Request. Thanks!
|
@@ -85,9 +90,8 @@ the Free Software Foundation, either version 3 of the License, or
|
|
85
90
|
|
86
91
|
This program is distributed in the hope that it will be useful,
|
87
92
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
88
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
93
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
89
94
|
GNU General Public License for more details.
|
90
95
|
|
91
96
|
You should have received a copy of the GNU General Public License
|
92
|
-
along with this program.
|
93
|
-
|
97
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
data/Rakefile
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
2
4
|
begin
|
3
5
|
require 'bundler/setup'
|
4
6
|
rescue LoadError
|
@@ -20,7 +22,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
|
|
20
22
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
23
|
end
|
22
24
|
|
23
|
-
APP_RAKEFILE = File.expand_path('
|
25
|
+
APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__)
|
24
26
|
|
25
27
|
Bundler::GemHelper.install_tasks
|
26
28
|
|
@@ -38,7 +40,7 @@ task default: :test
|
|
38
40
|
begin
|
39
41
|
require 'rubocop/rake_task'
|
40
42
|
RuboCop::RakeTask.new
|
41
|
-
rescue
|
43
|
+
rescue StandardError
|
42
44
|
puts 'Rubocop not loaded.'
|
43
45
|
end
|
44
46
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Api
|
2
4
|
module V2
|
3
5
|
class DlmlockEventsController < V2::BaseController
|
@@ -34,6 +36,7 @@ module Api
|
|
34
36
|
def resource_class_for(resource)
|
35
37
|
return ForemanDlm::Dlmlock if resource == 'dlmlock'
|
36
38
|
return ForemanDlm::DlmlockEvent if resource == 'dlmlock_event'
|
39
|
+
|
37
40
|
super
|
38
41
|
end
|
39
42
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Api
|
2
4
|
module V2
|
3
5
|
class DlmlocksController < V2::BaseController
|
@@ -37,7 +39,8 @@ module Api
|
|
37
39
|
error 404, 'Lock could not be found.'
|
38
40
|
param :id, String, :required => true, :desc => N_('Id or name of the DLM lock')
|
39
41
|
|
40
|
-
def show
|
42
|
+
def show
|
43
|
+
end
|
41
44
|
|
42
45
|
api :POST, '/dlmlocks', N_('Create a DLM lock')
|
43
46
|
param_group :dlmlock, :as => :create
|
@@ -52,7 +55,7 @@ module Api
|
|
52
55
|
param_group :dlmlock
|
53
56
|
|
54
57
|
def update
|
55
|
-
process_response @dlmlock.
|
58
|
+
process_response @dlmlock.update(dlmlocks_params)
|
56
59
|
end
|
57
60
|
|
58
61
|
api :DELETE, '/dlmlocks/:id/', N_('Delete a DLM lock')
|
@@ -73,7 +76,7 @@ module Api
|
|
73
76
|
|
74
77
|
== Authentication & Host Identification
|
75
78
|
The host is authenticated via a client certificate and identified via the CN of that certificate.
|
76
|
-
|
79
|
+
DOCS
|
77
80
|
|
78
81
|
def acquire
|
79
82
|
process_lock_response @dlmlock.acquire!(@host)
|
@@ -91,7 +94,7 @@ module Api
|
|
91
94
|
|
92
95
|
== Authentication & Host Identification
|
93
96
|
The host is authenticated via a client certificate and identified via the CN of that certificate.
|
94
|
-
|
97
|
+
DOCS
|
95
98
|
|
96
99
|
def release
|
97
100
|
process_lock_response @dlmlock.release!(@host)
|
@@ -108,6 +111,7 @@ module Api
|
|
108
111
|
rescue ActiveRecord::RecordNotFound
|
109
112
|
result = scope.find_by(:name => id)
|
110
113
|
raise ActiveRecord::RecordNotFound unless result
|
114
|
+
|
111
115
|
result
|
112
116
|
end
|
113
117
|
|
@@ -132,16 +136,16 @@ module Api
|
|
132
136
|
logger.info 'Denying access because no host could be detected.'
|
133
137
|
if User.current
|
134
138
|
render_error 'access_denied',
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
+
:status => :forbidden,
|
140
|
+
:locals => {
|
141
|
+
:details => 'You need to authenticate with a valid client cert. The DN has to match a known host.',
|
142
|
+
}
|
139
143
|
else
|
140
144
|
render_error 'unauthorized',
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
+
:status => :unauthorized,
|
146
|
+
:locals => {
|
147
|
+
:user_login => get_client_cert_hostname,
|
148
|
+
}
|
145
149
|
end
|
146
150
|
end
|
147
151
|
true
|
@@ -162,7 +166,7 @@ module Api
|
|
162
166
|
deny_access
|
163
167
|
else
|
164
168
|
render_error 'precondition_failed', :status => :precondition_failed, :locals => {
|
165
|
-
:message => 'Precondition failed. Lock is in invalid state for this operation.'
|
169
|
+
:message => 'Precondition failed. Lock is in invalid state for this operation.',
|
166
170
|
}
|
167
171
|
end
|
168
172
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ForemanDlm
|
2
4
|
module FindHostByClientCert
|
3
5
|
extend ActiveSupport::Concern
|
@@ -46,17 +48,11 @@ module ForemanDlm
|
|
46
48
|
end
|
47
49
|
|
48
50
|
def get_client_cert_hostname
|
49
|
-
|
50
|
-
unless
|
51
|
-
logger.info { "Client certificate is invalid: #{verify}" }
|
52
|
-
return
|
53
|
-
end
|
54
|
-
|
55
|
-
dn = request.env[Setting[:ssl_client_dn_env]]
|
56
|
-
return unless dn && dn =~ /CN=([^\s\/,]+)/i
|
51
|
+
client_certificate = Foreman::ClientCertificate.new(request: request)
|
52
|
+
return unless client_certificate.verified?
|
57
53
|
|
58
|
-
hostname =
|
59
|
-
logger.debug "Extracted hostname '#{hostname}' from client certificate."
|
54
|
+
hostname = client_certificate.subject
|
55
|
+
logger.debug "Extracted hostname '#{hostname}' from client certificate." if hostname
|
60
56
|
hostname
|
61
57
|
end
|
62
58
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ForemanDlm
|
2
4
|
module UpdateCheckinTime
|
3
5
|
extend ActiveSupport::Concern
|
@@ -13,6 +15,7 @@ module ForemanDlm
|
|
13
15
|
# Updates the last_checkin timestamp of a user
|
14
16
|
def update_detected_host_checkin_time
|
15
17
|
return unless @detected_host
|
18
|
+
|
16
19
|
facet = @detected_host.dlm_facet || @detected_host.build_dlm_facet
|
17
20
|
facet.save unless facet.persisted?
|
18
21
|
facet.touch(:last_checkin_at)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ForemanDlm
|
2
4
|
class DlmlocksController < ::ForemanDlm::ApplicationController
|
3
5
|
include ::Foreman::Controller::AutoCompleteSearch
|
@@ -9,7 +11,8 @@ module ForemanDlm
|
|
9
11
|
@dlmlocks = resource_base_search_and_page(:host)
|
10
12
|
end
|
11
13
|
|
12
|
-
def show
|
14
|
+
def show
|
15
|
+
end
|
13
16
|
|
14
17
|
def destroy
|
15
18
|
if @dlmlock.destroy
|
@@ -1,14 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ForemanDlm
|
2
4
|
module DlmlockHelper
|
3
5
|
def dlmlock_status_icon_class(lock)
|
4
6
|
return 'ban' if lock.disabled?
|
5
7
|
return 'lock' if lock.taken?
|
8
|
+
|
6
9
|
'unlock'
|
7
10
|
end
|
8
11
|
|
9
12
|
def dlmlock_status_icon_color_class(lock)
|
10
13
|
return 'text-danger' if lock.disabled?
|
11
14
|
return 'text-success' if lock.taken?
|
15
|
+
|
12
16
|
'text-info'
|
13
17
|
end
|
14
18
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ForemanDlm
|
2
4
|
module Expirable
|
3
5
|
extend ActiveSupport::Concern
|
@@ -22,6 +24,7 @@ module ForemanDlm
|
|
22
24
|
total_count += count
|
23
25
|
|
24
26
|
break if event_ids.blank?
|
27
|
+
|
25
28
|
sleep sleep_time
|
26
29
|
end
|
27
30
|
duration = ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time) / 60).to_i
|
@@ -1,24 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ForemanDlm
|
2
4
|
module HostExtensions
|
3
5
|
extend ActiveSupport::Concern
|
4
6
|
|
5
7
|
included do
|
6
8
|
has_many :dlmlocks,
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
class_name: 'ForemanDlm::Dlmlock',
|
10
|
+
foreign_key: 'host_id',
|
11
|
+
dependent: :nullify,
|
12
|
+
inverse_of: :host
|
11
13
|
|
12
14
|
has_many :dlmlock_events,
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
class_name: 'ForemanDlm::DlmlockEvent',
|
16
|
+
foreign_key: 'host_id',
|
17
|
+
dependent: :destroy,
|
18
|
+
inverse_of: :host
|
17
19
|
|
18
20
|
define_model_callbacks :lock, :only => :after
|
19
21
|
define_model_callbacks :unlock, :only => :after
|
20
22
|
end
|
21
23
|
|
24
|
+
def can_acquire_update_locks?
|
25
|
+
param = host_param('can_acquire_update_locks')
|
26
|
+
return true if param.blank?
|
27
|
+
|
28
|
+
Foreman::Cast.to_bool(param)
|
29
|
+
end
|
30
|
+
|
22
31
|
def refresh_dlmlock_status
|
23
32
|
refresh_statuses([HostStatus::DlmlockStatus])
|
24
33
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ForemanDlm
|
2
4
|
module HostMonitoringExtensions
|
3
5
|
extend ActiveSupport::Concern
|
@@ -9,6 +11,7 @@ module ForemanDlm
|
|
9
11
|
|
10
12
|
def add_lock_monitoring_downtime
|
11
13
|
return unless monitored?
|
14
|
+
|
12
15
|
logger.info "Setting Monitoring downtime for #{self}"
|
13
16
|
monitoring.set_downtime_host(self, lock_monitoring_downtime_options)
|
14
17
|
true
|
@@ -18,6 +21,7 @@ module ForemanDlm
|
|
18
21
|
|
19
22
|
def remove_lock_monitoring_downtime
|
20
23
|
return unless monitored?
|
24
|
+
|
21
25
|
logger.info "Deleting Monitoring downtime for #{self}"
|
22
26
|
monitoring.del_downtime_host(self, lock_monitoring_downtime_options)
|
23
27
|
true
|
@@ -29,7 +33,7 @@ module ForemanDlm
|
|
29
33
|
{
|
30
34
|
comment: _('Host acquired lock.'),
|
31
35
|
start_time: Time.current.to_i,
|
32
|
-
end_time: Time.current.advance(:minutes => 180).to_i
|
36
|
+
end_time: Time.current.advance(:minutes => 180).to_i,
|
33
37
|
}
|
34
38
|
end
|
35
39
|
end
|
@@ -1,13 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ForemanDlm
|
2
4
|
module UserExtensions
|
3
5
|
extend ActiveSupport::Concern
|
4
6
|
|
5
7
|
included do
|
6
8
|
has_many :dlmlock_events,
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
class_name: 'ForemanDlm::DlmlockEvent',
|
10
|
+
foreign_key: 'user_id',
|
11
|
+
dependent: :nullify,
|
12
|
+
inverse_of: :user
|
11
13
|
end
|
12
14
|
end
|
13
15
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ForemanDlm
|
2
4
|
class Dlmlock < ApplicationRecord
|
3
5
|
include Authorizable
|
@@ -7,16 +9,15 @@ module ForemanDlm
|
|
7
9
|
end
|
8
10
|
|
9
11
|
def self.dlm_stale_time
|
10
|
-
(Setting
|
12
|
+
(Setting[:dlm_stale_time] || 4).hours
|
11
13
|
end
|
12
14
|
|
13
15
|
belongs_to_host
|
14
16
|
|
15
17
|
has_many :dlmlock_events,
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
inverse_of: :dlmlock
|
18
|
+
class_name: '::ForemanDlm::DlmlockEvent',
|
19
|
+
dependent: :destroy,
|
20
|
+
inverse_of: :dlmlock
|
20
21
|
|
21
22
|
validates :name, presence: true, uniqueness: true
|
22
23
|
|
@@ -46,6 +47,8 @@ module ForemanDlm
|
|
46
47
|
attr_accessor :old
|
47
48
|
|
48
49
|
def acquire!(host)
|
50
|
+
return false unless host.can_acquire_update_locks?
|
51
|
+
|
49
52
|
result = atomic_update(nil, host)
|
50
53
|
ForemanDlm::RefreshDlmlockStatus.set(wait: self.class.dlm_stale_time).perform_later([host.id]) if result
|
51
54
|
result
|
@@ -66,7 +69,7 @@ module ForemanDlm
|
|
66
69
|
def locked_by?(host)
|
67
70
|
self.host == host
|
68
71
|
end
|
69
|
-
|
72
|
+
alias_method :acquired_by?, :locked_by?
|
70
73
|
|
71
74
|
def disabled?
|
72
75
|
!enabled?
|
@@ -75,7 +78,7 @@ module ForemanDlm
|
|
75
78
|
def locked?
|
76
79
|
host.present?
|
77
80
|
end
|
78
|
-
|
81
|
+
alias_method :taken?, :locked?
|
79
82
|
|
80
83
|
def humanized_type
|
81
84
|
_('Generic Lock')
|
@@ -90,7 +93,7 @@ module ForemanDlm
|
|
90
93
|
query = {
|
91
94
|
id: id,
|
92
95
|
host_id: [new_host.try(:id), old_host.try(:id)],
|
93
|
-
enabled: true
|
96
|
+
enabled: true,
|
94
97
|
}
|
95
98
|
|
96
99
|
updated = self.class.where(query).update(changes.merge(updated_at: Time.now.utc))
|
@@ -126,9 +129,9 @@ module ForemanDlm
|
|
126
129
|
)
|
127
130
|
end
|
128
131
|
|
129
|
-
def run_callback(
|
130
|
-
|
131
|
-
logger.debug { "custom hook after_#{callback} on #{
|
132
|
+
def run_callback(host, callback)
|
133
|
+
host.run_callbacks callback do
|
134
|
+
logger.debug { "custom hook after_#{callback} on #{host} will be executed if defined." }
|
132
135
|
true
|
133
136
|
end
|
134
137
|
end
|
@@ -1,2 +1,2 @@
|
|
1
|
-
<% title _(
|
1
|
+
<% title _('Distributed Locks') %>
|
2
2
|
<%= render :partial => 'list' %>
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<% title @dlmlock.name %>
|
2
2
|
<% breadcrumbs(
|
3
|
-
|
3
|
+
resource_url: api_dlmlocks_path
|
4
4
|
) if respond_to?(:breadcrumbs) # Requires Foreman >= 1.18 %>
|
5
5
|
|
6
6
|
<%= title_actions link_to(_('Back'), foreman_dlm_dlmlocks_path, :class => 'btn btn-default'),
|
@@ -6,9 +6,9 @@
|
|
6
6
|
<p>
|
7
7
|
<%= _('You don\'t seem to have any locks.') %></br>
|
8
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/
|
9
|
+
<%= link_to _('Learn more about this in the documentation.'), 'https://github.com/dm-drogeriemarkt/foreman_dlm', :rel => "external" %>.
|
10
10
|
</p>
|
11
11
|
<div class="blank-slate-pf-main-action">
|
12
|
-
<%= link_to _('Documentation'), 'https://github.com/
|
12
|
+
<%= link_to _('Documentation'), 'https://github.com/dm-drogeriemarkt/foreman_dlm', :rel => 'external', :class => 'btn btn-primary btn-lg' %>
|
13
13
|
</div>
|
14
14
|
</div>
|
@@ -2,14 +2,14 @@
|
|
2
2
|
<%= alert class: 'alert-info',
|
3
3
|
header: '',
|
4
4
|
text: n_(
|
5
|
-
'This host holds
|
5
|
+
'This host holds one lock.',
|
6
6
|
'This host holds %s locks.',
|
7
7
|
@host.dlmlocks.count
|
8
8
|
) % @host.dlmlocks.count
|
9
9
|
%>
|
10
10
|
<% end %>
|
11
11
|
|
12
|
-
<table class="<%= table_css_classes %>
|
12
|
+
<table class="<%= table_css_classes %>">
|
13
13
|
<thead>
|
14
14
|
<tr>
|
15
15
|
<th colspan="2"><%= _('Locks') %></th>
|
@@ -17,7 +17,7 @@
|
|
17
17
|
</thead>
|
18
18
|
<tbody>
|
19
19
|
<tr>
|
20
|
-
<td><%= _('Last
|
20
|
+
<td class="text-nowrap"><%= _('Last check-in') %></td>
|
21
21
|
<td><%= @host.dlm_facet && @host.dlm_facet.last_checkin_at ? date_time_relative(@host.dlm_facet.last_checkin_at) : _('N/A') %></td>
|
22
22
|
</tr>
|
23
23
|
<tr>
|