Skip to content

Commit

Permalink
Reconfigure Network: Added support for standard networks
Browse files Browse the repository at this point in the history
  • Loading branch information
kruge002 committed Feb 19, 2018
1 parent cce292a commit 5040e9f
Showing 1 changed file with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def add_disk_config_spec(vmcs, options)
def add_network_adapter_config_spec(vmcs, options)
add_device_config_spec(vmcs, VirtualDeviceConfigSpecOperation::Add) do |vdcs|
vdcs.device = VimHash.new("VirtualVmxnet3") do |dev|
dev.key = rand(-9999..-100) # negative integer as temporary key
dev.key = get_next_device_idx # negative integer as temporary key
dev.unitNumber = 0
dev.addressType = "Generated"
dev.wakeOnLanEnabled = "true"
Expand All @@ -272,14 +272,18 @@ def add_network_adapter_config_spec(vmcs, options)
con.connected = "true"
con.startConnected = "true"
end
dev.backing = VimHash.new("VirtualEthernetCardDistributedVirtualPortBackingInfo") do |bck|
bck.port = VimHash.new("DistributedVirtualSwitchPortConnection") do |pc|
# A DistributedVirtualPortgroup name is unique in a datacenter so look for a Lan with this name
# on all switches in the cluster
lan = Lan.find_by(:name => options[:network], :switch_id => HostSwitch.where(:host_id => host).pluck(:switch_id))

pc.switchUuid = lan.switch.switch_uuid
pc.portgroupKey = lan.uid_ems
lan = Lan.find_by(:name => options[:network], :switch_id => HostSwitch.where(:host_id => host.id).pluck(:switch_id))
raise MiqException::MiqVmError, "Network [#{options[:network]}] is not available on target" if lan.nil?
if lan.switch.shared
dev.backing = VimHash.new("VirtualEthernetCardDistributedVirtualPortBackingInfo") do |bck|
bck.port = VimHash.new("DistributedVirtualSwitchPortConnection") do |pc|
pc.switchUuid = lan.switch.switch_uuid
pc.portgroupKey = lan.uid_ems
end
end
else
dev.backing = VimHash.new('VirtualEthernetCardNetworkBackingInfo') do |bck|
bck.deviceName = options[:network]
end
end
end
Expand Down Expand Up @@ -366,4 +370,9 @@ def set_spec_option(obj, property, value, modifier = nil)
end
end
end

def get_next_device_idx
@new_device_idx ||= -100
@new_device_idx -= 1
end
end

0 comments on commit 5040e9f

Please sign in to comment.