Skip to content

Commit

Permalink
Graph refresh - vm target
Browse files Browse the repository at this point in the history
When calling vm target refresh the db is updated properly using
graph refresh code base.
  • Loading branch information
pkliczewski committed Jul 4, 2017
1 parent 8cf3210 commit cd846e3
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 114 deletions.
4 changes: 1 addition & 3 deletions app/models/manageiq/providers/redhat/infra_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ class ManageIQ::Providers::Redhat::InfraManager < ManageIQ::Providers::InfraMana
supports :provisioning
supports :refresh_new_target

has_many :ems_custom_attributes, :through => :vms_and_templates

def refresher
Refresh::RefresherBuilder.new(self).build
end
Expand Down Expand Up @@ -78,7 +76,7 @@ def self.provision_class(via)

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)
.build(:use_highest_supported_version => true).new(:ems => self)
ovirt_services_for_reconfigure.vm_reconfigure(vm, options)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def collect_inventory_for_targets(ems, targets)
end

def preprocess_targets
# See if any should be escalated to a full refresh and do not use full_refresh_threshold
@targets_by_ems_id.each do |ems_id, targets|
ems = @ems_by_ems_id[ems_id]
ems_in_list = targets.any? { |t| t.kind_of?(ExtManagementSystem) }
Expand Down
6 changes: 1 addition & 5 deletions app/models/manageiq/providers/redhat/inventory/collector.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class ManageIQ::Providers::Redhat::Inventory::Collector < ManagerRefresh::Inventory::Collector
# TODO review the changes here and find common parts with ManageIQ::Providers::Redhat::InfraManager::Inventory::Strategies::V4
require_nested :InfraManager
require_nested :TargetCollection

Expand Down Expand Up @@ -28,11 +29,6 @@ def initialize_inventory_sources
@templates = []
end

def hash_collection
# TODO: check whether needed
::ManageIQ::Providers::Redhat::Inventory::HashCollection
end

def collect_ems_clusters
manager.with_provider_connection(VERSION_HASH) do |connection|
connection.system_service.clusters_service.list
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class ManageIQ::Providers::Redhat::Inventory::Collector::TargetCollection < ManageIQ::Providers::Redhat::Inventory::Collector
# TODO review the changes here and find common parts with ManageIQ::Providers::Redhat::InfraManager::Inventory::Strategies::V4
def initialize(_manager, _target)
super
parse_targets!
Expand All @@ -14,7 +15,7 @@ def ems_clusters

manager.with_provider_connection(VERSION_HASH) do |connection|
references(:ems_clusters).each do |id|
clusters + connection.system_service.clusters_service.cluster_service(id).get
clusters += connection.system_service.clusters_service.cluster_service(id).get
end
end

Expand All @@ -27,7 +28,7 @@ def networks

manager.with_provider_connection(VERSION_HASH) do |connection|
references(:networks).each do |id|
nets + connection.system_service.networks_service.network_service(id).get
nets += connection.system_service.networks_service.network_service(id).get
end
end

Expand All @@ -40,7 +41,7 @@ def storagedomains

manager.with_provider_connection(VERSION_HASH) do |connection|
references(:storagedomains).each do |id|
domains + connection.system_service.storage_domains_service.storage_domain_service(id).get
domains += connection.system_service.storage_domains_service.storage_domain_service(id).get
end
end

Expand All @@ -53,7 +54,7 @@ def datacenters

manager.with_provider_connection(VERSION_HASH) do |connection|
references(:datacenters).each do |id|
dcs + connection.system_service.data_centers_service.data_center_service(id).get
dcs += connection.system_service.data_centers_service.data_center_service(id).get
end
end

Expand All @@ -66,7 +67,7 @@ def hosts

manager.with_provider_connection(VERSION_HASH) do |connection|
references(:vms).each do |ems_ref|
h + connection.system_service.hosts_service.host_service(uuid_from_ems_ref(ems_ref)).get
h += connection.system_service.hosts_service.host_service(uuid_from_ems_ref(ems_ref)).get
end
end

Expand All @@ -79,7 +80,7 @@ def vms

manager.with_provider_connection(VERSION_HASH) do |connection|
references(:vms).each do |ems_ref|
v + connection.system_service.vms_service.vm_service(uuid_from_ems_ref(ems_ref)).get
v += connection.system_service.vms_service.vm_service(uuid_from_ems_ref(ems_ref)).get
end
end

Expand All @@ -92,7 +93,7 @@ def templates

manager.with_provider_connection(VERSION_HASH) do |connection|
references(:templates).each do |id|
temp + connection.system_service.templates_service.list(:search => "vm.id=#{id}")
temp += connection.system_service.templates_service.list(:search => "vm.id=#{id}")
end
end

Expand Down Expand Up @@ -142,24 +143,24 @@ def infer_related_vm_ems_refs_db!
changed_vms = manager.vms.where(:ems_ref => references(:vms))

changed_vms.each do |vm|
add_simple_target!(:ems_clusters, uuid_from_target(vm.ems_cluster))
vm.storages.collect(&:ems_ref).compact.each { |ems_ref| add_simple_target!(:storagedomains, uuid_from_ems_ref(ems_ref)) }
add_simple_target!(:datacenters, uuid_from_target(vm.parent_datacenter))
add_simple_target!(:templates, uuid_from_target(vm))
add_simple_target!(:ems_clusters, vm.ems_cluster.ems_ref)
vm.storages.collect(&:ems_ref).compact.each { |ems_ref| add_simple_target!(:storagedomains, ems_ref) }
add_simple_target!(:datacenters, vm.parent_datacenter.ems_ref)
add_simple_target!(:templates, vm.ems_ref)
end
end

def infer_related_vm_ems_refs_api!
vms.each do |vm|
add_simple_target!(:ems_clusters, vm.cluster.id)
add_simple_target!(:ems_clusters, ems_ref_from_sdk(vm.cluster))
disks = collect_attached_disks(vm)
disks.each do |disk|
disk.storage_domains.to_miq_a.each do |sd|
add_simple_target!(:storagedomains, sd.id)
add_simple_target!(:storagedomains, ems_ref_from_sdk(sd))
end
end
add_simple_target!(:datacenters, vm.cluster.data_center.id)
add_simple_target!(:templates, vm.id)
add_simple_target!(:datacenters, ems_ref_from_sdk(vm.cluster.data_center))
add_simple_target!(:templates, ems_ref_from_sdk(vm))
end
end

Expand Down Expand Up @@ -191,6 +192,10 @@ def uuid_from_ems_ref(ems_ref)
URI(ems_ref).path.split('/').last
end

def ems_ref_from_sdk(object)
ManageIQ::Providers::Redhat::InfraManager.make_ems_ref(object.href)
end

def add_simple_target!(association, ems_ref)
return if ems_ref.blank?

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class ManageIQ::Providers::Redhat::Inventory::Parser::InfraManager < ManageIQ::Providers::Redhat::Inventory::Parser
# TODO review the changes here and find common parts with ManageIQ::Providers::Redhat::InfraManager::Refresh::Parse::*
def parse
log_header = "MIQ(#{self.class.name}.#{__method__}) Collecting data for EMS name: [#{collector.manager.name}] id: [#{collector.manager.id}]"
$rhevm_log.info("#{log_header}...")
Expand All @@ -16,7 +17,7 @@ def ems_clusters
collector.ems_clusters.each do |cluster|
r_id = "#{cluster.id}_respool"

persister.resource_pools.find_or_build(r_id).assign_attributes(
persister.resource_pools.find_or_build(:ems_uid => r_id).assign_attributes(
:name => "Default for Cluster #{cluster.name}",
:uid_ems => r_id,
:is_default => true,
Expand Down Expand Up @@ -52,7 +53,7 @@ def storagedomains

ems_ref = ManageIQ::Providers::Redhat::InfraManager.make_ems_ref(storagedomain.try(:href))

persister.storages.find_or_build(storagedomain.id).assign_attributes(
persister.storages.find_or_build(ems_ref).assign_attributes(
:ems_ref => ems_ref,
:ems_ref_obj => ems_ref,
:name => storagedomain.try(:name),
Expand Down Expand Up @@ -230,7 +231,6 @@ def network_for_nic(nic, host, networks)
cluster_id = host.dig(:cluster, :id)
cluster = persister.clusters.lazy_find(cluster_id)
datacenter_id = cluster.dig(:data_center, :id)
# TODO: get rid of detect
network = networks.detect { |n| n.name == network_name && n.dig(:data_center, :id) == datacenter_id }
end

Expand All @@ -251,7 +251,7 @@ def lans(persister_switch, network)
return
end

persister.lans..find_or_build_by(
persister.lans.find_or_build_by(
:switch => persister_switch,
:uid_ems => uid
).assign_attributes(
Expand Down Expand Up @@ -300,13 +300,13 @@ def vms
:raw_power_state => template ? "never" : vm.status,
:boot_time => vm.try(:start_time),
:host => persister.hosts.lazy_find(host_id),
:ems_cluster => persister.ems_clusters.lazy_find(vm.cluster.id),
:ems_cluster => persister.ems_clusters.lazy_find(ManageIQ::Providers::Redhat::InfraManager.make_ems_ref(vm.cluster.href)),
:storages => storages,
:storage => storages.first,
:snapshots => snapshots(vm)
)

vm_hardware(persister_vm, vm)
snapshots(persister_vm, vm)
operating_systems(persister_vm, vm)
custom_attributes(persister_vm, vm)
end
Expand All @@ -316,7 +316,7 @@ def storages(vm)
storages = []
collector.collect_attached_disks(vm).to_miq_a.each do |disk|
disk.storage_domains.to_miq_a.each do |sd|
storages << persister.storages.lazy_find(sd.id)
storages << persister.storages.lazy_find(ManageIQ::Providers::Redhat::InfraManager.make_ems_ref(sd.href))
end
end
storages.compact!
Expand Down Expand Up @@ -379,7 +379,7 @@ def hardware_disks(persister_hardware, vm)
disks.each do |interface, devices|
devices.each_with_index do |device, index|
storage_domain = device.storage_domains && device.storage_domains.first
storage_id = storage_domain && storage_domain.id
storage_ref = storage_domain && storage_domain.href

persister.disks.find_or_build_by(
:hardware => persister_hardware,
Expand All @@ -396,7 +396,7 @@ def hardware_disks(persister_hardware, vm)
:disk_type => device.sparse == true ? 'thin' : 'thick',
:mode => 'persistent',
:bootable => device.try(:bootable),
:storage => persister.storages.lazy_find(storage_id)
:storage => persister.storages.lazy_find(ManageIQ::Providers::Redhat::InfraManager.make_ems_ref(storage_ref))
)
end
end
Expand All @@ -421,14 +421,15 @@ def hardware_guest_devices(persister_hardware, vm, addresses)
end
end

def snapshots(persister_vm, vm)
def snapshots(vm)
snapshots = collector.collect_snapshots(vm)
parent_id = nil
snaps = []
snapshots.each_with_index do |snapshot, idx|
name = description = snapshot.description
name = "Active Image" if name[0, 13] == '_ActiveImage_'

persister.snapshots.find_or_build(persister_vm).assign_attributes(
snaps << persister.snapshots.find_or_build(:uid => snapshot.id).assign_attributes(
:uid_ems => snapshot.id,
:uid => snapshot.id,
:parent_uid => parent_id,
Expand All @@ -439,6 +440,7 @@ def snapshots(persister_vm, vm)
)
parent_id = snapshot.id
end
snaps
end

def operating_systems(persister_vm, vm)
Expand All @@ -454,7 +456,10 @@ def custom_attributes(persister_vm, vm)
custom_attrs = vm.try(:custom_properties)

custom_attrs.to_a.each do |ca|
persister.custom_attributes.find_or_build(persister_vm).assign_attributes(
persister.custom_attributes.find_or_build(
:resource => persister_vm,
:name => ca.name,
).assign_attributes(
:section => 'custom_field',
:name => ca.name,
:value => ca.value.try(:truncate, 255),
Expand Down
Loading

0 comments on commit cd846e3

Please sign in to comment.