forked from theforeman/foreman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
status.rb
83 lines (63 loc) · 1.87 KB
/
status.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
module HostStatus
class Status < ApplicationRecord
prepend Foreman::STI
self.table_name = 'host_status'
belongs_to_host :inverse_of => :host_statuses
validates :host, :presence => true
validates :host_id, :uniqueness => {:scope => :type}
validates :reported_at, :presence => true
before_validation :update_timestamp, :if => ->(status) { status.reported_at.blank? }
class Jail < ::Safemode::Jail
allow :host, :to_global, :to_label, :status, :name, :relevant?
allow_class_method :status_name, :humanized_name
end
def to_global(options = {})
HostStatus::Global::OK
end
def to_label(options = {})
raise NotImplementedError, "Method 'to_label' method needs to be implemented"
end
def to_status(options = {})
raise NotImplementedError, "Method 'to_status' method needs to be implemented"
end
def self.status_name
raise NotImplementedError, "Method 'status_name' method needs to be implemented"
end
def name
self.class.status_name
end
def self.humanized_name
status_name.underscore
end
def refresh!
refresh
save!
end
def refresh
update_timestamp
update_status
end
# Whether this status should be displayed to users, it may not be relevant for certain
# types of hosts
def relevant?(options = {})
true
end
# a substatus is used by some other status in order to determine its own status
# this type of status does not affect the global status
def substatus?(options = {})
false
end
private
def update_timestamp
self.reported_at = Time.now.utc
end
def update_status
self.status = to_status
end
def remediation_help_text
nil
end
end
end
require_dependency 'host_status/configuration_status'
require_dependency 'host_status/build_status'