Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #27931 - 'Could not match network interface' #7066

Merged
merged 1 commit into from Sep 24, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/concerns/fog_extensions/vsphere/server.rb
Expand Up @@ -40,7 +40,7 @@ def scsi_controller_type
def select_nic(fog_nics, nic)
nic_attrs = nic.compute_attributes
all_networks = service.list_networks(datacenter: datacenter)
vm_network = all_networks.detect { |network| nic_attrs['network'] && [network[:name], network[:id], network[:_ref]].compact.include?(nic_attrs['network']) }
vm_network = all_networks.detect { |network| nic_attrs['network'] && [network[:name], network[:id]].compact.include?(nic_attrs['network']) }
vm_network ||= all_networks.detect { |network| network[:_ref] == nic_attrs['network'] }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't mind droping the _ref even here, but could we at least move the name here as well, so we know the id is the primary attribute?

vm_network = all_networks.detect { |network| network[:id] == nic_attrs['network'] }
vm_network ||= all_networks.detect { |network| nic_attrs['network'] && [network[:name], network[:_ref]].compact.include?(nic_attrs['network']) }

Or even drop the _ref completely and make both lines simple.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't feel like I understand this code well enough to make a judgement on the proposed change nor to test it in any way that would confirm if either way is better. The root cause I can find is that some of the objects in our vCenter have _ref's that match other object's id's. Any fix which ensures a positive match on id is always selected in preference to any possible match against _ref should fix the issue.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood, this change make sense as is.
I will propose the cleanup in followup PR, if you are uncomfortable to do it ;)

unless vm_network
Rails.logger.info "Could not find Vsphere network for #{nic_attrs.inspect}"
Expand Down