Skip to content

Commit

Permalink
Skip a network that disappears during enumeration
Browse files Browse the repository at this point in the history
There's a race condition in #find_network between the enumeration of the
datacenter's network folder and the retrieval of each network's name. If
*any* network disappears during this iteration then #create_vm will
fail. This skips any network that disappears during the enumeration.
  • Loading branch information
ktchen14 committed Dec 19, 2019
1 parent 03ef4f7 commit 55320f9
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/vsphere_cpi/lib/cloud/vsphere/vcenter_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def find_network(datacenter, network_name)
if network_name.include?('/')
container_name = File.dirname(network_name)
network_name = File.basename(network_name)
network_container = find_by_inventory_path([ datacenter.name, 'network', container_name])
network_container = find_by_inventory_path([datacenter.name, 'network', container_name])
if network_container.nil?
network_container = find_child_by_name(datacenter.mob.network_folder, container_name.split('/'))
end
Expand All @@ -229,7 +229,14 @@ def find_network(datacenter, network_name)
end

target_network = nil
matching_networks = valid_networks.select { |n| n.name == network_name }
matching_networks = valid_networks.select do |network|
begin
network.name == network_name
rescue => e
logger.warn("Can't retrieve name of network #{network}: #{e}")
false
end
end
if matching_networks.length == 1
target_network = matching_networks.first
elsif matching_networks.length > 1
Expand Down

0 comments on commit 55320f9

Please sign in to comment.