Skip to content

Commit

Permalink
Unify network ID attribute
Browse files Browse the repository at this point in the history
Use _ref as ID for all kinds of networks.
  • Loading branch information
ezr-ondrej authored and chris1984 committed Jul 29, 2021
1 parent bd61eaa commit 9b88e63
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
6 changes: 3 additions & 3 deletions lib/fog/vsphere/requests/compute/get_network.rb
Expand Up @@ -38,20 +38,20 @@ def choose_finder(ref_or_name, distributedswitch)
# only the one will do
proc do |n|
n._ref == ref_or_name || (
n.is_a?(RbVmomi::VIM::DistributedVirtualPortgroup) && (n.name == ref_or_name || n.key == ref_or_name) &&
n.is_a?(RbVmomi::VIM::DistributedVirtualPortgroup) && (n.name == ref_or_name) &&
(n.config.distributedVirtualSwitch.name == distributedswitch)
)
end
when :dvs
# the first distributed virtual switch will do - selected by network - gives control to vsphere
proc do |n|
n._ref == ref_or_name || (
n.is_a?(RbVmomi::VIM::DistributedVirtualPortgroup) && (n.name == ref_or_name || n.key == ref_or_name)
n.is_a?(RbVmomi::VIM::DistributedVirtualPortgroup) && (n.name == ref_or_name)
)
end
else
# the first matching network will do, seems like the non-distributed networks come first
proc { |n| n._ref == ref_or_name || n.name == ref_or_name || (n.is_a?(RbVmomi::VIM::DistributedVirtualPortgroup) && n.key == ref_or_name) }
proc { |n| n._ref == ref_or_name || n.name == ref_or_name }
end
end
end
Expand Down
14 changes: 6 additions & 8 deletions lib/fog/vsphere/requests/compute/list_networks.rb
Expand Up @@ -30,17 +30,15 @@ def list_networks(filters = {})
virtualswitch: dvswitches[network['config.distributedVirtualSwitch']._ref]
)
elsif network.obj.is_a?(RbVmomi::VIM::OpaqueNetwork)
map_attrs_to_hash(network, network_dvportgroup_attribute_mapping).merge(
id: network.obj._ref,
map_attrs_to_hash(network, network_attribute_mapping).merge(
opaqueNetworkId: network.obj.summary.opaqueNetworkId
)
else
map_attrs_to_hash(network, network_attribute_mapping).merge(
id: network.obj._ref
)
map_attrs_to_hash(network, network_attribute_mapping)
end.merge(
datacenter: datacenter_name,
_ref: network.obj._ref
_ref: network.obj._ref,
id: managed_obj_id(network.obj),
datacenter: datacenter_name
)
end.compact
end
Expand All @@ -56,7 +54,7 @@ def network_attribute_mapping

def network_dvportgroup_attribute_mapping
network_attribute_mapping.merge(
id: 'config.key'
dvp_uuid: 'config.key'
)
end

Expand Down

0 comments on commit 9b88e63

Please sign in to comment.