diff --git a/app/models/ems_cluster.rb b/app/models/ems_cluster.rb index cb6784f51ca..c7a9eb6b4f6 100644 --- a/app/models/ems_cluster.rb +++ b/app/models/ems_cluster.rb @@ -34,6 +34,8 @@ class EmsCluster < ApplicationRecord virtual_has_many :storages, :uses => {:hosts => :storages} virtual_has_many :resource_pools, :uses => :all_relationships + virtual_has_many :lans, :uses => {:hosts => :lans} + has_many :failover_hosts, -> { failover }, :class_name => "Host" include SerializedEmsRefObjMixin diff --git a/app/models/mixins/aggregation_mixin/methods.rb b/app/models/mixins/aggregation_mixin/methods.rb index 25a3b568228..6ef80dcaa00 100644 --- a/app/models/mixins/aggregation_mixin/methods.rb +++ b/app/models/mixins/aggregation_mixin/methods.rb @@ -47,5 +47,11 @@ def aggregate_hardware(from, field, targets = nil) hdws.inject(0) { |t, hdw| t + hdw.send(field).to_i } end + + def lans + hosts = all_hosts + MiqPreloader.preload(hosts, :lans) + hosts.flat_map(&:lans).compact.uniq + end end end