foreman_wreckingball 3.0.1 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/foreman_wreckingball/status_hosts_table.js +49 -0
- data/app/assets/stylesheets/foreman_wreckingball/status_hosts_table.css.scss +13 -0
- data/app/controllers/foreman_wreckingball/hosts_controller.rb +53 -13
- data/app/helpers/concerns/foreman_wreckingball/hosts_helper_extensions.rb +0 -15
- data/app/lib/actions/foreman_wreckingball/host/remediate_hardware_version.rb +63 -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 +5 -0
- data/app/models/foreman_wreckingball/hardware_version_status.rb +62 -0
- data/app/models/foreman_wreckingball/spectre_v2_status.rb +2 -2
- data/app/models/foreman_wreckingball/tools_status.rb +1 -1
- data/app/models/foreman_wreckingball/vmware_facet.rb +9 -0
- data/app/models/setting/wreckingball.rb +22 -0
- data/app/services/foreman_wreckingball/vmware_cluster_importer.rb +6 -1
- data/app/services/foreman_wreckingball/vmware_hypervisor_importer.rb +16 -1
- data/app/views/foreman_wreckingball/hosts/_hosts.json.rabl +41 -0
- data/app/views/foreman_wreckingball/hosts/_status_dashboard_content.erb +1 -2
- data/app/views/foreman_wreckingball/hosts/_status_row.html.erb +8 -43
- data/app/views/foreman_wreckingball/hosts/_status_row_hosts_table.html.erb +17 -0
- data/app/views/foreman_wreckingball/hosts/status_dashboard.html.erb +2 -0
- data/app/views/foreman_wreckingball/hosts/status_hosts.json.rabl +13 -0
- data/config/routes.rb +1 -0
- 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 +17 -1
- data/lib/foreman_wreckingball/version.rb +1 -1
- data/test/actions/foreman_wreckingball/host/refresh_vmware_facet_test.rb +2 -1
- data/test/actions/foreman_wreckingball/host/remediate_hardware_version_test.rb +63 -0
- data/test/actions/foreman_wreckingball/host/remediate_vmware_operatingsystem_test.rb +3 -1
- data/test/controllers/foreman_wreckingball/hosts_controller_test.rb +19 -0
- data/test/factories/compute_resource.rb +5 -0
- data/test/factories/foreman_wreckingball_factories.rb +15 -0
- data/test/factories/host.rb +8 -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 +23 -2
- data/test/models/host_test.rb +1 -0
- data/test/unit/foreman_wreckingball/vmware_hypervisor_importer_test.rb +11 -0
- metadata +18 -3
- data/app/services/foreman_wreckingball/debris_collector.rb +0 -249
@@ -4,6 +4,7 @@ FactoryBot.define do
|
|
4
4
|
factory :vmware_facet, class: 'ForemanWreckingball::VmwareFacet' do
|
5
5
|
vmware_cluster
|
6
6
|
tools_state 2 #:toolsOk
|
7
|
+
power_state 1 #:poweredOn
|
7
8
|
cpus 2
|
8
9
|
corespersocket 1
|
9
10
|
memory_mb 8192
|
@@ -149,4 +150,18 @@ FactoryBot.define do
|
|
149
150
|
reported_at { Time.now.utc }
|
150
151
|
after(:build) { |status| status.status = status.to_status }
|
151
152
|
end
|
153
|
+
|
154
|
+
factory :vmware_hardware_version_status, class: 'ForemanWreckingball::HardwareVersionStatus' do
|
155
|
+
association :host, factory: [:host, :with_vmware_facet]
|
156
|
+
reported_at { Time.now.utc }
|
157
|
+
after(:build) { |status| status.status = status.to_status }
|
158
|
+
|
159
|
+
trait(:with_ok_status) do
|
160
|
+
after(:build) { |status| status.status = ForemanWreckingball::HardwareVersionStatus::OK }
|
161
|
+
end
|
162
|
+
|
163
|
+
trait(:with_out_of_date_status) do
|
164
|
+
after(:build) { |status| status.status = ForemanWreckingball::HardwareVersionStatus::OUTOFDATE }
|
165
|
+
end
|
166
|
+
end
|
152
167
|
end
|
data/test/factories/host.rb
CHANGED
@@ -31,10 +31,18 @@ FactoryBot.modify do
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
+
trait :with_vmware_hardware_version_status do
|
35
|
+
with_vmware_facet
|
36
|
+
after(:create) do |host, _evaluator|
|
37
|
+
create :vmware_hardware_version_status, host: host
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
34
41
|
trait :with_wreckingball_statuses do
|
35
42
|
with_vmware_tools_status
|
36
43
|
with_vmware_operatingsystem_status
|
37
44
|
with_vmware_cpu_hot_add_status
|
45
|
+
with_vmware_hardware_version_status
|
38
46
|
end
|
39
47
|
end
|
40
48
|
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_plugin_helper'
|
4
|
+
|
5
|
+
module ForemanWreckingball
|
6
|
+
class HardwareVersionStatusTest < ActiveSupport::TestCase
|
7
|
+
setup do
|
8
|
+
User.current = users(:admin)
|
9
|
+
Setting::Wreckingball.load_defaults
|
10
|
+
end
|
11
|
+
|
12
|
+
should belong_to(:host)
|
13
|
+
|
14
|
+
let(:host) do
|
15
|
+
FactoryBot.create(
|
16
|
+
:host,
|
17
|
+
:managed,
|
18
|
+
:with_vmware_facet
|
19
|
+
)
|
20
|
+
end
|
21
|
+
let(:status) { ForemanWreckingball::HardwareVersionStatus.new(host: host) }
|
22
|
+
|
23
|
+
test 'has a host association' do
|
24
|
+
status.save!
|
25
|
+
assert_equal status, host.public_send(status.class.host_association)
|
26
|
+
end
|
27
|
+
|
28
|
+
test '#relevant is only for hosts with a vmware facet' do
|
29
|
+
h = FactoryBot.build(:host, :managed)
|
30
|
+
refute ForemanWreckingball::ToolsStatus.new(host: h).relevant?
|
31
|
+
assert status.relevant?
|
32
|
+
end
|
33
|
+
|
34
|
+
test '#relevant is for hosts with a hardware version' do
|
35
|
+
assert status.relevant?
|
36
|
+
host.vmware_facet.hardware_version = nil
|
37
|
+
refute status.relevant?
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'status calculation' do
|
41
|
+
test 'is out of date when version is too old' do
|
42
|
+
status.host.vmware_facet.hardware_version = 'vmx-9'
|
43
|
+
assert_equal HardwareVersionStatus::OUTOFDATE, status.to_status
|
44
|
+
end
|
45
|
+
|
46
|
+
test 'is ok when version is recent enough' do
|
47
|
+
status.host.vmware_facet.hardware_version = 'vmx-13'
|
48
|
+
assert_equal HardwareVersionStatus::OK, status.to_status
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe 'status labels' do
|
53
|
+
test 'when version is out of date' do
|
54
|
+
status.status = HardwareVersionStatus::OUTOFDATE
|
55
|
+
assert_equal 'Out of date', status.to_label
|
56
|
+
end
|
57
|
+
|
58
|
+
test 'when version is recent' do
|
59
|
+
status.status = HardwareVersionStatus::OK
|
60
|
+
assert_equal 'OK', status.to_label
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe 'global status' do
|
65
|
+
test 'is warning when version is out of date' do
|
66
|
+
status.status = HardwareVersionStatus::OUTOFDATE
|
67
|
+
assert_equal HostStatus::Global::WARN, status.to_global
|
68
|
+
end
|
69
|
+
|
70
|
+
test 'is ok when version is recent' do
|
71
|
+
status.status = HardwareVersionStatus::OK
|
72
|
+
assert_equal HostStatus::Global::OK, status.to_global
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '#recent_hw_version?' do
|
77
|
+
test 'is true when hw version is new' do
|
78
|
+
status.host.vmware_facet.hardware_version = 'vmx-13'
|
79
|
+
assert status.recent_hw_version?
|
80
|
+
end
|
81
|
+
|
82
|
+
test 'is false when hw version is ancient' do
|
83
|
+
status.host.vmware_facet.hardware_version = 'vmx-3'
|
84
|
+
refute status.recent_hw_version?
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -32,13 +32,16 @@ module ForemanWreckingball
|
|
32
32
|
end
|
33
33
|
|
34
34
|
describe 'status calculation' do
|
35
|
+
setup do
|
36
|
+
Host::Managed.any_instance.stubs(:supports_power?).returns(true)
|
37
|
+
end
|
38
|
+
|
35
39
|
test 'when host is powered down' do
|
36
|
-
|
40
|
+
host.vmware_facet.update(power_state: 'poweredOff')
|
37
41
|
assert_equal ForemanWreckingball::ToolsStatus::POWERDOWN, status.to_status
|
38
42
|
end
|
39
43
|
|
40
44
|
test 'when host is powered on' do
|
41
|
-
Host::Managed.any_instance.stubs(:supports_power_and_running?).returns(true)
|
42
45
|
assert_equal 2, status.to_status
|
43
46
|
end
|
44
47
|
end
|
@@ -8,6 +8,26 @@ module ForemanWreckingball
|
|
8
8
|
should belong_to(:vmware_cluster)
|
9
9
|
should have_many(:vmware_hypervisor_facets)
|
10
10
|
|
11
|
+
describe '#vm_ready?' do
|
12
|
+
let(:host) do
|
13
|
+
FactoryBot.create(
|
14
|
+
:host,
|
15
|
+
:managed,
|
16
|
+
:with_vmware_facet
|
17
|
+
)
|
18
|
+
end
|
19
|
+
let(:vmware_facet) { host.vmware_facet }
|
20
|
+
|
21
|
+
test 'is true when vm is powered on' do
|
22
|
+
assert_equal true, vmware_facet.vm_ready?
|
23
|
+
end
|
24
|
+
|
25
|
+
test 'is false when vm is not powered on' do
|
26
|
+
vmware_facet.power_state = 'suspended'
|
27
|
+
assert_equal false, vmware_facet.vm_ready?
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
11
31
|
describe '#refresh!' do
|
12
32
|
let(:uuid) { '5032c8a5-9c5e-ba7a-3804-832a03e16381' }
|
13
33
|
let(:vm) do
|
@@ -25,7 +45,7 @@ module ForemanWreckingball
|
|
25
45
|
end
|
26
46
|
|
27
47
|
let(:compute_resource) do
|
28
|
-
cr = FactoryBot.create(:compute_resource, :vmware, :uuid => 'Solutions')
|
48
|
+
cr = FactoryBot.create(:compute_resource, :vmware, :with_taxonomy, :uuid => 'Solutions')
|
29
49
|
ComputeResource.find(cr.id)
|
30
50
|
end
|
31
51
|
|
@@ -47,7 +67,7 @@ module ForemanWreckingball
|
|
47
67
|
::Fog::Compute::Vsphere::Server.any_instance.stubs(:cpuHotAddEnabled).returns(false)
|
48
68
|
::Fog::Compute::Vsphere::Server.any_instance.stubs(:hardware_version).returns('vmx-9')
|
49
69
|
::Fog::Compute::Vsphere::Server.any_instance.stubs(:corespersocket).returns(1)
|
50
|
-
::Fog::Compute::Vsphere::Server.any_instance.stubs(:
|
70
|
+
::Fog::Compute::Vsphere::Server.any_instance.stubs(:power_state).returns('poweredOn')
|
51
71
|
end
|
52
72
|
teardown { ::Fog.unmock! }
|
53
73
|
|
@@ -58,6 +78,7 @@ module ForemanWreckingball
|
|
58
78
|
assert_equal 2196, vmware_facet.memory_mb
|
59
79
|
assert_equal 'rhel6_64Guest', vmware_facet.guest_id
|
60
80
|
assert_equal 'toolsOk', vmware_facet.tools_state
|
81
|
+
assert_equal 'poweredOn', vmware_facet.power_state
|
61
82
|
assert_equal false, vmware_facet.cpu_hot_add
|
62
83
|
assert_equal ['cpuid.SSE3', 'cpuid.AES', 'cpuid.Intel'], vmware_facet.cpu_features
|
63
84
|
assert_equal 'vmx-9', vmware_facet.hardware_version
|
data/test/models/host_test.rb
CHANGED
@@ -10,4 +10,5 @@ class Host::ManagedTest < ActiveSupport::TestCase
|
|
10
10
|
should have_one(:vmware_operatingsystem_status_object)
|
11
11
|
should have_one(:vmware_cpu_hot_add_status_object)
|
12
12
|
should have_one(:vmware_spectre_v2_status_object)
|
13
|
+
should have_one(:vmware_hardware_version_status_object)
|
13
14
|
end
|
@@ -63,6 +63,17 @@ module ForemanWreckingball
|
|
63
63
|
assert_equal '4c4c4544-0051-3610-8046-c4c44f584a32', host.vmware_hypervisor_facet.uuid
|
64
64
|
end
|
65
65
|
|
66
|
+
test 'removes hypervisor facets from stale hosts' do
|
67
|
+
host_on_other_cluster = FactoryBot.create(:host, :managed, :with_vmware_hypervisor_facet)
|
68
|
+
stale_facet = FactoryBot.create(:vmware_hypervisor_facet, vmware_cluster: cluster, compute_resource: compute_resource)
|
69
|
+
|
70
|
+
importer.import!
|
71
|
+
|
72
|
+
assert_nil ForemanWreckingball::VmwareHypervisorFacet.find_by(id: stale_facet.id)
|
73
|
+
assert_not_nil Host::Managed.find_by(name: 'host1.example.com').vmware_hypervisor_facet
|
74
|
+
assert_not_nil Host::Managed.find_by(id: host_on_other_cluster.id).vmware_hypervisor_facet
|
75
|
+
end
|
76
|
+
|
66
77
|
test 'updates host by katello name' do
|
67
78
|
host = FactoryBot.create(:host, organization: organization)
|
68
79
|
host.update!(:name => "virt-who-host1.example.com-#{organization.id}")
|
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: 3.0
|
4
|
+
version: 3.1.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-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: foreman-tasks
|
@@ -63,16 +63,21 @@ files:
|
|
63
63
|
- README.md
|
64
64
|
- Rakefile
|
65
65
|
- app/assets/javascripts/foreman_wreckingball/modal.js
|
66
|
+
- app/assets/javascripts/foreman_wreckingball/status_hosts_table.js
|
67
|
+
- app/assets/stylesheets/foreman_wreckingball/status_hosts_table.css.scss
|
66
68
|
- app/controllers/foreman_wreckingball/hosts_controller.rb
|
67
69
|
- app/helpers/concerns/foreman_wreckingball/hosts_helper_extensions.rb
|
68
70
|
- app/helpers/foreman_wreckingball/hypervisors_helper.rb
|
69
71
|
- app/jobs/update_hosts_vmware_facets.rb
|
70
72
|
- app/lib/actions/foreman_wreckingball/host/refresh_vmware_facet.rb
|
73
|
+
- app/lib/actions/foreman_wreckingball/host/remediate_hardware_version.rb
|
71
74
|
- app/lib/actions/foreman_wreckingball/host/remediate_vmware_operatingsystem.rb
|
72
75
|
- app/lib/actions/foreman_wreckingball/vmware/schedule_vmware_sync.rb
|
73
76
|
- app/lib/actions/foreman_wreckingball/vmware/sync_compute_resource.rb
|
74
77
|
- app/lib/fog_extensions/foreman_wreckingball/vsphere/host.rb
|
78
|
+
- app/lib/fog_extensions/foreman_wreckingball/vsphere/mock.rb
|
75
79
|
- app/lib/fog_extensions/foreman_wreckingball/vsphere/real.rb
|
80
|
+
- app/lib/fog_extensions/foreman_wreckingball/vsphere/server.rb
|
76
81
|
- app/lib/vsphere_os_identifiers.rb
|
77
82
|
- app/lib/vsphere_os_identifiers/data.yaml
|
78
83
|
- app/lib/vsphere_os_identifiers/os.rb
|
@@ -82,26 +87,32 @@ files:
|
|
82
87
|
- app/models/concerns/foreman_wreckingball/vmware_facet_host_extensions.rb
|
83
88
|
- app/models/concerns/foreman_wreckingball/vmware_hypervisor_facet_host_extensions.rb
|
84
89
|
- app/models/foreman_wreckingball/cpu_hot_add_status.rb
|
90
|
+
- app/models/foreman_wreckingball/hardware_version_status.rb
|
85
91
|
- app/models/foreman_wreckingball/operatingsystem_status.rb
|
86
92
|
- app/models/foreman_wreckingball/spectre_v2_status.rb
|
87
93
|
- app/models/foreman_wreckingball/tools_status.rb
|
88
94
|
- app/models/foreman_wreckingball/vmware_cluster.rb
|
89
95
|
- app/models/foreman_wreckingball/vmware_facet.rb
|
90
96
|
- app/models/foreman_wreckingball/vmware_hypervisor_facet.rb
|
91
|
-
- app/
|
97
|
+
- app/models/setting/wreckingball.rb
|
92
98
|
- app/services/foreman_wreckingball/vmware_cluster_importer.rb
|
93
99
|
- app/services/foreman_wreckingball/vmware_hypervisor_importer.rb
|
94
100
|
- app/views/compute_resources/_hypervisors_tab.html.erb
|
101
|
+
- app/views/foreman_wreckingball/hosts/_hosts.json.rabl
|
95
102
|
- app/views/foreman_wreckingball/hosts/_status_dashboard_content.erb
|
96
103
|
- app/views/foreman_wreckingball/hosts/_status_dashboard_empty.erb
|
97
104
|
- app/views/foreman_wreckingball/hosts/_status_row.html.erb
|
105
|
+
- app/views/foreman_wreckingball/hosts/_status_row_hosts_table.html.erb
|
98
106
|
- app/views/foreman_wreckingball/hosts/schedule_remediate.html.erb
|
99
107
|
- app/views/foreman_wreckingball/hosts/status_dashboard.html.erb
|
108
|
+
- app/views/foreman_wreckingball/hosts/status_hosts.json.rabl
|
100
109
|
- config/routes.rb
|
101
110
|
- db/migrate/20171106155000_create_vmware_facets.rb
|
102
111
|
- db/migrate/20180504135345_add_cpu_features_to_vmware_facets.rb
|
103
112
|
- db/migrate/20180504135515_add_hardware_version_to_vmware_facets.rb
|
104
113
|
- db/migrate/20180614105545_add_feature_capabilities_to_vmware_hypervisor_facets.rb
|
114
|
+
- db/migrate/20181020174609_add_power_state_to_vmware_facets.rb
|
115
|
+
- db/migrate/20181021111543_add_indexes_to_vmware_hypervisor_facets.rb
|
105
116
|
- lib/foreman_wreckingball.rb
|
106
117
|
- lib/foreman_wreckingball/engine.rb
|
107
118
|
- lib/foreman_wreckingball/scheduled_jobs.rb
|
@@ -112,6 +123,7 @@ files:
|
|
112
123
|
- locale/foreman_wreckingball.pot
|
113
124
|
- locale/gemspec.rb
|
114
125
|
- test/actions/foreman_wreckingball/host/refresh_vmware_facet_test.rb
|
126
|
+
- test/actions/foreman_wreckingball/host/remediate_hardware_version_test.rb
|
115
127
|
- test/actions/foreman_wreckingball/host/remediate_vmware_operatingsystem_test.rb
|
116
128
|
- test/actions/foreman_wreckingball/vmware/schedule_vmware_sync_test.rb
|
117
129
|
- test/actions/foreman_wreckingball/vmware/sync_compute_resource_test.rb
|
@@ -123,6 +135,7 @@ files:
|
|
123
135
|
- test/models/compute_resource_test.rb
|
124
136
|
- test/models/compute_resources/vmware_test.rb
|
125
137
|
- test/models/foreman_wreckingball/cpu_hot_add_status_test.rb
|
138
|
+
- test/models/foreman_wreckingball/hardware_version_status_test.rb
|
126
139
|
- test/models/foreman_wreckingball/operatingsystem_status_test.rb
|
127
140
|
- test/models/foreman_wreckingball/spectre_v2_status_test.rb
|
128
141
|
- test/models/foreman_wreckingball/tools_status_test.rb
|
@@ -165,6 +178,7 @@ test_files:
|
|
165
178
|
- test/models/foreman_wreckingball/operatingsystem_status_test.rb
|
166
179
|
- test/models/foreman_wreckingball/spectre_v2_status_test.rb
|
167
180
|
- test/models/foreman_wreckingball/vmware_hypervisor_facet_test.rb
|
181
|
+
- test/models/foreman_wreckingball/hardware_version_status_test.rb
|
168
182
|
- test/models/foreman_wreckingball/cpu_hot_add_status_test.rb
|
169
183
|
- test/models/foreman_wreckingball/vmware_cluster_test.rb
|
170
184
|
- test/models/foreman_wreckingball/vmware_facet_test.rb
|
@@ -174,6 +188,7 @@ test_files:
|
|
174
188
|
- test/factories/host.rb
|
175
189
|
- test/factories/foreman_wreckingball_factories.rb
|
176
190
|
- test/actions/foreman_wreckingball/host/remediate_vmware_operatingsystem_test.rb
|
191
|
+
- test/actions/foreman_wreckingball/host/remediate_hardware_version_test.rb
|
177
192
|
- test/actions/foreman_wreckingball/host/refresh_vmware_facet_test.rb
|
178
193
|
- test/actions/foreman_wreckingball/vmware/sync_compute_resource_test.rb
|
179
194
|
- test/actions/foreman_wreckingball/vmware/schedule_vmware_sync_test.rb
|
@@ -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
|