Skip to content

Commit

Permalink
Add lans as a virtual relationship to ems_cluster
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Jillian Tullo committed Feb 19, 2018
1 parent 38ede59 commit a4cc28e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/models/ems_cluster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a4cc28e

Please sign in to comment.