From a4cc28e342496b329cc4e950e828c0cd2d258d64 Mon Sep 17 00:00:00 2001 From: Jillian Tullo Date: Mon, 19 Feb 2018 10:19:56 -0500 Subject: [PATCH] Add lans as a virtual relationship to ems_cluster Lans need to be exposed via the API for the creation of transformation mappings. By adding this virtual relationship, they are able to be queried via `/api/clusters/:id?attributes=lans` There will be a lans collection added to the API in a follow-up PR --- app/models/ems_cluster.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/models/ems_cluster.rb b/app/models/ems_cluster.rb index cb6784f51ca3..d6c687d06311 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 @@ -230,6 +232,12 @@ def memory_reserve get_reserve(:memory_reserve) end + def lans + hosts = all_hosts + MiqPreloader.preload(hosts, :lans) + hosts.collect(&:lans).flatten.compact.uniq + end + def effective_resource(resource) resource = resource.to_s unless %w(cpu vcpu memory).include?(resource)