Skip to content

Commit

Permalink
Fix storage.parent multiple parents found error
Browse files Browse the repository at this point in the history
Since datastores can live in multiple datacenters and map to a single
storage record they belong to multiple datacenter/datastoreFolder
folders.  This leads to multiple parents found errors when doing
storage.parent.
  • Loading branch information
agrare committed Feb 6, 2019
1 parent 7730642 commit 83868f6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,10 @@ def self.folder_inv_to_hashes(inv, result, result_uids)
inv.each do |mor, data|
mor = data['MOR'] # Use the MOR directly from the data since the mor as a key may be corrupt

child_mors = get_mors(data, 'childEntity')
# Since datastores living in multiple datacenters map to a single Storage record
# the same record will live in multiple folders. This leads to Multiple parents found
# exceptions if we allow datastores to be in child_uids.
child_mors = get_mors(data, 'childEntity').reject { |child| child.vimType == "Datastore" }

new_result = {
:type => EmsFolder.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def relationship_save_block(relationship_key, relationship_type, parent_type)
child_recs.each do |model_class, children_by_id|
children_by_id.each_value do |child|
new_parent_klass, new_parent_id = parent_by_child[model_class][child.id]
prev_parent = child.with_relationship_type(relationship_type) { child.parent(:of_type => parent_type) }
prev_parent = child.with_relationship_type(relationship_type) { child.parents(:of_type => parent_type)&.first }

next if prev_parent && (prev_parent.class.base_class == new_parent_klass && prev_parent.id == new_parent_id)

Expand Down

0 comments on commit 83868f6

Please sign in to comment.