foreman_wreckingball 3.0.1 → 3.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/app/assets/javascripts/foreman_wreckingball/modal.js +26 -18
- data/app/assets/javascripts/foreman_wreckingball/status_hosts_table.js +81 -0
- data/app/assets/javascripts/foreman_wreckingball/status_managed_hosts_dashboard.js +14 -0
- data/app/assets/javascripts/foreman_wreckingball/status_row.js +17 -0
- data/app/assets/stylesheets/foreman_wreckingball/status_hosts_table.css.scss +13 -0
- data/app/assets/stylesheets/foreman_wreckingball/status_managed_hosts_dashboard.css.scss +8 -0
- data/app/controllers/foreman_wreckingball/hosts_controller.rb +143 -43
- data/app/helpers/concerns/foreman_wreckingball/hosts_helper_extensions.rb +0 -15
- data/app/helpers/foreman_wreckingball/statuses_helper.rb +21 -0
- data/app/lib/actions/foreman_wreckingball/bulk_remediate.rb +27 -0
- data/app/lib/actions/foreman_wreckingball/host/remediate_hardware_version.rb +63 -0
- data/app/lib/actions/foreman_wreckingball/host/remediate_spectre_v2.rb +58 -0
- data/app/lib/fog_extensions/foreman_wreckingball/vsphere/mock.rb +13 -0
- data/app/lib/fog_extensions/foreman_wreckingball/vsphere/real.rb +7 -0
- data/app/lib/fog_extensions/foreman_wreckingball/vsphere/server.rb +14 -0
- data/app/models/concerns/foreman_wreckingball/host_extensions.rb +10 -20
- data/app/models/concerns/foreman_wreckingball/host_status_extensions.rb +13 -0
- data/app/models/concerns/foreman_wreckingball/user_extensions.rb +12 -0
- data/app/models/concerns/foreman_wreckingball/usergroup_extensions.rb +18 -0
- data/app/models/concerns/foreman_wreckingball/vmware_facet_host_extensions.rb +10 -0
- data/app/models/foreman_wreckingball/cpu_hot_add_status.rb +8 -0
- data/app/models/foreman_wreckingball/hardware_version_status.rb +70 -0
- data/app/models/foreman_wreckingball/operatingsystem_status.rb +8 -0
- data/app/models/foreman_wreckingball/spectre_v2_status.rb +19 -3
- data/app/models/foreman_wreckingball/tools_status.rb +9 -1
- data/app/models/foreman_wreckingball/vmware_facet.rb +9 -4
- data/app/models/foreman_wreckingball/vmware_hypervisor_facet.rb +4 -7
- data/app/models/setting/wreckingball.rb +22 -0
- data/app/services/foreman_wreckingball/vmware_cluster_importer.rb +7 -7
- data/app/services/foreman_wreckingball/vmware_hypervisor_importer.rb +17 -4
- data/app/views/foreman_wreckingball/hosts/_hosts.json.rabl +35 -0
- data/app/views/foreman_wreckingball/hosts/_status_dashboard_content.erb +13 -23
- data/app/views/foreman_wreckingball/hosts/_status_managed_hosts_dashboard_cards.html.erb +16 -0
- data/app/views/foreman_wreckingball/hosts/_status_managed_hosts_dashboard_cards_card.html.erb +11 -0
- data/app/views/foreman_wreckingball/hosts/_status_row.html.erb +16 -55
- data/app/views/foreman_wreckingball/hosts/_status_row_actions.html.erb +22 -0
- data/app/views/foreman_wreckingball/hosts/_status_row_hosts_table.html.erb +24 -0
- data/app/views/foreman_wreckingball/hosts/_status_row_hosts_table_actions.html.erb +9 -0
- data/app/views/foreman_wreckingball/hosts/schedule_remediate.html.erb +44 -26
- data/app/views/foreman_wreckingball/hosts/status_dashboard.html.erb +9 -6
- data/app/views/foreman_wreckingball/hosts/status_hosts.json.rabl +13 -0
- data/app/views/foreman_wreckingball/hosts/status_managed_hosts_dashboard.html.erb +142 -0
- data/config/environments/production.rb +7 -0
- data/config/routes.rb +4 -4
- data/db/migrate/20181020174609_add_power_state_to_vmware_facets.rb +7 -0
- data/db/migrate/20181021111543_add_indexes_to_vmware_hypervisor_facets.rb +8 -0
- data/lib/foreman_wreckingball/engine.rb +71 -23
- data/lib/foreman_wreckingball/version.rb +1 -1
- data/lib/tasks/foreman_vmware_checks_tasks.rake +1 -1
- data/test/actions/foreman_wreckingball/bulk_remediate_test.rb +31 -0
- data/test/actions/foreman_wreckingball/host/refresh_vmware_facet_test.rb +5 -4
- data/test/actions/foreman_wreckingball/host/remediate_hardware_version_test.rb +63 -0
- data/test/actions/foreman_wreckingball/host/remediate_spectre_v2_test.rb +62 -0
- data/test/actions/foreman_wreckingball/host/remediate_vmware_operatingsystem_test.rb +4 -2
- data/test/controllers/foreman_wreckingball/hosts_controller_test.rb +278 -39
- data/test/factories/compute_resource.rb +6 -1
- data/test/factories/foreman_wreckingball_factories.rb +166 -115
- data/test/factories/host.rb +16 -0
- data/test/factories/task.rb +17 -0
- data/test/helpers/foreman_wreckingball/status_helper.rb +10 -0
- data/test/integration/hosts_status_dashboard_test.rb +50 -0
- data/test/integration/hosts_status_managed_hosts_test.rb +105 -0
- data/test/integration_test_plugin_helper.rb +13 -0
- data/test/models/foreman_wreckingball/hardware_version_status_test.rb +88 -0
- data/test/models/foreman_wreckingball/tools_status_test.rb +5 -2
- data/test/models/foreman_wreckingball/vmware_facet_test.rb +27 -6
- data/test/models/host_status_test.rb +22 -0
- data/test/models/host_test.rb +64 -4
- data/test/models/usergroup_test.rb +25 -0
- data/test/test_plugin_helper.rb +19 -0
- data/test/unit/foreman_wreckingball/vmware_cluster_importer_test.rb +17 -2
- data/test/unit/foreman_wreckingball/vmware_hypervisor_importer_test.rb +11 -0
- metadata +55 -8
- data/app/services/foreman_wreckingball/debris_collector.rb +0 -249
@@ -1,249 +0,0 @@
|
|
1
|
-
require 'rbvmomi'
|
2
|
-
|
3
|
-
module ForemanWreckingball
|
4
|
-
class DebrisCollector
|
5
|
-
|
6
|
-
PROPERTY_MAPPING = {
|
7
|
-
:VirtualMachine => {
|
8
|
-
mapped: {
|
9
|
-
cpus: 'config.hardware.numCPU',
|
10
|
-
corespersocket: 'config.hardware.numCoresPerSocket',
|
11
|
-
memory_mb: 'config.hardware.memoryMB',
|
12
|
-
tools_state: 'guest.toolsStatus',
|
13
|
-
guest_id: 'config.guestId',
|
14
|
-
cpu_hot_add: 'config.cpuHotAddEnabled',
|
15
|
-
hardware_version: 'config.version',
|
16
|
-
#cpu_features: ''
|
17
|
-
},
|
18
|
-
additional: [
|
19
|
-
'name',
|
20
|
-
'config.instanceUuid'
|
21
|
-
]
|
22
|
-
},
|
23
|
-
:Folder => {
|
24
|
-
mapped: {
|
25
|
-
name: 'name'
|
26
|
-
},
|
27
|
-
additional: [
|
28
|
-
'childEntity'
|
29
|
-
]
|
30
|
-
},
|
31
|
-
}.freeze
|
32
|
-
|
33
|
-
attr_reader :compute_resource
|
34
|
-
attr_accessor :version, :stop_requested
|
35
|
-
|
36
|
-
delegate :logger, to: ::Rails
|
37
|
-
|
38
|
-
def initialize(compute_resource:)
|
39
|
-
logger.debug "Wreckingball Debris Collector: Initializing."
|
40
|
-
@compute_resource = compute_resource
|
41
|
-
self.version = ''
|
42
|
-
self.stop_requested = false
|
43
|
-
end
|
44
|
-
|
45
|
-
|
46
|
-
def run
|
47
|
-
logger.debug "Wreckingball Debris Collector: Started."
|
48
|
-
|
49
|
-
property_filter
|
50
|
-
|
51
|
-
logger.debug "Wreckingball Debris Collector: Starting initial import."
|
52
|
-
initial_refresh
|
53
|
-
logger.debug "Wreckingball Debris Collector: Finished initial import."
|
54
|
-
|
55
|
-
logger.debug "Wreckingball Debris Collector: Finished."
|
56
|
-
ensure
|
57
|
-
destroy_property_filter
|
58
|
-
end
|
59
|
-
|
60
|
-
def stop
|
61
|
-
logger.debug "Wreckingball Debris Collector: Stop requested."
|
62
|
-
self.stop_requested = true
|
63
|
-
end
|
64
|
-
|
65
|
-
private
|
66
|
-
|
67
|
-
def initial_refresh
|
68
|
-
monitor_updates
|
69
|
-
end
|
70
|
-
|
71
|
-
def monitor_updates
|
72
|
-
begin
|
73
|
-
update_set = wait_for_updates
|
74
|
-
return version if update_set.nil?
|
75
|
-
|
76
|
-
self.version = update_set.version
|
77
|
-
process_update_set(update_set)
|
78
|
-
end while update_set.truncated
|
79
|
-
end
|
80
|
-
|
81
|
-
def process_update_set(update_set)
|
82
|
-
property_filter_update = update_set.filterSet.to_a.detect do |update|
|
83
|
-
update.filter == property_filter
|
84
|
-
end
|
85
|
-
return if property_filter_update.nil?
|
86
|
-
|
87
|
-
object_update_set = property_filter_update.objectSet
|
88
|
-
return if object_update_set.blank?
|
89
|
-
|
90
|
-
logger.debug "Wreckingball Debris Collector: Processing #{object_update_set.count} updates..."
|
91
|
-
|
92
|
-
process_object_update_set(object_update_set)
|
93
|
-
|
94
|
-
logger.debug "Wreckingball Debris Collector: Processing #{object_update_set.count} updates... completed."
|
95
|
-
end
|
96
|
-
|
97
|
-
def process_object_update_set(object_update_set)
|
98
|
-
object_update_set.each do |object_update|
|
99
|
-
process_object_update(object_update)
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
def process_object_update(object_update)
|
104
|
-
managed_object = object_update.obj
|
105
|
-
|
106
|
-
logger.debug "#{object_update.kind} #{object_update.obj.class.wsdl_name}:#{object_update.obj._ref}"
|
107
|
-
|
108
|
-
case object_update.obj.class.wsdl_name
|
109
|
-
when 'VirtualMachine'
|
110
|
-
process_virtual_machine_update(object_update)
|
111
|
-
else
|
112
|
-
# Ignore this for now
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
def process_virtual_machine_update(object_update)
|
117
|
-
managed_object = object_update.obj
|
118
|
-
# TODO: Cache this
|
119
|
-
uuid = managed_object.config.instanceUuid
|
120
|
-
|
121
|
-
logger.error "Processing for uuid #{uuid}"
|
122
|
-
|
123
|
-
host = Host::Managed.find_by(compute_resource: compute_resource, uuid: uuid)
|
124
|
-
|
125
|
-
return unless host
|
126
|
-
|
127
|
-
facet = host.vmware_facet || host.build_vmware_facet
|
128
|
-
|
129
|
-
# TODO: Cluster
|
130
|
-
facet.update(
|
131
|
-
map_update_to_properties(:VirtualMachine, object_update.changeSet)
|
132
|
-
)
|
133
|
-
end
|
134
|
-
|
135
|
-
def map_update_to_properties(type, change_set)
|
136
|
-
mapping = PROPERTY_MAPPING[type][:mapped]
|
137
|
-
|
138
|
-
change_set.each_with_object({}) do |property_change, hsh|
|
139
|
-
hsh[mapping.key(property_change.name)] = property_change.val if mapping.key(property_change.name)
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
def wait_for_updates
|
144
|
-
connection.propertyCollector.WaitForUpdatesEx(
|
145
|
-
:version => version,
|
146
|
-
:options => wait_for_updates_options
|
147
|
-
)
|
148
|
-
end
|
149
|
-
|
150
|
-
def wait_for_updates_options
|
151
|
-
RbVmomi::VIM.WaitOptions(
|
152
|
-
:maxWaitSeconds => 10
|
153
|
-
)
|
154
|
-
end
|
155
|
-
|
156
|
-
def property_filter
|
157
|
-
@property_filter ||= create_property_filter
|
158
|
-
end
|
159
|
-
|
160
|
-
def property_set
|
161
|
-
PROPERTY_MAPPING.map do |type, properties|
|
162
|
-
RbVmomi::VIM::PropertySpec(
|
163
|
-
type: type,
|
164
|
-
pathSet: properties[:mapped].values + (properties[:additional] || [])
|
165
|
-
)
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
def traversal_spec_folder_to_child_entity
|
170
|
-
RbVmomi::VIM.TraversalSpec(
|
171
|
-
:name => 'FolderTraversalSpec',
|
172
|
-
:type => 'Folder',
|
173
|
-
:path => 'childEntity',
|
174
|
-
:skip => false,
|
175
|
-
:selectSet => [
|
176
|
-
RbVmomi::VIM.SelectionSpec(:name => 'FolderTraversalSpec'),
|
177
|
-
#RbVmomi::VIM.SelectionSpec(:name => 'tsDcToDsFolder'),
|
178
|
-
#RbVmomi::VIM.SelectionSpec(:name => 'tsDcToHostFolder'),
|
179
|
-
#RbVmomi::VIM.SelectionSpec(:name => 'tsDcToNetworkFolder'),
|
180
|
-
RbVmomi::VIM.SelectionSpec(:name => 'DatacenterToVmFolderTraversalSpec'),
|
181
|
-
#RbVmomi::VIM.SelectionSpec(:name => 'tsCrToHost'),
|
182
|
-
#RbVmomi::VIM.SelectionSpec(:name => 'tsCrToRp'),
|
183
|
-
#RbVmomi::VIM.SelectionSpec(:name => 'tsRpToRp'),
|
184
|
-
#RbVmomi::VIM.SelectionSpec(:name => 'tsRpToVm')
|
185
|
-
]
|
186
|
-
)
|
187
|
-
end
|
188
|
-
|
189
|
-
def traversal_spec_datacenter_to_vm_folder
|
190
|
-
RbVmomi::VIM.TraversalSpec(
|
191
|
-
:name => 'DatacenterToVmFolderTraversalSpec',
|
192
|
-
:type => 'Datacenter',
|
193
|
-
:path => 'vmFolder',
|
194
|
-
:skip => false,
|
195
|
-
:selectSet => [
|
196
|
-
RbVmomi::VIM.SelectionSpec(:name => 'FolderTraversalSpec')
|
197
|
-
]
|
198
|
-
)
|
199
|
-
end
|
200
|
-
|
201
|
-
def object_set(root)
|
202
|
-
traversal_spec = [
|
203
|
-
traversal_spec_folder_to_child_entity,
|
204
|
-
#datacenter_to_datastore_folder,
|
205
|
-
#datacenter_to_host_folder,
|
206
|
-
#datacenter_to_network_folder,
|
207
|
-
traversal_spec_datacenter_to_vm_folder
|
208
|
-
#compute_resource_to_host,
|
209
|
-
#compute_resource_to_resource_pool,
|
210
|
-
#resource_pool_to_resource_pool,
|
211
|
-
#resource_pool_to_vm,
|
212
|
-
]
|
213
|
-
|
214
|
-
RbVmomi::VIM.ObjectSpec(
|
215
|
-
:obj => root,
|
216
|
-
:selectSet => traversal_spec
|
217
|
-
)
|
218
|
-
end
|
219
|
-
|
220
|
-
def create_property_filter
|
221
|
-
property_filter_spec = RbVmomi::VIM.PropertyFilterSpec(
|
222
|
-
:objectSet => [
|
223
|
-
object_set(
|
224
|
-
root_folder
|
225
|
-
)
|
226
|
-
],
|
227
|
-
:propSet => property_set
|
228
|
-
)
|
229
|
-
|
230
|
-
connection.propertyCollector.CreateFilter(
|
231
|
-
:spec => property_filter_spec,
|
232
|
-
:partialUpdates => true
|
233
|
-
)
|
234
|
-
end
|
235
|
-
|
236
|
-
def destroy_property_filter
|
237
|
-
return unless @property_filter
|
238
|
-
@property_filter.DestroyPropertyFilter
|
239
|
-
end
|
240
|
-
|
241
|
-
def root_folder
|
242
|
-
connection.serviceContent.rootFolder
|
243
|
-
end
|
244
|
-
|
245
|
-
def connection
|
246
|
-
compute_resource.send(:client).send(:connection)
|
247
|
-
end
|
248
|
-
end
|
249
|
-
end
|