Skip to content

Commit

Permalink
Merge pull request #18235 from kbrock/event_report_children
Browse files Browse the repository at this point in the history
EmsCluster#direct_vm_rels use sql to filter
  • Loading branch information
Fryguy authored Jan 15, 2019
2 parents 1cc8bfc + e87aac6 commit 4c9780c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/models/ems_cluster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def total_vcpus
# Direct Vm relationship methods
def direct_vm_rels
# Look for only the Vms at the second depth (default RP + 1)
descendant_rels(:of_type => 'VmOrTemplate').select { |r| (r.depth - depth) == 2 }
grandchild_rels(:of_type => 'VmOrTemplate')
end

def direct_vms
Expand Down
3 changes: 1 addition & 2 deletions app/models/host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -667,8 +667,7 @@ def disconnect_storage(s)
# Vm relationship methods
def direct_vms
# Look for only the Vms at the second depth (default RP + 1)
rels = descendant_rels(:of_type => 'Vm').select { |r| (r.depth - depth) == 2 }
Relationship.resources(rels).sort_by { |r| r.name.downcase }
grandchildren(:of_type => 'Vm').sort_by { |r| r.name.downcase }
end

# Resource Pool relationship methods
Expand Down
4 changes: 4 additions & 0 deletions app/models/mixins/relationship_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,10 @@ def grandchild_rels(*args)
Relationship.filter_by_resource_type(rels, options)
end

def grandchildren(*args)
Relationship.resources(grandchild_rels(*args))
end

def child_and_grandchild_rels(*args)
options = args.extract_options!
rels = relationships.inject(Relationship.none) do |stmt, r|
Expand Down
8 changes: 8 additions & 0 deletions spec/models/mixins/relationship_mixin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,14 @@
end
end

describe "#grandchildren" do
it "works with relationships" do
vms[0].with_relationship_type(test_rel_type) do
expect(vms[0].grandchildren).to match_array([vms[3], vms[4], vms[5], vms[6], vms[7]])
end
end
end

describe "#child_and_grandchild_rels" do
it "works with relationships" do
vms[0].with_relationship_type(test_rel_type) do
Expand Down

0 comments on commit 4c9780c

Please sign in to comment.