forked from ManageIQ/manageiq-providers-ovirt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfra_manager.rb
149 lines (127 loc) · 4.4 KB
/
infra_manager.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
class ManageIQ::Providers::Redhat::InfraManager < ManageIQ::Providers::InfraManager
require_nested :EventCatcher
require_nested :EventParser
require_nested :RefreshWorker
require_nested :MetricsCapture
require_nested :MetricsCollectorWorker
require_nested :Host
require_nested :Provision
require_nested :ProvisionViaIso
require_nested :ProvisionViaPxe
require_nested :ProvisionWorkflow
require_nested :Refresh
require_nested :Template
require_nested :Vm
include_concern :ApiIntegration
include_concern :VmImport
supports :provisioning
supports :refresh_new_target
def refresher
Refresh::RefresherBuilder.new(self).build
end
def self.ems_type
@ems_type ||= "rhevm".freeze
end
def self.description
@description ||= "Red Hat Virtualization".freeze
end
def self.default_blacklisted_event_names
%w(
UNASSIGNED
USER_REMOVE_VG
USER_REMOVE_VG_FAILED
USER_VDC_LOGIN
USER_VDC_LOGOUT
USER_VDC_LOGIN_FAILED
)
end
def self.without_iso_datastores
includes(:iso_datastore).where(:iso_datastores => {:id => nil})
end
def self.any_without_iso_datastores?
without_iso_datastores.count > 0
end
def self.event_monitor_class
self::EventCatcher
end
def host_quick_stats(host)
qs = {}
with_provider_connection(:version => 4) do |connection|
stats_list = connection.system_service.hosts_service.host_service(host.uid_ems)
.statistics_service.list
qs["overallMemoryUsage"] = stats_list.detect { |x| x.name == "memory.used" }
.values.first.datum
qs["overallCpuUsage"] = stats_list.detect { |x| x.name == "cpu.load.avg.5m" }
.values.first.datum
end
qs
end
def self.provision_class(via)
case via
when "iso" then self::ProvisionViaIso
when "pxe" then self::ProvisionViaPxe
else self::Provision
end
end
def vm_reconfigure(vm, options = {})
ovirt_services_for_reconfigure = ManageIQ::Providers::Redhat::InfraManager::OvirtServices::Builder.new(self)
.build(:use_highest_supported_version => true).new(:ems => self)
ovirt_services_for_reconfigure.vm_reconfigure(vm, options)
end
def add_disks(add_disks_spec, vm)
storage = add_disks_spec[:storage]
with_disk_attachments_service(vm) do |service|
add_disks_spec[:disks].each { |disk_spec| service.add(prepare_disk(disk_spec, storage)) }
end
end
# prepare disk attachment request payload of adding disk for reconfigure vm
def prepare_disk(disk_spec, storage)
disk_spec = disk_spec.symbolize_keys
da_options = {
:size_in_mb => disk_spec[:disk_size_in_mb],
:storage => storage,
:name => disk_spec[:disk_name],
:thin_provisioned => disk_spec[:thin_provisioned],
:bootable => disk_spec[:bootable],
}
disk_attachment_builder = DiskAttachmentBuilder.new(da_options)
disk_attachment_builder.disk_attachment
end
# add disk to a virtual machine for a request arrived from an automation call
def vm_add_disk(vm, options = {})
storage = options[:datastore] || vm.storage
raise _("Data Store does not exist, unable to add disk") unless storage
da_options = {
:size_in_mb => options[:diskSize],
:storage => storage,
:name => options[:diskName],
:thin_provisioned => options[:thinProvisioned],
:bootable => options[:bootable],
:interface => options[:interface]
}
disk_attachment_builder = DiskAttachmentBuilder.new(da_options)
with_disk_attachments_service(vm) do |service|
service.add(disk_attachment_builder.disk_attachment)
end
end
def vm_migrate(vm, options = {})
host_id = URI(options[:host]).path.split('/').last
migration_options = {
:host => {
:id => host_id
}
}
with_version4_vm_service(vm) do |service|
service.migrate(migration_options)
end
end
def unsupported_migration_options
[:storage, :respool, :folder, :datacenter, :host_filter, :cluster]
end
# Migrations are supposed to work only in one cluster. If more VMs are going
# to be migrated, all have to live on the same cluster, otherwise they can
# not be migrated together.
def supports_migrate_for_all?(vms)
vms.map(&:ems_cluster).uniq.compact.size == 1
end
end