-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Graph refresh - target vm #35
Conversation
end | ||
|
||
def clusters | ||
if target.kind_of? VmOrTemplate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, seems like you still count with only 1 target being here.
If should be that the target is a TargetCollection, then target.targets could contain VmOrTemplate object. Then if the cluster would be needed for Vms, you should first parse all VmOrTemplate cluster references then fetch only referenced clusters.
If you don't fetch the cluster, the reference will be filled from the DB.
|
||
def clusters | ||
collector.clusters.each do |cluster| | ||
persister.resource_pools.find_or_build(r_id).assign_attributes( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the r_id does not seem to be defined?
persister.clusters.find_or_build(cluster.id).assign_attributes( | ||
:ems_ref => ems_ref, | ||
:ems_ref_obj => ems_ref, | ||
:uid_ems => cluster.id, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in the persistor, you have the default unique uuid (manager_ref attribute) as ems_ref, which is default. The unique uuid attribute should be what you use in persister.clusters.find_or_build(unique_uuid/manager_ref)
logical_unit && logical_unit.id | ||
end | ||
|
||
free = storagedomain.try(:available).to_i |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can probably put these one liners directly to the hash below, to spare some LOC
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will move only those which are used in one place
host_os_version = host.dig(:os, :version) | ||
ems_ref = ManageIQ::Providers::Redhat::InfraManager.make_ems_ref(host_inv.href) | ||
|
||
clusters = persister.clusters.lazy_find(host.dig(:cluster, :id)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you want to access the clusters directly do:
cluster = persister.clusters.find(host.dig(:cluster, :id)) # should return just 1, since we are using unique index here
storage_ids = [] | ||
dcs.each do |dc| | ||
if dc_ids.include? dc.id | ||
storage_ids << collector.collect_dc_domains(dc).to_miq_a.collect { |s| s[:id] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be nice to have a TODO if we could solve this lazily, maybe we can't
|
||
host_operating_systems(persister_host, host, hostname) | ||
networks = collector.collect_networks | ||
switchs(persister_host, host, nics, networks) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: plural of switch should be switches
nics.to_miq_a.each do |nic| | ||
network = network_from_nic(nic, host, networks) | ||
|
||
if network |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switch_uid = network.try(:id) || network_name
should result in the same thing
def network_for_nic(nic, host, networks) | ||
network_id = nic.dig(:network, :id) | ||
if network_id | ||
network = networks.detect { |n| n.id == network_id } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you cycle this through a lot of hosts&nics, might be better to avoid .detect which is O(n)
so somewhere above you could do indexed_networks = networks.index_by(:id)
and here just do indexed_networks[:network_id], which is O(1)
although I don't see the network_for_nic called anywhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw. this would be in general, I've seen that Ovirt has ineffective parser, which is most likely caused by these O(n) lookups, which result easily in O(n^2) when called in another cycle.
So would be nice to also fix parser performance for the graph refresh. :-) I've seen that parsing took the same time as saving to the DB for the old refresh, it should take like 1% of the time we need to save to the DB
cluster_id = host.dig(:cluster, :id) | ||
cluster = persister.clusters.lazy_find(cluster_id) | ||
datacenter_id = cluster.dig(:data_center, :id) | ||
network = networks.detect { |n| n.name == network_name && n.dig(:data_center, :id) == datacenter_id } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a crusade to kill all .detect :-)
storages = [] | ||
collector.attached_disks(vm).to_miq_a.each do |disk| | ||
disk.storage_domains.to_miq_a.each do |sd| | ||
storages << persister.storages.lazy_find(:ems_ref => sd.id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lazy find knows only strings now and can take only the unique uuid (if needed we could extend it to teach it multiple indexes)
so persister.storages.lazy_find(sd.id)
name = description = snapshot.description | ||
name = "Active Image" if name[0, 13] == '_ActiveImage_' | ||
|
||
persister.snapshots.find_or_build_by(persister_vm).assign_attributes( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
find_or_build
def operating_systems(persister_vm, vm) | ||
guest_os = vm.dig(:os, :type) | ||
|
||
persister.operating_systems.find_or_build_by(persister_vm).assign_attributes( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
find_or_build
return result if custom_attrs.nil? | ||
|
||
custom_attrs.each do |ca| | ||
persister.custom_attributes.find_or_build_by(persister_vm).assign_attributes( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
find_or_build
…_refresh check if name is blank and use instance_id instead
48b2aec
to
c82b554
Compare
return collect_emsclusters | ||
def ems_clusters | ||
clusters = [] | ||
if target.targets.any? { |t| t.kind_of? VmOrTemplate } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, so for the saving to work properly, the Collector and Persistor should use the same: references(:ems_clusters)
references(:ems_clusters) => [:cluster_ems_ref_1, :cluster_ems_ref_2]
So what it will then say, is collect me only [:cluster_ems_ref_1, :cluster_ems_ref_2] from the API. And when saving, compare it to [:cluster_ems_ref_1, :cluster_ems_ref_2] in the MIQ DB.
so Collector and Persistor should be aligned like this
9ff22f4
to
91ecd68
Compare
@matobet please take a look |
The reason for failed test is missing default manager which is provided by dependent PR |
91ecd68
to
802338f
Compare
@@ -76,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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra line?
return | ||
end | ||
|
||
persister.lans..find_or_build_by( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
..
This pull request is not mergeable. Please rebase and repush. |
802338f
to
557b05a
Compare
557b05a
to
cd846e3
Compare
When calling vm target refresh the db is updated properly using graph refresh code base.
cd846e3
to
c743ab6
Compare
Some comments on commits pkliczewski/manageiq-providers-ovirt@0abcb77~...c743ab6 spec/models/manageiq/providers/redhat/infra_manager/refresh/refresher_target_vm_4_spec.rb
|
Checked commits pkliczewski/manageiq-providers-ovirt@0abcb77~...c743ab6 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 app/models/manageiq/providers/redhat/inventory/parser/infra_manager.rb
|
Collector and parser implementations
RFE link: https://bugzilla.redhat.com/1466172