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 61ce705
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 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
6 changes: 6 additions & 0 deletions app/models/mixins/aggregation_mixin/methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 61ce705

Please sign in to comment.